diff --git a/lib/node_modules/@stdlib/blas/ext/cusum/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/cusum/lib/assign.js index cd7031f4723f..d70f221f61a4 100644 --- a/lib/node_modules/@stdlib/blas/ext/cusum/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/cusum/lib/assign.js @@ -26,11 +26,11 @@ var isComplexLike = require( '@stdlib/assert/is-complex-like' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ).assign; diff --git a/lib/node_modules/@stdlib/blas/ext/cusum/lib/main.js b/lib/node_modules/@stdlib/blas/ext/cusum/lib/main.js index abfc38da7cf6..9b7d994d2d67 100644 --- a/lib/node_modules/@stdlib/blas/ext/cusum/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/cusum/lib/main.js @@ -26,11 +26,11 @@ var isComplexLike = require( '@stdlib/assert/is-complex-like' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js index c216a025775f..b3e2e4e87a13 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js @@ -26,12 +26,12 @@ var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); var defaults = require( '@stdlib/ndarray/defaults' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ).assign; diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js index d2df675eb458..3f6da9fae8fa 100644 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js @@ -26,12 +26,12 @@ var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); var defaults = require( '@stdlib/ndarray/defaults' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ); diff --git a/lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js b/lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js deleted file mode 100644 index 07e99731e89f..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/index-of/lib/non_core_shape.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 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 normalizeIndices = require( '@stdlib/ndarray/base/to-unique-normalized-indices' ); -var indicesComplement = require( '@stdlib/array/base/indices-complement' ); -var takeIndexed = require( '@stdlib/array/base/take-indexed' ); - - -// MAIN // - -/** -* Returns the shape defined by the dimensions which are **not** included in a list of dimensions. -* -* @private -* @param {NonNegativeIntegerArray} shape - input ndarray -* @param {IntegerArray} dims - list of dimensions -* @returns {NonNegativeIntegerArray} shape -*/ -function nonCoreShape( shape, dims ) { // TODO: consider moving to a `@stdlib/ndarray/base` utility - var ind = normalizeIndices( dims, shape.length-1 ); - if ( ind === null ) { - // Note: this is an error condition, as `null` is returned when provided out-of-bounds indices... - return []; - } - return takeIndexed( shape, indicesComplement( shape.length, ind ) ); -} - - -// EXPORTS // - -module.exports = nonCoreShape; diff --git a/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/assign.js index 034248d20b1a..f372d2aa00ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/assign.js @@ -26,12 +26,12 @@ var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); var defaults = require( '@stdlib/ndarray/defaults' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ).assign; diff --git a/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/main.js index 96c7f530b52e..fbff5adaed0b 100644 --- a/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/main.js @@ -26,12 +26,12 @@ var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); var defaults = require( '@stdlib/ndarray/defaults' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ); diff --git a/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/non_core_shape.js b/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/non_core_shape.js deleted file mode 100644 index 07e99731e89f..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/last-index-of/lib/non_core_shape.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 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 normalizeIndices = require( '@stdlib/ndarray/base/to-unique-normalized-indices' ); -var indicesComplement = require( '@stdlib/array/base/indices-complement' ); -var takeIndexed = require( '@stdlib/array/base/take-indexed' ); - - -// MAIN // - -/** -* Returns the shape defined by the dimensions which are **not** included in a list of dimensions. -* -* @private -* @param {NonNegativeIntegerArray} shape - input ndarray -* @param {IntegerArray} dims - list of dimensions -* @returns {NonNegativeIntegerArray} shape -*/ -function nonCoreShape( shape, dims ) { // TODO: consider moving to a `@stdlib/ndarray/base` utility - var ind = normalizeIndices( dims, shape.length-1 ); - if ( ind === null ) { - // Note: this is an error condition, as `null` is returned when provided out-of-bounds indices... - return []; - } - return takeIndexed( shape, indicesComplement( shape.length, ind ) ); -} - - -// EXPORTS // - -module.exports = nonCoreShape; diff --git a/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js b/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js index f244d4e74c35..008a712f980c 100644 --- a/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js @@ -30,11 +30,11 @@ var isRealFloatingDataType = require( '@stdlib/ndarray/base/assert/is-real-float var isSignedIntegerDataType = require( '@stdlib/ndarray/base/assert/is-signed-integer-data-type' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var format = require( '@stdlib/string/format' ); -var nonCoreShape = require( './non_core_shape.js' ); var base = require( './base.js' ); diff --git a/lib/node_modules/@stdlib/blas/ext/sorthp/lib/non_core_shape.js b/lib/node_modules/@stdlib/blas/ext/sorthp/lib/non_core_shape.js deleted file mode 100644 index 07e99731e89f..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/sorthp/lib/non_core_shape.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 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 normalizeIndices = require( '@stdlib/ndarray/base/to-unique-normalized-indices' ); -var indicesComplement = require( '@stdlib/array/base/indices-complement' ); -var takeIndexed = require( '@stdlib/array/base/take-indexed' ); - - -// MAIN // - -/** -* Returns the shape defined by the dimensions which are **not** included in a list of dimensions. -* -* @private -* @param {NonNegativeIntegerArray} shape - input ndarray -* @param {IntegerArray} dims - list of dimensions -* @returns {NonNegativeIntegerArray} shape -*/ -function nonCoreShape( shape, dims ) { // TODO: consider moving to a `@stdlib/ndarray/base` utility - var ind = normalizeIndices( dims, shape.length-1 ); - if ( ind === null ) { - // Note: this is an error condition, as `null` is returned when provided out-of-bounds indices... - return []; - } - return takeIndexed( shape, indicesComplement( shape.length, ind ) ); -} - - -// EXPORTS // - -module.exports = nonCoreShape; diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/README.md b/lib/node_modules/@stdlib/ndarray/base/complement-shape/README.md new file mode 100644 index 000000000000..b5ecb07aeede --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/README.md @@ -0,0 +1,124 @@ + + +# complementShape + +> Return the shape defined by the dimensions which are not included in a list of dimensions. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var complementShape = require( '@stdlib/ndarray/base/complement-shape' ); +``` + +#### complementShape( shape, dims ) + +Returns the shape defined by the dimensions which are not included in a list of dimensions. + +```javascript +var sh = complementShape( [ 3, 2 ], [ -1 ] ); +// returns [ 3 ] +``` + +The function accepts the following parameters: + +- **shape**: array shape. +- **dims**: list of dimensions. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zip = require( '@stdlib/array/base/zip' ); +var filled = require( '@stdlib/array/base/filled' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var complementShape = require( '@stdlib/ndarray/base/complement-shape' ); + +var opts = { + 'dtype': 'int32' +}; +var d1 = discreteUniform( 100, 1, 10, opts ); +var d2 = discreteUniform( d1.length, 1, 10, opts ); +var d3 = discreteUniform( d1.length, 1, 10, opts ); +var d4 = discreteUniform( d1.length, 1, 10, opts ); + +var dims = discreteUniform( 2, -4, 3, opts ); +var shapes = zip( [ d1, d2, d3, d4 ] ); + +logEachMap( 'shape: (%s). dims: (%s). complement: (%s).', shapes, filled( dims, d1.length ), complementShape ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/complement-shape/benchmark/benchmark.js new file mode 100644 index 000000000000..60aeaa4d7880 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/benchmark/benchmark.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var complementShape = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var shape; + var out; + var i; + + shape = discreteUniform( 5, 1, 10, { + 'dtype': 'generic' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + shape[ 0 ] += 1; + out = complementShape( shape, [ -1, -2, -4 ] ); + if ( out.length !== 2 ) { + 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/complement-shape/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/repl.txt new file mode 100644 index 000000000000..d13e0e06be9e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}( shape, dims ) + Returns the shape defined by the dimensions which are not included in a list + of dimensions. + + Parameters + ---------- + shape: ArrayLike + Array shape. + + dims: ArrayLike + List of dimensions. + + Returns + ------- + out: Array + Output shape. + + Examples + -------- + > var sh = [ 3, 2 ]; + > var out = {{alias}}( sh, [ 1 ] ) + [ 3 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/types/index.d.ts new file mode 100644 index 000000000000..6b2d35290444 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Returns the shape defined by the dimensions which are not included in a list of dimensions. +* +* @param shape - array shape +* @param dims - list of dimensions +* @returns output shape +* +* @example +* var sh = complementShape( [ 3, 2 ], [ -1 ] ); +* // returns [ 3 ] +* +* sh = complementShape( [ 3, 2, 1 ], [ -2 ] ); +* // returns [ 3, 1 ] +* +* sh = complementShape( [ 3 ], [ 0 ] ); +* // returns [] +* +* sh = complementShape( [ 3, 2 ], [ 0 ] ); +* // returns [ 2 ] +* +* sh = complementShape( [ 3 ], [ 0 ] ); +* // returns [] +* +* sh = complementShape( [], [] ); +* // returns [] +*/ +declare function complementShape( shape: Collection, dims: Collection ): Array; + + +// EXPORTS // + +export = complementShape; diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/types/test.ts new file mode 100644 index 000000000000..6ba3862d8892 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/docs/types/test.ts @@ -0,0 +1,59 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 complementShape = require( './index' ); + + +// TESTS // + +// The function returns an array of numbers... +{ + complementShape( [ 3, 2, 1 ], [ -1 ] ); // $ExpectType number[] +} + +// The compiler throws an error if the function is provided a first argument that is not an array-like object containing numbers... +{ + complementShape( true, [ -1 ] ); // $ExpectError + complementShape( false, [ -1 ] ); // $ExpectError + complementShape( null, [ -1 ] ); // $ExpectError + complementShape( undefined, [ -1 ] ); // $ExpectError + complementShape( '5', [ -1 ] ); // $ExpectError + complementShape( [ '1', '2' ], [ -1 ] ); // $ExpectError + complementShape( {}, [ -1 ] ); // $ExpectError + complementShape( ( x: number ): number => x, [ -1 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not an array-like object containing numbers... +{ + complementShape( [ 2, 3 ], 5 ); // $ExpectError + complementShape( [ 2, 3 ], true ); // $ExpectError + complementShape( [ 2, 3 ], false ); // $ExpectError + complementShape( [ 2, 3 ], null ); // $ExpectError + complementShape( [ 2, 3 ], undefined ); // $ExpectError + complementShape( [ 2, 3 ], '5' ); // $ExpectError + complementShape( [ 2, 3 ], [ '1', '2' ] ); // $ExpectError + complementShape( [ 2, 3 ], {} ); // $ExpectError + complementShape( [ 2, 3 ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + complementShape(); // $ExpectError + complementShape( [ 3, 2 ] ); // $ExpectError + complementShape( [ 3, 2 ], [ -1 ], 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/complement-shape/examples/index.js new file mode 100644 index 000000000000..c681d9ff63ae --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zip = require( '@stdlib/array/base/zip' ); +var filled = require( '@stdlib/array/base/filled' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var complementShape = require( './../lib' ); + +var opts = { + 'dtype': 'int32' +}; +var d1 = discreteUniform( 100, 1, 10, opts ); +var d2 = discreteUniform( d1.length, 1, 10, opts ); +var d3 = discreteUniform( d1.length, 1, 10, opts ); +var d4 = discreteUniform( d1.length, 1, 10, opts ); + +var dims = discreteUniform( 2, -4, 3, opts ); +var shapes = zip( [ d1, d2, d3, d4 ] ); + +logEachMap( 'shape: (%s). dims: (%s). complement: (%s).', shapes, filled( dims, d1.length ), complementShape ); diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/complement-shape/lib/index.js new file mode 100644 index 000000000000..27442c7e1f36 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Return the shape defined by the dimensions which are not included in a list of dimensions. +* +* @module @stdlib/ndarray/base/complement-shape +* +* @example +* var complementShape = require( '@stdlib/ndarray/base/complement-shape' ); +* +* var sh = complementShape( [ 3, 2 ], [ 0 ] ); +* // returns [ 2 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/cusum/lib/non_core_shape.js b/lib/node_modules/@stdlib/ndarray/base/complement-shape/lib/main.js similarity index 86% rename from lib/node_modules/@stdlib/blas/ext/cusum/lib/non_core_shape.js rename to lib/node_modules/@stdlib/ndarray/base/complement-shape/lib/main.js index 07e99731e89f..d9f37c6219d8 100644 --- a/lib/node_modules/@stdlib/blas/ext/cusum/lib/non_core_shape.js +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/lib/main.js @@ -30,12 +30,15 @@ var takeIndexed = require( '@stdlib/array/base/take-indexed' ); /** * Returns the shape defined by the dimensions which are **not** included in a list of dimensions. * -* @private -* @param {NonNegativeIntegerArray} shape - input ndarray +* @param {NonNegativeIntegerArray} shape - input shape * @param {IntegerArray} dims - list of dimensions * @returns {NonNegativeIntegerArray} shape +* +* @example +* var sh = complementShape( [ 3, 2 ], [ 0 ] ); +* // returns [ 2 ] */ -function nonCoreShape( shape, dims ) { // TODO: consider moving to a `@stdlib/ndarray/base` utility +function complementShape( shape, dims ) { var ind = normalizeIndices( dims, shape.length-1 ); if ( ind === null ) { // Note: this is an error condition, as `null` is returned when provided out-of-bounds indices... @@ -47,4 +50,4 @@ function nonCoreShape( shape, dims ) { // TODO: consider moving to a `@stdlib/nd // EXPORTS // -module.exports = nonCoreShape; +module.exports = complementShape; diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/package.json b/lib/node_modules/@stdlib/ndarray/base/complement-shape/package.json new file mode 100644 index 000000000000..9b83ad65f24f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/ndarray/base/complement-shape", + "version": "0.0.0", + "description": "Return the shape defined by the dimensions which are not included in a list of 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", + "lib": "./lib", + "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", + "complement", + "subshape", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/complement-shape/test/test.js b/lib/node_modules/@stdlib/ndarray/base/complement-shape/test/test.js new file mode 100644 index 000000000000..c36bb4e36ca5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/complement-shape/test/test.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 complementShape = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof complementShape, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a complement shape', function test( t ) { + var expected; + var actual; + var shape; + + shape = [ 3, 2 ]; + expected = [ 3 ]; + actual = complementShape( shape, [ 1 ] ); + + 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 ]; + expected = [ 2, 10 ]; + actual = complementShape( shape, [ 1 ] ); + + 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 ]; + expected = [ 2, 1, 10 ]; + actual = complementShape( shape, [] ); + + 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 ]; + expected = [ 10 ]; + actual = complementShape( shape, [ -3, -2 ] ); + + 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 ]; + expected = [ 1 ]; + actual = complementShape( shape, [ 0, -1 ] ); + + 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(); +}); + +tape( 'the function returns an empty array when provided out-of-bounds indices', function test( t ) { + var expected; + var actual; + var shape; + + shape = [ 3, 2 ]; + expected = []; + actual = complementShape( shape, [ 10 ] ); + + 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 = [ 3, 2 ]; + expected = []; + actual = complementShape( shape, [ -10 ] ); + + 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(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/lib/index.js index 61bf28fa14bd..3dd0b64ff4c1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/lib/index.js @@ -265,6 +265,15 @@ setReadOnly( ns, 'char2dtype', require( '@stdlib/ndarray/base/char2dtype' ) ); */ setReadOnly( ns, 'clampIndex', require( '@stdlib/ndarray/base/clamp-index' ) ); +/** +* @name complementShape +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/ndarray/base/complement-shape} +*/ +setReadOnly( ns, 'complementShape', require( '@stdlib/ndarray/base/complement-shape' ) ); + /** * @name copy * @memberof ns