From 8c87bcdd136c7dd4181d8c80615ceda54f706f57 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 22 Feb 2026 23:08:57 +0500 Subject: [PATCH 1/6] feat: add ndarray/base/atleastnd --- 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 --- --- .../@stdlib/ndarray/base/atleastnd/README.md | 113 ++++++++++++++++++ .../base/atleastnd/benchmark/benchmark.js | 103 ++++++++++++++++ .../ndarray/base/atleastnd/docs/repl.txt | 29 +++++ .../base/atleastnd/docs/types/index.d.ts | 49 ++++++++ .../ndarray/base/atleastnd/docs/types/test.ts | 68 +++++++++++ .../ndarray/base/atleastnd/examples/index.js | 35 ++++++ .../ndarray/base/atleastnd/lib/index.js | 47 ++++++++ .../ndarray/base/atleastnd/lib/main.js | 107 +++++++++++++++++ .../ndarray/base/atleastnd/package.json | 65 ++++++++++ .../ndarray/base/atleastnd/test/test.js | 89 ++++++++++++++ 10 files changed, 705 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md b/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md new file mode 100644 index 000000000000..560d48ad590d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md @@ -0,0 +1,113 @@ + + +# atleastnd + +> Convert the inputs to ndarrays having at least the provided number of dimensions. + +
+ +
+ + + +
+ +## Usage + +```javascript +var atleastnd = require( '@stdlib/ndarray/base/atleastnd' ); +``` + +#### atleastnd( ndims, arrays ) + +Converts the inputs to ndarrays having at least the provided number of dimensions. + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] ); +// returns [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] + +var y = array( [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ); +// returns [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] + +var out = atleastnd( 3, [ x, y ] ); +// returns [ , ] +``` + +The function accepts the following arguments: + +- **ndims**: minimum number of dimensions. +- **arrays**: array-like object containing a list of arrays. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var atleastnd = require( '@stdlib/ndarray/base/atleastnd' ); + +var x = discreteUniform( [ 2, 2, 2 ], -100, 100 ); +// returns + +var y = discreteUniform( [ 5, 2 ], -100, 100 ); +// returns + +var out = atleastnd( 3, [ x, y ] ); +// returns [ , ] + +console.log( ndarray2array( out[ 0 ] ) ); +console.log( ndarray2array( out[ 1 ] ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/benchmark/benchmark.js new file mode 100644 index 000000000000..bdca3c6e1058 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ndarrayBase = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var atleastnd = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::base_ndarray:ndims=2', pkg ), function benchmark( b ) { + var values; + var buffer; + var offset; + var dtype; + var order; + var out; + var i; + + dtype = 'float64'; + buffer = new Float64Array( 12 ); + offset = 0; + order = 'row-major'; + + values = [ + ndarrayBase( dtype, buffer, [ 3, 2, 2 ], [ 4, 2, 1 ], offset, order ), + ndarrayBase( dtype, buffer, [ 4, 3 ], [ 3, 1 ], offset, order ), + ndarrayBase( dtype, buffer, [ 12 ], [ 1 ], offset, order ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = atleastnd( 2, [ 10.0, values[ i%values.length ] ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::ndarray:ndims=2', pkg ), function benchmark( b ) { + var values; + var buffer; + var offset; + var dtype; + var order; + var out; + var i; + + dtype = 'float64'; + buffer = new Float64Array( 12 ); + offset = 0; + order = 'row-major'; + + values = [ + ndarray( dtype, buffer, [ 3, 2, 2 ], [ 4, 2, 1 ], offset, order ), + ndarray( dtype, buffer, [ 4, 3 ], [ 3, 1 ], offset, order ), + ndarray( dtype, buffer, [ 12 ], [ 1 ], offset, order ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = atleastnd( 2, [ 10.0, values[ i%values.length ] ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt new file mode 100644 index 000000000000..9d28a32f58df --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( ndims, arrays ) + Converts the inputs to ndarrays having at least the provided number of + dimensions. + + Parameters + ---------- + ndims: number + Minimum number of dimensions. + + arrays: ArrayLikeObject + List of arrays. + + Returns + ------- + out: Array + List of arrays. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + [ [ 1, 2 ], [ 3, 4 ] ] + > var y = {{alias:@stdlib/ndarray/array}}( [ 5, 6, 7, 8 ] ) + [ 5, 6, 7, 8 ] + > var out = {{alias}}( 3, [ x, y ] ) + [ , ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts new file mode 100644 index 000000000000..ae512a75c731 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Converts the inputs to ndarrays having at least the provided number of dimensions. +* +* @param ndims - minimum number of dimensions +* @param arrays - array-like object containing a list of arrays +* @returns output arrays +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* +* var y = array( [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ); +* // returns [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] +* +* var out = atleastnd( 3, [ x, y ] ); +* // returns [ , ] +*/ +declare function atleastnd( ndims: number, arrays: Array ): Array; + + +// EXPORTS // + +export = atleastnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts new file mode 100644 index 000000000000..2f368973c109 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts @@ -0,0 +1,68 @@ +/* +* @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 zeros = require( '@stdlib/ndarray/zeros' ); +import atleastnd = require( './index' ); + + +// TESTS // + +// The function returns an array of ndarrays... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2, 2 ] ); + + atleastnd( 3, [ x ] ); // $ExpectType ndarray[] + atleastnd( 3, [ x, y ] ); // $ExpectType ndarray[] + atleastnd( 3, [ x, y, x ] ); // $ExpectType ndarray[] +} + +// The compiler throws an error if the function is not provided a first argument which is a number... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2, 2 ] ); + + atleastnd( '5', [ x, y ] ); // $ExpectError + atleastnd( true, [ x, y ] ); // $ExpectError + atleastnd( false, [ x, y ] ); // $ExpectError + atleastnd( null, [ x, y ] ); // $ExpectError + atleastnd( {}, [ x, y ] ); // $ExpectError + atleastnd( [ '5' ], [ x, y ] ); // $ExpectError + atleastnd( ( x: number ): number => x, [ x, y ] ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a second argument which is an array ... +{ + atleastnd( 3, '5' ); // $ExpectError + atleastnd( 3, 5 ); // $ExpectError + atleastnd( 3, true ); // $ExpectError + atleastnd( 3, false ); // $ExpectError + atleastnd( 3, null ); // $ExpectError + atleastnd( 3, {} ); // $ExpectError + atleastnd( 3, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ] ); + const y = zeros( [ 2, 2, 2 ] ); + + atleastnd(); // $ExpectError + atleastnd( 3 ); // $ExpectError + atleastnd( 3, [ x, y ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js new file mode 100644 index 000000000000..81fd004ab2ce --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var atleastnd = require( './../lib' ); + +var x = discreteUniform( [ 3, 2, 2 ], -100, 100 ); +// returns + +var y = discreteUniform( [ 5, 2 ], -100, 100 ); +// returns + +var out = atleastnd( 3, [ x, y ] ); +// returns [ , ] + +console.log( ndarray2array( out[ 0 ] ) ); +console.log( ndarray2array( out[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js new file mode 100644 index 000000000000..ffa3b22ebecc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js @@ -0,0 +1,47 @@ +/** +* @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'; + +/** +* Convert the inputs to ndarrays having at least the provided number of dimensions. +* +* @module @stdlib/ndarray/base/atleastnd +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var atleastnd = require( '@stdlib/ndarray/base/atleastnd' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* +* var y = array( [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ); +* // returns [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] +* +* var out = atleastnd( 3, [ x, y ] ); +* // returns [ , ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js new file mode 100644 index 000000000000..0b13d1d42368 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js @@ -0,0 +1,107 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var dims = require( '@stdlib/ndarray/base/ndims' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ones = require( '@stdlib/array/base/ones' ); + + +// VARIABLES // + +var DTYPE = defaults.get( 'dtypes.default' ); +var ORDER = defaults.get( 'order' ); + + +// MAIN // + +/** +* Converts the inputs to ndarrays having at least the provided number of dimensions. +* +* @param {NonNegativeInteger} ndims - minimum number of dimensions +* @param {ArrayLikeObject} arrays - array-like object containing a list of arrays +* @returns {ArrayLikeObject} output arrays +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* +* var y = array( [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ); +* // returns [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] +* +* var out = atleastnd( 3, [ x, y ] ); +* // returns [ , ] +*/ +function atleastnd( ndims, arrays ) { + var strides; + var shape; + var out; + var sh; + var st; + var N; + var n; + var i; + var j; + + out = []; + for ( i = 0; i < arrays.length; i++ ) { + if ( isndarrayLike( arrays[ i ] ) ) { + N = dims( arrays[ i ] ); + if ( N >= ndims ) { + out.push( arrays[ i ] ); + } else { + sh = getShape( arrays[ i ], false ); + n = ndims - N; + st = getStrides( arrays[ i ], false ); + shape = []; + strides = []; + for ( j = 0; j < n; j++ ) { + shape.push( 1 ); + strides.push( st[ 0 ] ); + } + for ( j = 0; j < sh.length; j++ ) { + shape.push( sh[ j ] ); + strides.push( st[ j ] ); + } + out.push( ndarray( getDType( arrays[ i ] ), getData( arrays[ i ] ), shape, strides, getOffset( arrays[ i ] ), getOrder( arrays[ i ] ) ) ); // eslint-disable-line max-len + } + } else { + out.push( broadcastScalar( arrays[ i ], DTYPE, ones( ndims ), ORDER ) ); // eslint-disable-line max-len + } + } + return out; +} + + +// EXPORTS // + +module.exports = atleastnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json b/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json new file mode 100644 index 000000000000..9376fc616fdb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ndarray/base/atleastnd", + "version": "0.0.0", + "description": "Coverts the inputs to ndarrays having at least the provided number 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", + "include": "./include", + "lib": "./lib", + "scripts": "./scripts", + "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", + "base", + "strided", + "array", + "ndarray", + "atleast", + "broadcast", + "np.atleast_1d" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js new file mode 100644 index 000000000000..ad3e6a8704e8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js @@ -0,0 +1,89 @@ +/** +* @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 getShape = require( '@stdlib/ndarray/base/shape' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var atleastnd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof atleastnd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function converts the inputs to ndarrays having at least the provided number of dimensions.', function test( t ) { + var out; + var x; + var y; + var z; + + x = zeros( [ 2, 2 ] ); + y = zeros( [ 2 ] ); + z = 10.0; + + out = atleastnd( 3, [ x, y, z ] ); + + t.strictEqual( isArray( out ), true, 'returns expected value' ); + t.deepEqual( getShape( out[ 0 ] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 1 ] ), [ 1, 1, 2 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 2 ] ), [ 1, 1, 1 ], 'returns expected value' ); + t.notEqual( out[ 0 ], x, 'returns new instance' ); + t.notEqual( out[ 1 ], y, 'returns new instance' ); + t.notEqual( out[ 2 ], z, 'returns new instance' ); + t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the same ndarray if provided an ndarray having dimensions more than or equal to `ndims`', function test( t ) { + var out; + var x; + var y; + var z; + + x = zeros( [ 2, 2 ] ); + y = zeros( [ 3, 2, 2 ] ); + z = zeros( [ 1, 3, 2, 2 ] ); + + out = atleastnd( 3, [ x, y, z ] ); + + t.strictEqual( isArray( out ), true, 'returns expected value' ); + t.deepEqual( getShape( out[ 0 ] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 1 ] ), [ 3, 2, 2 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 2 ] ), [ 1, 3, 2, 2 ], 'returns expected value' ); + t.notEqual( out[ 0 ], x, 'returns new instance' ); + t.strictEqual( out[ 1 ], y, 'returns new instance' ); + t.strictEqual( out[ 2 ], z, 'returns new instance' ); + t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); + + t.end(); +}); From c7b2a99fd3026ce70d373d2b34bd7c9edf66b897 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 22 Feb 2026 23:19:28 +0500 Subject: [PATCH 2/6] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/atleastnd/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js index 81fd004ab2ce..51c237037f94 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/examples/index.js @@ -19,7 +19,7 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/discrete-uniform' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var atleastnd = require( './../lib' ); var x = discreteUniform( [ 3, 2, 2 ], -100, 100 ); From 45165b15c41205c29e690400dbb39ae928885ce3 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 22 Feb 2026 23:22:04 +0500 Subject: [PATCH 3/6] docs: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md b/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md index 560d48ad590d..d49e4ce536a1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md @@ -78,7 +78,7 @@ The function accepts the following arguments: ```javascript var discreteUniform = require( '@stdlib/random/discrete-uniform' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var atleastnd = require( '@stdlib/ndarray/base/atleastnd' ); var x = discreteUniform( [ 2, 2, 2 ], -100, 100 ); From 4ce22f76b3c85f10dc4f9fdba8111e2003f05090 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 22 Feb 2026 23:24:45 +0500 Subject: [PATCH 4/6] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json b/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json index 9376fc616fdb..b3a9a45cd889 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json @@ -18,10 +18,7 @@ "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", - "include": "./include", "lib": "./lib", - "scripts": "./scripts", - "src": "./src", "test": "./test" }, "types": "./docs/types", From c52b6820196ac4cdf003118bfef9e8730e133a8b Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 27 Feb 2026 16:53:44 -0800 Subject: [PATCH 5/6] 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: na - 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 --- --- .../@stdlib/ndarray/base/atleastnd/README.md | 28 ++++++-- .../ndarray/base/atleastnd/docs/repl.txt | 8 +-- .../base/atleastnd/docs/types/index.d.ts | 9 +-- .../ndarray/base/atleastnd/docs/types/test.ts | 5 +- .../ndarray/base/atleastnd/lib/index.js | 2 +- .../ndarray/base/atleastnd/lib/main.js | 72 ++++++++++++------- .../ndarray/base/atleastnd/package.json | 2 +- .../ndarray/base/atleastnd/test/test.js | 42 ++++++++--- 8 files changed, 117 insertions(+), 51 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md b/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md index d49e4ce536a1..90a9dc2ee03b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/README.md @@ -20,7 +20,7 @@ limitations under the License. # atleastnd -> Convert the inputs to ndarrays having at least the provided number of dimensions. +> Convert a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions.
@@ -38,9 +38,7 @@ var atleastnd = require( '@stdlib/ndarray/base/atleastnd' ); #### atleastnd( ndims, arrays ) -Converts the inputs to ndarrays having at least the provided number of dimensions. - - +Converts a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions. ```javascript var array = require( '@stdlib/ndarray/array' ); @@ -58,7 +56,7 @@ var out = atleastnd( 3, [ x, y ] ); The function accepts the following arguments: - **ndims**: minimum number of dimensions. -- **arrays**: array-like object containing a list of arrays. +- **arrays**: array-like object containing a list of scalars and/or ndarrays.
@@ -66,6 +64,20 @@ The function accepts the following arguments:
+## Notes + +- If a provided ndarray has fewer dimensions than `ndims`, the returned ndarray is a view on the input ndarray data buffer. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned ndarray, copy the ndarray **before** performing operations which may mutate elements. + +- The returned ndarray is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarray][@stdlib/ndarray/base/ctor] does not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. + +- If provided a scalar value (i.e., a non-ndarray) and that value + + - is a number, the returned ndarray will have the [default][@stdlib/ndarray/defaults] real-valued floating-point data type. + - is a boolean, the returned ndarray will have the [default][@stdlib/ndarray/defaults] boolean data type. + - is a complex number object of a known data type, the data type of the returned ndarray will be the same as the provided value. + - is a complex number object of an unknown data type, the returned ndarray will have the [default][@stdlib/ndarray/defaults] complex-valued floating-point data type. + - is any other value type, the returned ndarray will have a `'generic'` data type. +
@@ -108,6 +120,12 @@ console.log( ndarray2array( out[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt index 9d28a32f58df..756b4b555197 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( ndims, arrays ) - Converts the inputs to ndarrays having at least the provided number of - dimensions. + Converts a list of values (scalars and/or ndarrays) to ndarrays having at + least a specified number of dimensions. Parameters ---------- @@ -9,12 +9,12 @@ Minimum number of dimensions. arrays: ArrayLikeObject - List of arrays. + List of scalars and/or ndarrays. Returns ------- out: Array - List of arrays. + List of ndarrays. Examples -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts index ae512a75c731..339904717703 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/index.d.ts @@ -20,14 +20,15 @@ /// +import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; /** -* Converts the inputs to ndarrays having at least the provided number of dimensions. +* Converts a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions. * * @param ndims - minimum number of dimensions -* @param arrays - array-like object containing a list of arrays -* @returns output arrays +* @param arrays - array-like object containing a list of scalars and/or ndarrays +* @returns an array of ndarrays * * @example * var array = require( '@stdlib/ndarray/array' ); @@ -41,7 +42,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * var out = atleastnd( 3, [ x, y ] ); * // returns [ , ] */ -declare function atleastnd( ndims: number, arrays: Array ): Array; +declare function atleastnd( ndims: number, arrays: ArrayLike ): Array; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts index 2f368973c109..75be55e3afbd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/docs/types/test.ts @@ -32,7 +32,7 @@ import atleastnd = require( './index' ); atleastnd( 3, [ x, y, x ] ); // $ExpectType ndarray[] } -// The compiler throws an error if the function is not provided a first argument which is a number... +// The compiler throws an error if the function is provided a first argument which is not a number... { const x = zeros( [ 2, 2 ] ); const y = zeros( [ 2, 2, 2 ] ); @@ -46,9 +46,8 @@ import atleastnd = require( './index' ); atleastnd( ( x: number ): number => x, [ x, y ] ); // $ExpectError } -// The compiler throws an error if the function is not provided a second argument which is an array ... +// The compiler throws an error if the function is provided a second argument which is not an array ... { - atleastnd( 3, '5' ); // $ExpectError atleastnd( 3, 5 ); // $ExpectError atleastnd( 3, true ); // $ExpectError atleastnd( 3, false ); // $ExpectError diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js index ffa3b22ebecc..35879905f019 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Convert the inputs to ndarrays having at least the provided number of dimensions. +* Convert a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions. * * @module @stdlib/ndarray/base/atleastnd * diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js index 0b13d1d42368..e742eb6cbdfb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js @@ -21,6 +21,10 @@ // MODULES // var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var complexDataType = require( '@stdlib/complex/dtype' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var dims = require( '@stdlib/ndarray/base/ndims' ); var defaults = require( '@stdlib/ndarray/defaults' ); @@ -36,18 +40,20 @@ var ones = require( '@stdlib/array/base/ones' ); // VARIABLES // -var DTYPE = defaults.get( 'dtypes.default' ); +var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' ); +var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' ); +var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' ); var ORDER = defaults.get( 'order' ); // MAIN // /** -* Converts the inputs to ndarrays having at least the provided number of dimensions. +* Converts a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions. * * @param {NonNegativeInteger} ndims - minimum number of dimensions -* @param {ArrayLikeObject} arrays - array-like object containing a list of arrays -* @returns {ArrayLikeObject} output arrays +* @param {ArrayLikeObject} arrays - array-like object containing a list of scalars and/or ndarrays +* @returns {Array} list of ndarrays * * @example * var array = require( '@stdlib/ndarray/array' ); @@ -67,36 +73,54 @@ function atleastnd( ndims, arrays ) { var out; var sh; var st; + var dt; + var v; var N; - var n; var i; var j; out = []; for ( i = 0; i < arrays.length; i++ ) { - if ( isndarrayLike( arrays[ i ] ) ) { - N = dims( arrays[ i ] ); + v = arrays[ i ]; + if ( isndarrayLike( v ) ) { + N = dims( v ); if ( N >= ndims ) { - out.push( arrays[ i ] ); - } else { - sh = getShape( arrays[ i ], false ); - n = ndims - N; - st = getStrides( arrays[ i ], false ); - shape = []; - strides = []; - for ( j = 0; j < n; j++ ) { - shape.push( 1 ); - strides.push( st[ 0 ] ); - } - for ( j = 0; j < sh.length; j++ ) { - shape.push( sh[ j ] ); - strides.push( st[ j ] ); - } - out.push( ndarray( getDType( arrays[ i ] ), getData( arrays[ i ] ), shape, strides, getOffset( arrays[ i ] ), getOrder( arrays[ i ] ) ) ); // eslint-disable-line max-len + out.push( v ); + continue; + } + sh = getShape( v, false ); + st = getStrides( v, false ); + + shape = []; + strides = []; + + // Prepend singleton dimensions... + for ( j = 0; j < ndims-N; j++ ) { + shape.push( 1 ); + strides.push( st[ 0 ] ); + } + // Copy remaining dimensions... + for ( j = 0; j < sh.length; j++ ) { + shape.push( sh[ j ] ); + strides.push( st[ j ] ); + } + out.push( new ndarray( getDType( v ), getData( v ), shape, strides, getOffset( v ), getOrder( v ) ) ); // eslint-disable-line max-len + continue; + } + // For scalar values, resolve a corresponding ndarray data type... + if ( isNumber( v ) ) { // TODO: consider abstracting this logic to an `ndarray/base/scalar-dtype` (???) package, as this logic is found elsewhere (e.g., `ndarray/from-scalar`) and it would be good to avoid duplication, especially as we add support for more ndarray data types + dt = DEFAULT_REAL; + } else if ( isBoolean( v ) ) { + dt = DEFAULT_BOOL; + } else if ( isComplexLike( v ) ) { + dt = complexDataType( v ); + if ( dt === null ) { + dt = DEFAULT_CMPLX; } } else { - out.push( broadcastScalar( arrays[ i ], DTYPE, ones( ndims ), ORDER ) ); // eslint-disable-line max-len + dt = 'generic'; } + out.push( broadcastScalar( v, dt, ones( ndims ), ORDER ) ); } return out; } diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json b/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json index b3a9a45cd889..972946320b26 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/atleastnd", "version": "0.0.0", - "description": "Coverts the inputs to ndarrays having at least the provided number of dimensions.", + "description": "Convert a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js index ad3e6a8704e8..bf5d34107720 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js @@ -25,6 +25,7 @@ var isArray = require( '@stdlib/assert/is-array' ); var getShape = require( '@stdlib/ndarray/base/shape' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); var atleastnd = require( './../lib' ); @@ -36,33 +37,56 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function converts the inputs to ndarrays having at least the provided number of dimensions.', function test( t ) { +tape( 'the function a list of values (scalars and/or ndarrays) to ndarrays having at least a specified number of dimensions', function test( t ) { var out; var x; var y; var z; + var w; + var u; + var v; + var s; x = zeros( [ 2, 2 ] ); y = zeros( [ 2 ] ); z = 10.0; + w = true; + u = new Complex128( 1.0, 2.0 ); + v = { + 're': 3.0, + 'im': 4.0 + }; + s = 'beep'; - out = atleastnd( 3, [ x, y, z ] ); + out = atleastnd( 3, [ x, y, z, w, u, v, s ] ); t.strictEqual( isArray( out ), true, 'returns expected value' ); t.deepEqual( getShape( out[ 0 ] ), [ 1, 2, 2 ], 'returns expected value' ); t.deepEqual( getShape( out[ 1 ] ), [ 1, 1, 2 ], 'returns expected value' ); t.deepEqual( getShape( out[ 2 ] ), [ 1, 1, 1 ], 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.notEqual( out[ 1 ], y, 'returns new instance' ); - t.notEqual( out[ 2 ], z, 'returns new instance' ); + t.deepEqual( getShape( out[ 3 ] ), [ 1, 1, 1 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 4 ] ), [ 1, 1, 1 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 5 ] ), [ 1, 1, 1 ], 'returns expected value' ); + t.deepEqual( getShape( out[ 6 ] ), [ 1, 1, 1 ], 'returns expected value' ); + t.notEqual( out[ 0 ], x, 'returns expected value' ); + t.notEqual( out[ 1 ], y, 'returns expected value' ); + t.notEqual( out[ 2 ], z, 'returns expected value' ); + t.notEqual( out[ 3 ], w, 'returns expected value' ); + t.notEqual( out[ 4 ], u, 'returns expected value' ); + t.notEqual( out[ 5 ], v, 'returns expected value' ); + t.notEqual( out[ 6 ], s, 'returns expected value' ); t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 3 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 4 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 5 ] instanceof ndarray, true, 'returns expected value' ); + t.strictEqual( out[ 6 ] instanceof ndarray, true, 'returns expected value' ); t.end(); }); -tape( 'the function returns the same ndarray if provided an ndarray having dimensions more than or equal to `ndims`', function test( t ) { +tape( 'the function returns an ndarray unchanged if an ndarray has at least a specified number of dimensions', function test( t ) { var out; var x; var y; @@ -78,9 +102,9 @@ tape( 'the function returns the same ndarray if provided an ndarray having dimen t.deepEqual( getShape( out[ 0 ] ), [ 1, 2, 2 ], 'returns expected value' ); t.deepEqual( getShape( out[ 1 ] ), [ 3, 2, 2 ], 'returns expected value' ); t.deepEqual( getShape( out[ 2 ] ), [ 1, 3, 2, 2 ], 'returns expected value' ); - t.notEqual( out[ 0 ], x, 'returns new instance' ); - t.strictEqual( out[ 1 ], y, 'returns new instance' ); - t.strictEqual( out[ 2 ], z, 'returns new instance' ); + t.notEqual( out[ 0 ], x, 'returns expected value' ); + t.strictEqual( out[ 1 ], y, 'returns expected value' ); + t.strictEqual( out[ 2 ], z, 'returns expected value' ); t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' ); t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' ); t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' ); From df980d4358f6c4a04cc16c9eed7ae34e6cd8b6de Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 27 Feb 2026 17:00:01 -0800 Subject: [PATCH 6/6] test: add dtype tests --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/atleastnd/test/test.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js index bf5d34107720..d8344662e3e9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/test/test.js @@ -22,7 +22,9 @@ var tape = require( 'tape' ); var isArray = require( '@stdlib/assert/is-array' ); -var getShape = require( '@stdlib/ndarray/base/shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var defaults = require( '@stdlib/ndarray/defaults' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); @@ -68,6 +70,13 @@ tape( 'the function a list of values (scalars and/or ndarrays) to ndarrays havin t.deepEqual( getShape( out[ 4 ] ), [ 1, 1, 1 ], 'returns expected value' ); t.deepEqual( getShape( out[ 5 ] ), [ 1, 1, 1 ], 'returns expected value' ); t.deepEqual( getShape( out[ 6 ] ), [ 1, 1, 1 ], 'returns expected value' ); + t.strictEqual( String( getDType( out[ 0 ] ) ), String( getDType( x ) ), 'returns expected value' ); + t.strictEqual( String( getDType( out[ 1 ] ) ), String( getDType( y ) ), 'returns expected value' ); + t.strictEqual( String( getDType( out[ 2 ] ) ), String( defaults.get( 'dtypes.real_floating_point' ) ), 'returns expected value' ); + t.strictEqual( String( getDType( out[ 3 ] ) ), String( defaults.get( 'dtypes.boolean' ) ), 'returns expected value' ); + t.strictEqual( String( getDType( out[ 4 ] ) ), 'complex128', 'returns expected value' ); + t.strictEqual( String( getDType( out[ 5 ] ) ), String( defaults.get( 'dtypes.complex_floating_point' ) ), 'returns expected value' ); + t.strictEqual( String( getDType( out[ 6 ] ) ), 'generic', 'returns expected value' ); t.notEqual( out[ 0 ], x, 'returns expected value' ); t.notEqual( out[ 1 ], y, 'returns expected value' ); t.notEqual( out[ 2 ], z, 'returns expected value' );