From cd84c58ad42c6201e8148ad684c87014b86a8427 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 23 Feb 2026 23:43:40 +0500 Subject: [PATCH 1/5] feat: add ndarray/base/unflatten-shape --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ndarray/base/unflatten-shape/README.md | 134 ++++++++++++++++++ .../unflatten-shape/benchmark/benchmark.js | 79 +++++++++++ .../base/unflatten-shape/docs/repl.txt | 63 ++++++++ .../unflatten-shape/docs/types/index.d.ts | 88 ++++++++++++ .../base/unflatten-shape/docs/types/test.ts | 133 +++++++++++++++++ .../base/unflatten-shape/examples/index.js | 26 ++++ .../base/unflatten-shape/lib/assign.js | 78 ++++++++++ .../ndarray/base/unflatten-shape/lib/index.js | 49 +++++++ .../ndarray/base/unflatten-shape/lib/main.js | 50 +++++++ .../ndarray/base/unflatten-shape/package.json | 70 +++++++++ .../base/unflatten-shape/test/test.assign.js | 83 +++++++++++ .../ndarray/base/unflatten-shape/test/test.js | 65 +++++++++ .../base/unflatten-shape/test/test.main.js | 79 +++++++++++ 13 files changed, 997 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md new file mode 100644 index 000000000000..7661b8d9de8e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md @@ -0,0 +1,134 @@ + + +# unflattenShape + +> Unflatten a shape over multiple dimensions. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' ); +``` + +#### unflattenShape( shape, dim, sizes ) + +Unflattens a shape over multiple dimensions. + +```javascript +var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); +// returns [ 3, 2, 2, 1 ] +``` + +The function accepts the following parameters: + +- **shape**: array shape. +- **dim**: dimension to be unflattened. +- **sizes**: new shape of the unflattened dimension. + +#### unflattenShape.assign( shape, dim, sizes, out ) + +Unflattens a shape over multiple dimensions and assigns results to a provided output array. + +```javascript +var o = [ 0, 0, 0, 0 ]; + +var out = unflattenShape.assign( [ 6, 2, 1 ], 0, [ 3, 2 ], o ); +// returns [ 3, 2, 2, 1 ] + +var bool = ( out === o ); +// returns true +``` + +The function accepts the following parameters: + +- **shape**: array shape. +- **dim**: dimension to be unflattened. +- **sizes**: new shape of the unflattened dimension. +- **out**: output array. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' ); + +var out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 2 ] ); +// returns [ 2, 2, 2, 1 ] + +console.log( 'Unflattened Shape: ', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/benchmark/benchmark.js new file mode 100644 index 000000000000..be0f41d2683c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/benchmark/benchmark.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isArray = require( '@stdlib/assert/is-array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var unflattenShape = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var shape; + var sizes; + var out; + var i; + + shape = [ 5, 9, 3, 4, 2 ]; + sizes = [ 1, 1, 3 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = unflattenShape( shape, 2, sizes ); + if ( out.length !== 7 ) { + b.fail( 'should have expected length' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:assign', pkg ), function benchmark( b ) { + var shape; + var sizes; + var out; + var i; + + shape = [ 5, 9, 3, 4, 2 ]; + sizes = [ 1, 1, 3 ]; + out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = unflattenShape.assign( shape, 2, sizes, out ); + if ( out.length !== 7 ) { + b.fail( 'should have expected length' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt new file mode 100644 index 000000000000..3a4c3db6a3dd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt @@ -0,0 +1,63 @@ + +{{alias}}( shape, dim, sizes ) + Unflattens a shape over multiple dimensions. + + Parameters + ---------- + shape: ArrayLike + Array shape. + + dim: integer + Dimension to be unflattened. + + sizes: ArrayLike + New shape of the unflattened dimension. + + Returns + ------- + out: Array + Unflattened shape. + + Examples + -------- + > var sh = [ 6, 2, 1 ]; + > var sizes = [ 3, 2 ]; + > var out = {{alias}}( sh, 0, sizes ) + [ 3, 2, 2, 1 ] + + +{{alias}}.assign( shape, dim, sizes, out ) + Unflattens a shape over multiple dimensions and assigns results to a + provided output array. + + Parameters + ---------- + shape: ArrayLike + Array shape. + + dim: integer + Dimension to be unflattened. + + sizes: ArrayLike + New shape of the unflattened dimension. + + out: Array|TypedArray|Object + Output array. + + Returns + ------- + out: Array|TypedArray|Object + Output array. + + Examples + -------- + > var sh = [ 6, 2, 1 ]; + > var sizes = [ 3, 2 ]; + > var o = [ 0, 0, 0, 0 ]; + > var out = {{alias}}.assign( sh, 0, sizes, o ) + [ 3, 2, 2, 1 ] + > var bool = ( o === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts new file mode 100644 index 000000000000..a898d3589f28 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts @@ -0,0 +1,88 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* Interface describing `unflattenShape` +*/ +interface Routine { + /** + * Unflattens a shape over multiple dimensions. + * + * @param shape - array shape + * @param dim - dimension to be unflattened + * @param sizes - new shape of the unflattened dimension + * @returns unflattened shape + * + * @example + * var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); + * // returns [ 3, 2, 2, 1 ] + */ + ( shape: Array, dim: number, sizes: Array ): Array; + + /** + * Unflattens a shape over multiple dimensions. + * + * @param shape - array shape + * @param dim - dimension to be unflattened + * @param sizes - new shape of the unflattened dimension + * @param out - output array + * @returns unflattened shape + * + * @example + * var o = [ 0, 0, 0, 0 ]; + * + * var out = unflattenShape.assign( [ 6, 2, 1 ], 0, [ 3, 2 ], o ); + * // returns [ 3, 2, 2, 1 ] + * + * var bool = ( out === o ); + * // returns true + */ + assign( shape: Array, dim: number, sizes: Array, out: Array ): Array; +} + +/** +* Unflattens a shape over multiple dimensions. +* +* @param shape - array shape +* @param dim - dimension to be unflattened +* @param sizes - new shape of the unflattened dimension +* @returns unflattened shape +* +* @example +* var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); +* // returns [ 3, 2, 2, 1 ] +* +* @example +* var o = [ 0, 0, 0, 0 ]; +* +* var out = unflattenShape.assign( [ 6, 2, 1 ], 0, [ 3, 2 ], o ); +* // returns [ 3, 2, 2, 1 ] +* +* var bool = ( out === o ); +* // returns true +*/ +declare var unflattenShape: Routine; + + +// EXPORTS // + +export = unflattenShape; diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts new file mode 100644 index 000000000000..a717baf520b2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts @@ -0,0 +1,133 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import unflattenShape = require( './index' ); + + +// TESTS // + +// The function returns an array of numbers... +{ + unflattenShape( [ 6, 2, 1 ], 1, [ 3, 2 ] ); // $ExpectType number[] +} + +// The compiler throws an error if the function is provided a first argument that is not an array-like object containing numbers... +{ + unflattenShape( true, 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( false, 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( null, 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( undefined, 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( '5', 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( [ '1', '2' ], 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( {}, 1, [ 3, 2 ] ); // $ExpectError + unflattenShape( ( x: number ): number => x, 1, [ 3, 2 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + unflattenShape( [ 6, 2, 1 ], true, [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], false, [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], null, [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], undefined, [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], '5', [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], [ '1', '2' ], [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], {}, [ 3, 2 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], ( x: number ): number => x, [ 3, 2 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not an array-like object containing numbers... +{ + unflattenShape( [ 6, 2, 1 ], 1, true ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, false ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, null ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, undefined ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, '5' ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, [ '1', '2' ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, {} ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + unflattenShape(); // $ExpectError + unflattenShape( [ 6, 2, 1 ] ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1 ); // $ExpectError + unflattenShape( [ 6, 2, 1 ], 1, [ 3, 2 ], {} ); // $ExpectError +} + +// The assign method returns an array of numbers... +{ + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectType number[] +} + +// The compiler throws an error if the assign method is provided a first argument that is not an array-like object containing numbers... +{ + unflattenShape.assign( true, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( false, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( null, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( undefined, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( '5', 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ '1', '2' ], 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( {}, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( ( x: number ): number => x, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError +} + +// The compiler throws an error if the assign method is provided a second argument that is not a number... +{ + unflattenShape.assign( [ 6, 2, 1 ], true, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], false, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], null, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], undefined, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], '5', [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], [ '1', '2' ], [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], {}, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], ( x: number ): number => x, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError +} + +// The compiler throws an error if the assign method is provided a third argument that is not an array-like object containing numbers... +{ + unflattenShape.assign( [ 6, 2, 1 ], 1, true, [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, false, [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, null, [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, undefined, [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, '5', [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ '1', '2' ], [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, {}, [ 0, 0, 0, 0 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, ( x: number ): number => x, [ 0, 0, 0, 0 ] ); // $ExpectError +} + +// The compiler throws an error if the assign method is provided a fourth argument that is not an array-like object containing numbers... +{ + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], true ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], false ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], null ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], undefined ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], '5' ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], [ '1', '2' ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], {} ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the assign method is provided an unsupported number of arguments... +{ + unflattenShape.assign(); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1 ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ] ); // $ExpectError + unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], [ 0, 0, 0, 0 ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js new file mode 100644 index 000000000000..ce65d138d2c5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js @@ -0,0 +1,26 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var unflattenShape = require( './../lib' ); + +var out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 2 ] ); +// returns [ 2, 2, 2, 1 ] + +console.log( 'Unflattened Shape: ', out ); diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js new file mode 100644 index 000000000000..f09780db2f45 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var flattenShape = require( '@stdlib/ndarray/base/flatten-shape' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Unflattens a shape over multiple dimensions. +* +* @param {NonNegativeIntegerArray} shape - array shape +* @param {NonNegativeInteger} dim - dimension to be unflattened +* @param {NonNegativeIntegerArray} sizes - new shape of the unflattened dimension +* @param {NonNegativeIntegerArray} out - output array +* @throws {RangeError} - product of the sizes array must be equal to the dimension to be unflattened +* @returns {NonNegativeIntegerArray} unflattened shape +* +* @example +* var o = [ 0, 0, 0, 0 ]; +* +* var out = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ], o ); +* // returns [ 3, 2, 2, 1 ] +* +* var bool = ( out === o ); +* // returns true +*/ +function unflattenShape( shape, dim, sizes, out ) { + var s; + var i; + var j; + var k; + + s = flattenShape( sizes, sizes.length-1 ); + if ( shape[ dim ] !== s[ 0 ] ) { + throw new RangeError( format( 'invalid argument. Product of the sizes array must be equal to the dimension to be unflattened. Dim: `%d`. Product: `%d`.', shape[dim], s[0] ) ); + } + for ( i = 0; i < dim; i++ ) { + out[ i ] = shape[ i ]; + } + j = 0; + k = dim + sizes.length - 1; + for ( i = dim; i <= k; i++ ) { + out[ i ] = sizes[ j ]; + j += 1; + } + j = shape.length - 1; + for ( i = out.length-1; i > k; i-- ) { + out[ i ] = shape[ j ]; + j -= 1; + } + return out; +} + + +// EXPORTS // + +module.exports = unflattenShape; diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js new file mode 100644 index 000000000000..de35a6a31a7c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Unflatten a shape over multiple dimensions. +* +* @module @stdlib/ndarray/base/unflatten-shape +* +* @example +* var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' ); +* +* var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); +* // returns [ 3, 2, 2, 1 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js new file mode 100644 index 000000000000..1cb72f589960 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var zeros = require( '@stdlib/array/base/zeros' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Unflattens a shape over multiple dimensions. +* +* @param {NonNegativeIntegerArray} shape - array shape +* @param {NonNegativeInteger} dim - dimension to be unflattened +* @param {NonNegativeIntegerArray} sizes - new shape of the unflattened dimension +* @returns {NonNegativeIntegerArray} unflattened shape +* +* @example +* var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); +* // returns [ 3, 2, 2, 1 ] +*/ +function unflattenShape( shape, dim, sizes ) { + var out = zeros( shape.length + sizes.length - 1 ); + assign( shape, dim, sizes, out ); + return out; +} + + +// EXPORTS // + +module.exports = unflattenShape; diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json new file mode 100644 index 000000000000..0d56732f2423 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/ndarray/base/unflatten-shape", + "version": "0.0.0", + "description": "Unflatten a shape over multiple dimensions.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "ndarray", + "shape", + "unflatten", + "reshape", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js new file mode 100644 index 000000000000..72271c1cc191 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var assign = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function un-flattens a shape over multiple dimensions and assigns results to an output array', function test( t ) { + var expected; + var actual; + var shape; + var sizes; + var out; + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + expected = [ 2, 2, 2 ]; + out = [ 0, 0, 0 ]; + actual = assign( shape, 0, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 2, 1, 10 ]; + sizes = [ 2, 5 ]; + expected = [ 2, 1, 2, 5 ]; + out = [ 0, 0, 0, 0 ]; + actual = assign( shape, 2, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 1, 4, 3, 2 ]; + sizes = [ 1, 3 ]; + expected = [ 1, 4, 1, 3, 2 ]; + out = [ 0, 0, 0, 0, 0 ]; + actual = assign( shape, 2, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 12 ]; + sizes = [ 2, 2, 3 ]; + expected = [ 2, 2, 3 ]; + out = [ 0, 0, 0 ]; + actual = assign( shape, 0, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js new file mode 100644 index 000000000000..4d6c24c1f5c8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var unflattenShape = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof unflattenShape, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( unflattenShape, 'assign' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a `sizes` argument whose product does not equal the size of the dimension to un-flatten', function test( t ) { + var values; + var i; + + values = [ + [ 2, 5 ], + [ 1, 3 ], + [ 3, 2, 1 ], + [], + [ 0 ], + [ 1 ], + [ 1, 2, 3 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + unflattenShape( [ 6, 2, 1 ], 1, value ); + }; + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js new file mode 100644 index 000000000000..8d085356be34 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isArray = require( '@stdlib/assert/is-array' ); +var unflattenShape = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof unflattenShape, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function un-flattens a shape over multiple dimensions', function test( t ) { + var expected; + var actual; + var shape; + var sizes; + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + expected = [ 2, 2, 2 ]; + actual = unflattenShape( shape, 0, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 2, 1, 10 ]; + sizes = [ 2, 5 ]; + expected = [ 2, 1, 2, 5 ]; + actual = unflattenShape( shape, 2, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 1, 4, 3, 2 ]; + sizes = [ 1, 3 ]; + expected = [ 1, 4, 1, 3, 2 ]; + actual = unflattenShape( shape, 2, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 12 ]; + sizes = [ 2, 2, 3 ]; + expected = [ 2, 2, 3 ]; + actual = unflattenShape( shape, 0, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From 1155fe0a4acb1266eac12edc290f52605cd4c387 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 23 Feb 2026 23:53:46 +0500 Subject: [PATCH 2/5] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/unflatten-shape/package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json index 0d56732f2423..ce7134828c01 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json @@ -18,9 +18,7 @@ "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", - "include": "./include", "lib": "./lib", - "src": "./src", "test": "./test" }, "types": "./docs/types", From cc07da628556759f65a5a830d56199eb65774831 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 23 Feb 2026 23:54:23 +0500 Subject: [PATCH 3/5] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/unflatten-shape/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js index 4d6c24c1f5c8..296b9e3396b8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js @@ -53,7 +53,7 @@ tape( 'the function throws an error if provided a `sizes` argument whose product ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); } t.end(); From f6880d3ce7770db597150e2d6b21cc289eb8c9a4 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 23 Feb 2026 23:59:07 +0500 Subject: [PATCH 4/5] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/unflatten-shape/test/test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js index 296b9e3396b8..edb80d01fac4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js @@ -46,7 +46,6 @@ tape( 'the function throws an error if provided a `sizes` argument whose product [ 2, 5 ], [ 1, 3 ], [ 3, 2, 1 ], - [], [ 0 ], [ 1 ], [ 1, 2, 3 ] From 2444ee053e9edba973b97066fd61713bd6688f2c Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 27 Feb 2026 01:08:42 -0800 Subject: [PATCH 5/5] chore: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ndarray/base/unflatten-shape/README.md | 16 ++- .../base/unflatten-shape/docs/repl.txt | 22 ++-- .../unflatten-shape/docs/types/index.d.ts | 14 ++- .../base/unflatten-shape/docs/types/test.ts | 18 +-- .../base/unflatten-shape/examples/index.js | 11 +- .../base/unflatten-shape/lib/assign.js | 44 ++++--- .../ndarray/base/unflatten-shape/lib/index.js | 2 +- .../ndarray/base/unflatten-shape/lib/main.js | 6 +- .../ndarray/base/unflatten-shape/package.json | 2 +- .../base/unflatten-shape/test/test.assign.js | 112 +++++++++++++++++- .../ndarray/base/unflatten-shape/test/test.js | 25 ---- .../base/unflatten-shape/test/test.main.js | 104 +++++++++++++++- 12 files changed, 289 insertions(+), 87 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md index 7661b8d9de8e..6c68c0488dcb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/README.md @@ -20,7 +20,7 @@ limitations under the License. # unflattenShape -> Unflatten a shape over multiple dimensions. +> Expand a dimension over multiple dimensions. @@ -42,7 +42,7 @@ var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' ); #### unflattenShape( shape, dim, sizes ) -Unflattens a shape over multiple dimensions. +Expands a dimension over multiple dimensions. ```javascript var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); @@ -52,12 +52,12 @@ var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); The function accepts the following parameters: - **shape**: array shape. -- **dim**: dimension to be unflattened. +- **dim**: dimension to be unflattened. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. - **sizes**: new shape of the unflattened dimension. #### unflattenShape.assign( shape, dim, sizes, out ) -Unflattens a shape over multiple dimensions and assigns results to a provided output array. +Expands a dimension over multiple dimensions and assigns results to a provided output array. ```javascript var o = [ 0, 0, 0, 0 ]; @@ -72,7 +72,7 @@ var bool = ( out === o ); The function accepts the following parameters: - **shape**: array shape. -- **dim**: dimension to be unflattened. +- **dim**: dimension to be unflattened. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. - **sizes**: new shape of the unflattened dimension. - **out**: output array. @@ -102,7 +102,11 @@ var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' ); var out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 2 ] ); // returns [ 2, 2, 2, 1 ] -console.log( 'Unflattened Shape: ', out ); +out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 1, 2 ] ); +// returns [ 2, 2, 1, 2, 1 ] + +out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 1, 1, 2 ] ); +// returns [ 2, 2, 1, 1, 2, 1 ] ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt index 3a4c3db6a3dd..0181ef48f1f7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/repl.txt @@ -1,21 +1,23 @@ {{alias}}( shape, dim, sizes ) - Unflattens a shape over multiple dimensions. + Expands a dimension over multiple dimensions. Parameters ---------- - shape: ArrayLike + shape: ArrayLike Array shape. dim: integer - Dimension to be unflattened. + Dimension to be unflattened. If less than zero, the index is resolved + relative to the last dimension, with the last dimension corresponding to + the value `-1`. - sizes: ArrayLike + sizes: ArrayLike New shape of the unflattened dimension. Returns ------- - out: Array + out: Array Unflattened shape. Examples @@ -27,18 +29,20 @@ {{alias}}.assign( shape, dim, sizes, out ) - Unflattens a shape over multiple dimensions and assigns results to a + Expands a dimension over multiple dimensions and assigns results to a provided output array. Parameters ---------- - shape: ArrayLike + shape: ArrayLike Array shape. dim: integer - Dimension to be unflattened. + Dimension to be unflattened. If less than zero, the index is resolved + relative to the last dimension, with the last dimension corresponding to + the value `-1`. - sizes: ArrayLike + sizes: ArrayLike New shape of the unflattened dimension. out: Array|TypedArray|Object diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts index a898d3589f28..b5ba5ecfe585 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/index.d.ts @@ -20,12 +20,14 @@ /// +import { ArrayLike } from '@stdlib/types/array'; + /** -* Interface describing `unflattenShape` +* Interface describing `unflattenShape`. */ interface Routine { /** - * Unflattens a shape over multiple dimensions. + * Expands a dimension over multiple dimensions. * * @param shape - array shape * @param dim - dimension to be unflattened @@ -36,10 +38,10 @@ interface Routine { * var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] ); * // returns [ 3, 2, 2, 1 ] */ - ( shape: Array, dim: number, sizes: Array ): Array; + ( shape: ArrayLike, dim: number, sizes: ArrayLike ): Array; /** - * Unflattens a shape over multiple dimensions. + * Expands a dimension over multiple dimensions. * * @param shape - array shape * @param dim - dimension to be unflattened @@ -56,11 +58,11 @@ interface Routine { * var bool = ( out === o ); * // returns true */ - assign( shape: Array, dim: number, sizes: Array, out: Array ): Array; + assign = ArrayLike>( shape: ArrayLike, dim: number, sizes: ArrayLike, out: T ): T; } /** -* Unflattens a shape over multiple dimensions. +* Expands a dimension over multiple dimensions. * * @param shape - array shape * @param dim - dimension to be unflattened diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts index a717baf520b2..04a70768f9ed 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/docs/types/test.ts @@ -26,7 +26,7 @@ import unflattenShape = require( './index' ); unflattenShape( [ 6, 2, 1 ], 1, [ 3, 2 ] ); // $ExpectType number[] } -// The compiler throws an error if the function is provided a first argument that is not an array-like object containing numbers... +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... { unflattenShape( true, 1, [ 3, 2 ] ); // $ExpectError unflattenShape( false, 1, [ 3, 2 ] ); // $ExpectError @@ -38,7 +38,7 @@ import unflattenShape = require( './index' ); unflattenShape( ( x: number ): number => x, 1, [ 3, 2 ] ); // $ExpectError } -// The compiler throws an error if the function is provided a second argument that is not a number... +// The compiler throws an error if the function is provided a second argument which is not a number... { unflattenShape( [ 6, 2, 1 ], true, [ 3, 2 ] ); // $ExpectError unflattenShape( [ 6, 2, 1 ], false, [ 3, 2 ] ); // $ExpectError @@ -50,7 +50,7 @@ import unflattenShape = require( './index' ); unflattenShape( [ 6, 2, 1 ], ( x: number ): number => x, [ 3, 2 ] ); // $ExpectError } -// The compiler throws an error if the function is provided a third argument that is not an array-like object containing numbers... +// The compiler throws an error if the function is provided a third argument which is not an array-like object containing numbers... { unflattenShape( [ 6, 2, 1 ], 1, true ); // $ExpectError unflattenShape( [ 6, 2, 1 ], 1, false ); // $ExpectError @@ -70,12 +70,12 @@ import unflattenShape = require( './index' ); unflattenShape( [ 6, 2, 1 ], 1, [ 3, 2 ], {} ); // $ExpectError } -// The assign method returns an array of numbers... +// The `assign` method returns an array of numbers... { unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectType number[] } -// The compiler throws an error if the assign method is provided a first argument that is not an array-like object containing numbers... +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object containing numbers... { unflattenShape.assign( true, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError unflattenShape.assign( false, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError @@ -87,7 +87,7 @@ import unflattenShape = require( './index' ); unflattenShape.assign( ( x: number ): number => x, 1, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError } -// The compiler throws an error if the assign method is provided a second argument that is not a number... +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... { unflattenShape.assign( [ 6, 2, 1 ], true, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError unflattenShape.assign( [ 6, 2, 1 ], false, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError @@ -99,7 +99,7 @@ import unflattenShape = require( './index' ); unflattenShape.assign( [ 6, 2, 1 ], ( x: number ): number => x, [ 3, 2 ], [ 0, 0, 0, 0 ] ); // $ExpectError } -// The compiler throws an error if the assign method is provided a third argument that is not an array-like object containing numbers... +// The compiler throws an error if the `assign` method is provided a third argument which is not an array-like object containing numbers... { unflattenShape.assign( [ 6, 2, 1 ], 1, true, [ 0, 0, 0, 0 ] ); // $ExpectError unflattenShape.assign( [ 6, 2, 1 ], 1, false, [ 0, 0, 0, 0 ] ); // $ExpectError @@ -111,7 +111,7 @@ import unflattenShape = require( './index' ); unflattenShape.assign( [ 6, 2, 1 ], 1, ( x: number ): number => x, [ 0, 0, 0, 0 ] ); // $ExpectError } -// The compiler throws an error if the assign method is provided a fourth argument that is not an array-like object containing numbers... +// The compiler throws an error if the `assign` method is provided a fourth argument which is not an array-like object containing numbers... { unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], true ); // $ExpectError unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], false ); // $ExpectError @@ -123,7 +123,7 @@ import unflattenShape = require( './index' ); unflattenShape.assign( [ 6, 2, 1 ], 1, [ 3, 2 ], ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the assign method is provided an unsupported number of arguments... +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... { unflattenShape.assign(); // $ExpectError unflattenShape.assign( [ 6, 2, 1 ] ); // $ExpectError diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js index ce65d138d2c5..1308652521c6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/examples/index.js @@ -21,6 +21,13 @@ var unflattenShape = require( './../lib' ); var out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 2 ] ); -// returns [ 2, 2, 2, 1 ] +console.log( out ); +// => [ 2, 2, 2, 1 ] -console.log( 'Unflattened Shape: ', out ); +out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 1, 2 ] ); +console.log( out ); +// => [ 2, 2, 1, 2, 1 ] + +out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 1, 1, 2 ] ); +console.log( out ); +// => [ 2, 2, 1, 1, 2, 1 ] diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js index f09780db2f45..f53c05124f7f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/assign.js @@ -20,20 +20,23 @@ // MODULES // -var flattenShape = require( '@stdlib/ndarray/base/flatten-shape' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); +var join = require( '@stdlib/array/base/join' ); var format = require( '@stdlib/string/format' ); // MAIN // /** -* Unflattens a shape over multiple dimensions. +* Expands a dimension over multiple dimensions. * * @param {NonNegativeIntegerArray} shape - array shape -* @param {NonNegativeInteger} dim - dimension to be unflattened +* @param {integer} dim - dimension to be unflattened * @param {NonNegativeIntegerArray} sizes - new shape of the unflattened dimension * @param {NonNegativeIntegerArray} out - output array -* @throws {RangeError} - product of the sizes array must be equal to the dimension to be unflattened +* @throws {RangeError} second argument is out-of-bounds +* @throws {RangeError} product of the sizes must be equal to the size of the dimension to be unflattened * @returns {NonNegativeIntegerArray} unflattened shape * * @example @@ -46,28 +49,37 @@ var format = require( '@stdlib/string/format' ); * // returns true */ function unflattenShape( shape, dim, sizes, out ) { - var s; + var S1; + var S2; + var N; + var d; var i; var j; - var k; - s = flattenShape( sizes, sizes.length-1 ); - if ( shape[ dim ] !== s[ 0 ] ) { - throw new RangeError( format( 'invalid argument. Product of the sizes array must be equal to the dimension to be unflattened. Dim: `%d`. Product: `%d`.', shape[dim], s[0] ) ); + S1 = shape.length; + d = normalizeIndex( dim, S1-1 ); + if ( d < 0 ) { + throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', S1, dim ) ); } - for ( i = 0; i < dim; i++ ) { + S2 = sizes.length; + N = numel( sizes ); + if ( N !== shape[ d ] ) { + throw new RangeError( format( 'invalid argument. Product of the sizes must be equal to the size of the dimension to be unflattened. Dimension: %d. Size: %d. Value: `[%s]`.', d, shape[ d ], join( sizes, ', ' ) ) ); + } + for ( i = 0; i < d; i++ ) { out[ i ] = shape[ i ]; } j = 0; - k = dim + sizes.length - 1; - for ( i = dim; i <= k; i++ ) { + for ( ; i < d+S2; i++ ) { out[ i ] = sizes[ j ]; j += 1; } - j = shape.length - 1; - for ( i = out.length-1; i > k; i-- ) { - out[ i ] = shape[ j ]; - j -= 1; + j = d + 1; + if ( j < S1 ) { + for ( ; i < S1+S2-1; i++ ) { + out[ i ] = shape[ j ]; + j += 1; + } } return out; } diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js index de35a6a31a7c..cda38fd25023 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Unflatten a shape over multiple dimensions. +* Expand a dimension over multiple dimensions. * * @module @stdlib/ndarray/base/unflatten-shape * diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js index 1cb72f589960..1b0c1f8c2414 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/lib/main.js @@ -27,11 +27,13 @@ var assign = require( './assign.js' ); // MAIN // /** -* Unflattens a shape over multiple dimensions. +* Expands a dimension over multiple dimensions. * * @param {NonNegativeIntegerArray} shape - array shape -* @param {NonNegativeInteger} dim - dimension to be unflattened +* @param {integer} dim - dimension to be unflattened * @param {NonNegativeIntegerArray} sizes - new shape of the unflattened dimension +* @throws {RangeError} second argument is out-of-bounds +* @throws {RangeError} product of the sizes must be equal to the size of the dimension to be unflattened * @returns {NonNegativeIntegerArray} unflattened shape * * @example diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json index ce7134828c01..3e35ce17a032 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/unflatten-shape", "version": "0.0.0", - "description": "Unflatten a shape over multiple dimensions.", + "description": "Expand a dimension over multiple dimensions.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js index 72271c1cc191..0c22d0b0194f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.assign.js @@ -32,7 +32,69 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function un-flattens a shape over multiple dimensions and assigns results to an output array', function test( t ) { +tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { + var values; + var shape; + var sizes; + var out; + var i; + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + out = [ 0, 0, 0 ]; + + values = [ + -3, + -4, + 2, + 3, + 4 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( shape, value, sizes, out ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is incompatible with the size of a specified dimension', function test( t ) { + var values; + var shape; + var sizes; + var out; + var i; + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + out = [ 0, 0, 0 ]; + + values = [ + 0, + 1, + 2, + 3, + 5, + 6 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + sizes[ 0 ] = value; + assign( shape, 0, value, out ); + }; + } +}); + +tape( 'the function expands a dimension over multiple dimensions and assigns results to an output array', function test( t ) { var expected; var actual; var shape; @@ -46,7 +108,17 @@ tape( 'the function un-flattens a shape over multiple dimensions and assigns res actual = assign( shape, 0, sizes, out ); t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + expected = [ 2, 2, 2 ]; + out = [ 0, 0, 0 ]; + actual = assign( shape, -2, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); shape = [ 2, 1, 10 ]; @@ -56,7 +128,17 @@ tape( 'the function un-flattens a shape over multiple dimensions and assigns res actual = assign( shape, 2, sizes, out ); t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 2, 1, 10 ]; + sizes = [ 2, 5 ]; + expected = [ 2, 1, 2, 5 ]; + out = [ 0, 0, 0, 0 ]; + actual = assign( shape, -1, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); shape = [ 1, 4, 3, 2 ]; @@ -66,7 +148,17 @@ tape( 'the function un-flattens a shape over multiple dimensions and assigns res actual = assign( shape, 2, sizes, out ); t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 1, 4, 3, 2 ]; + sizes = [ 1, 3 ]; + expected = [ 1, 4, 1, 3, 2 ]; + out = [ 0, 0, 0, 0, 0 ]; + actual = assign( shape, -2, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); shape = [ 12 ]; @@ -76,7 +168,17 @@ tape( 'the function un-flattens a shape over multiple dimensions and assigns res actual = assign( shape, 0, sizes, out ); t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 12 ]; + sizes = [ 2, 2, 3 ]; + expected = [ 2, 2, 3 ]; + out = [ 0, 0, 0 ]; + actual = assign( shape, -1, sizes, out ); + + t.strictEqual( out, actual, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js index edb80d01fac4..b3adc48dacb9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.js @@ -37,28 +37,3 @@ tape( 'attached to the main export is an `assign` method', function test( t ) { t.strictEqual( isMethod( unflattenShape, 'assign' ), true, 'returns expected value' ); t.end(); }); - -tape( 'the function throws an error if provided a `sizes` argument whose product does not equal the size of the dimension to un-flatten', function test( t ) { - var values; - var i; - - values = [ - [ 2, 5 ], - [ 1, 3 ], - [ 3, 2, 1 ], - [ 0 ], - [ 1 ], - [ 1, 2, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - unflattenShape( [ 6, 2, 1 ], 1, value ); - }; - } -}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js index 8d085356be34..700ab50c4389 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unflatten-shape/test/test.main.js @@ -33,7 +33,65 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function un-flattens a shape over multiple dimensions', function test( t ) { +tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { + var values; + var shape; + var sizes; + var i; + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + + values = [ + -3, + -4, + 2, + 3, + 4 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + unflattenShape( shape, value, sizes ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is incompatible with the size of a specified dimension', function test( t ) { + var values; + var shape; + var sizes; + var i; + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + + values = [ + 0, + 1, + 2, + 3, + 5, + 6 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + sizes[ 0 ] = value; + unflattenShape( shape, 0, value ); + }; + } +}); + +tape( 'the function expands a dimension over multiple dimensions', function test( t ) { var expected; var actual; var shape; @@ -45,7 +103,16 @@ tape( 'the function un-flattens a shape over multiple dimensions', function test actual = unflattenShape( shape, 0, sizes ); t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 4, 2 ]; + sizes = [ 2, 2 ]; + expected = [ 2, 2, 2 ]; + actual = unflattenShape( shape, -2, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); shape = [ 2, 1, 10 ]; @@ -54,7 +121,16 @@ tape( 'the function un-flattens a shape over multiple dimensions', function test actual = unflattenShape( shape, 2, sizes ); t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 2, 1, 10 ]; + sizes = [ 2, 5 ]; + expected = [ 2, 1, 2, 5 ]; + actual = unflattenShape( shape, -1, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); shape = [ 1, 4, 3, 2 ]; @@ -63,7 +139,16 @@ tape( 'the function un-flattens a shape over multiple dimensions', function test actual = unflattenShape( shape, 2, sizes ); t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 1, 4, 3, 2 ]; + sizes = [ 1, 3 ]; + expected = [ 1, 4, 1, 3, 2 ]; + actual = unflattenShape( shape, -2, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); shape = [ 12 ]; @@ -72,7 +157,16 @@ tape( 'the function un-flattens a shape over multiple dimensions', function test actual = unflattenShape( shape, 0, sizes ); t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.strictEqual( actual.length, expected.length, 'returns expected length' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + shape = [ 12 ]; + sizes = [ 2, 2, 3 ]; + expected = [ 2, 2, 3 ]; + actual = unflattenShape( shape, -1, sizes ); + + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); t.end();