From 8b9aa6761a0c5093e68cd14f24916bbf136cb5e5 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 1 Jan 2026 14:19:07 +0500 Subject: [PATCH 1/3] feat: add ndarray/prepend-singleton-dimensions --- 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 --- --- .../prepend-singleton-dimensions/README.md | 134 +++++++++++++++++ .../benchmark/benchmark.js | 127 ++++++++++++++++ .../docs/repl.txt | 28 ++++ .../docs/types/index.d.ts | 46 ++++++ .../docs/types/test.ts | 64 +++++++++ .../examples/index.js | 29 ++++ .../prepend-singleton-dimensions/lib/index.js | 44 ++++++ .../prepend-singleton-dimensions/lib/main.js | 62 ++++++++ .../prepend-singleton-dimensions/package.json | 66 +++++++++ .../prepend-singleton-dimensions/test/test.js | 135 ++++++++++++++++++ 10 files changed, 735 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md new file mode 100644 index 000000000000..37114c588389 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md @@ -0,0 +1,134 @@ + + +# prependSingletonDimensions + +> Return a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] where a specified number of singleton dimensions are prepended. + + + +
+ +
+ + + + + +
+ +## Usage + + + +```javascript +var prependSingletonDimensions = require( '@stdlib/ndarray/prepend-singleton-dimensions' ); +``` + +#### prependSingletonDimensions( x, n ) + +Returns a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] where a specified number of singleton dimensions are prepended. + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +// Create a 2x2 ndarray: +var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +// returns [ [ 1, 2 ], [ 3, 4 ] ] + +// Prepend singleton dimensions: +var y = prependSingletonDimensions( x, 3 ); +// returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] +``` + +The function accepts the following arguments: + +- **x**: input [`ndarray`][@stdlib/ndarray/ctor]. +- **n**: number of singleton dimensions to prepend. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + + + +```javascript +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var prependSingletonDimensions = require( '@stdlib/ndarray/prepend-singleton-dimensions' ); + +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); + +var y = prependSingletonDimensions( x, 3 ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js new file mode 100644 index 000000000000..599343c2da58 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js @@ -0,0 +1,127 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var empty = require( '@stdlib/ndarray/empty' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var prependSingletonDimensions = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::1d', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2 ], { 'dtype': 'float64' } ), + empty( [ 2 ], { 'dtype': 'float32' } ), + empty( [ 2 ], { 'dtype': 'int32' } ), + empty( [ 2 ], { 'dtype': 'complex128' } ), + empty( [ 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = prependSingletonDimensions( values[ i%values.length ], 1 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::2d', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = prependSingletonDimensions( values[ i%values.length ], 1 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::3d', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = prependSingletonDimensions( values[ i%values.length ], 1 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt new file mode 100644 index 000000000000..3e3ea818efbd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( x, n ) + Returns a read-only view of an input ndarray where a specified number of + singleton dimensions are prepended. + + Parameters + ---------- + x: ndarray + Input array. + + n: integer + Number of singleton dimensions to prepend. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + [ [ 1, 2 ], [ 3, 4 ] ] + > var y = {{alias}}( x, 3 ) + [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts new file mode 100644 index 000000000000..5035b5fc0f55 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @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'; + +/** +* Returns a read-only view of an input ndarray where a specified number of singleton dimensions are prepended. +* +* @param x - input array +* @param n - number of singleton dimensions to prepend +* @returns output array +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = prependSingletonDimensions( x, 3 ); +* // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] +*/ +declare function prependSingletonDimensions( x: ndarray, n: number ): ndarray; + + +// EXPORTS // + +export = prependSingletonDimensions; diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts new file mode 100644 index 000000000000..49f9fdaf45a9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts @@ -0,0 +1,64 @@ +/* +* @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 array = require( '@stdlib/ndarray/array' ); +import prependSingletonDimensions = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + + prependSingletonDimensions( x, 3 ); // $ExpectType ndarray +} + +// The compiler throws an error if the function is not provided a first argument which is an ndarray... +{ + prependSingletonDimensions( '5', 3 ); // $ExpectError + prependSingletonDimensions( 5, 3 ); // $ExpectError + prependSingletonDimensions( true, 3 ); // $ExpectError + prependSingletonDimensions( false, 3 ); // $ExpectError + prependSingletonDimensions( null, 3 ); // $ExpectError + prependSingletonDimensions( {}, 3 ); // $ExpectError + prependSingletonDimensions( [ '5' ], 3 ); // $ExpectError + prependSingletonDimensions( ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a second argument which is a number... +{ + const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + + prependSingletonDimensions( x, '5' ); // $ExpectError + prependSingletonDimensions( x, true ); // $ExpectError + prependSingletonDimensions( x, false ); // $ExpectError + prependSingletonDimensions( x, null ); // $ExpectError + prependSingletonDimensions( x, {} ); // $ExpectError + prependSingletonDimensions( x, [ '5' ] ); // $ExpectError + prependSingletonDimensions( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + + prependSingletonDimensions(); // $ExpectError + prependSingletonDimensions( x ); // $ExpectError + prependSingletonDimensions( x, 3, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js new file mode 100644 index 000000000000..01e00d5da172 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js @@ -0,0 +1,29 @@ +/** +* @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 uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var prependSingletonDimensions = require( './../lib' ); + +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); + +var y = prependSingletonDimensions( x, 1 ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js new file mode 100644 index 000000000000..9a446fac4594 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 a read-only view of an input ndarray where a specified number of singleton dimensions are prepended. +* +* @module @stdlib/ndarray/prepend-singleton-dimensions +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var prependSingletonDimensions = require( '@stdlib/ndarray/prepend-singleton-dimensions' ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = prependSingletonDimensions( x, 3 ); +* // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js new file mode 100644 index 000000000000..b186407da874 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var base = require( '@stdlib/ndarray/base/prepend-singleton-dimensions' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a read-only view of an input ndarray where a specified number of singleton dimensions are prepended. +* +* @param {ndarray} x - input array +* @param {NonNegativeInteger} n - number of singleton dimensions to prepend +* @throws {TypeError} first argument must be an ndarray +* @throws {TypeError} second argument must be a nonnegative integer +* @returns {ndarray} ndarray view +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = prependSingletonDimensions( x, 3 ); +* // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] +*/ +function prependSingletonDimensions( x, n ) { + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isPositiveInteger( n ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); + } + return base( x, n, false ); +} + + +// EXPORTS // + +module.exports = prependSingletonDimensions; diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json new file mode 100644 index 000000000000..5c67eea68acc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/prepend-singleton-dimensions", + "version": "0.0.0", + "description": "Return a read-only view of an input ndarray where a specified number of singleton dimensions are prepended.", + "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", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "prepend", + "add", + "reshape", + "dimensions", + "multidimensional" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js new file mode 100644 index 000000000000..ce324a1bad5c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js @@ -0,0 +1,135 @@ +/** +* @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 isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var array = require( '@stdlib/ndarray/array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var prependSingletonDimensions = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof prependSingletonDimensions, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + prependSingletonDimensions( value, 1 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var values; + var x; + var i; + + x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + + values = [ + '5', + 5.5, + -1, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + prependSingletonDimensions( x, value ); + }; + } +}); + +tape( 'the function prepends singleton dimensions', function test( t ) { + var expected; + var x; + var y; + + x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + y = prependSingletonDimensions( x, 3 ); + + expected = [ 1, 1, 1, 2, 2 ]; + + t.deepEqual( getShape( y ), expected, 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + y = prependSingletonDimensions( x, 2 ); + + expected = [ 1, 1, 2, 2 ]; + + t.deepEqual( getShape( y ), expected, 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + y = prependSingletonDimensions( x, 1 ); + + expected = [ 1, 2, 2 ]; + + t.deepEqual( getShape( y ), expected, 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + t.end(); +}); From 8918dc6c76b66bc0df91394f95c3f12197c02af6 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 1 Jan 2026 14:26:47 +0500 Subject: [PATCH 2/3] fix: lint error --- 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: 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: na - task: lint_license_headers status: passed --- --- .../ndarray/prepend-singleton-dimensions/benchmark/benchmark.js | 2 +- .../ndarray/prepend-singleton-dimensions/examples/index.js | 2 +- .../@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js | 2 +- .../@stdlib/ndarray/prepend-singleton-dimensions/test/test.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js index 599343c2da58..9e79e5b57186 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js index 01e00d5da172..a417f1066385 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js index 9a446fac4594..2e46a26a7e67 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js index ce324a1bad5c..ae1def3d1e42 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. From d871a201459be1fcb41741879d9a1ee03be101dc Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 8 Jan 2026 16:30:10 -0800 Subject: [PATCH 3/3] 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: na - 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 --- --- .../prepend-singleton-dimensions/README.md | 6 +++--- .../benchmark/benchmark.js | 2 +- .../prepend-singleton-dimensions/docs/repl.txt | 4 ++-- .../docs/types/index.d.ts | 6 +++--- .../docs/types/test.ts | 18 +++++++++++++----- .../prepend-singleton-dimensions/lib/index.js | 2 +- .../prepend-singleton-dimensions/lib/main.js | 8 ++++---- .../prepend-singleton-dimensions/package.json | 2 +- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md index 37114c588389..c4957f9858c3 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/README.md @@ -20,7 +20,7 @@ limitations under the License. # prependSingletonDimensions -> Return a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] where a specified number of singleton dimensions are prepended. +> Return a read-only view of an input [ndarray][@stdlib/ndarray/ctor] with a specified number of prepended singleton dimensions. @@ -44,7 +44,7 @@ var prependSingletonDimensions = require( '@stdlib/ndarray/prepend-singleton-dim #### prependSingletonDimensions( x, n ) -Returns a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] where a specified number of singleton dimensions are prepended. +Returns a read-only view of an input [ndarray][@stdlib/ndarray/ctor] with a specified number of prepended singleton dimensions. @@ -62,7 +62,7 @@ var y = prependSingletonDimensions( x, 3 ); The function accepts the following arguments: -- **x**: input [`ndarray`][@stdlib/ndarray/ctor]. +- **x**: input [ndarray][@stdlib/ndarray/ctor]. - **n**: number of singleton dimensions to prepend. diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js index 9e79e5b57186..6caaa01f8f40 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/benchmark/benchmark.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var empty = require( '@stdlib/ndarray/empty' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; -var prependSingletonDimensions = require( './../lib' ); +var prependSingletonDimensions = require( './../lib' ); // eslint-disable-line id-length // MAIN // diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt index 3e3ea818efbd..7c56cf18eae1 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x, n ) - Returns a read-only view of an input ndarray where a specified number of - singleton dimensions are prepended. + Returns a read-only view of an input ndarray with a specified number of + prepended singleton dimensions. Parameters ---------- diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts index 5035b5fc0f55..4743e82b5dd6 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/index.d.ts @@ -20,10 +20,10 @@ /// -import { ndarray } from '@stdlib/types/ndarray'; +import { typedndarray } from '@stdlib/types/ndarray'; /** -* Returns a read-only view of an input ndarray where a specified number of singleton dimensions are prepended. +* Returns a read-only view of an input ndarray with a specified number of prepended singleton dimensions. * * @param x - input array * @param n - number of singleton dimensions to prepend @@ -38,7 +38,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * var y = prependSingletonDimensions( x, 3 ); * // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] */ -declare function prependSingletonDimensions( x: ndarray, n: number ): ndarray; +declare function prependSingletonDimensions = typedndarray>( x: U, n: number ): U; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts index 49f9fdaf45a9..c7558f48b836 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/docs/types/test.ts @@ -16,7 +16,9 @@ * limitations under the License. */ -import array = require( '@stdlib/ndarray/array' ); +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); import prependSingletonDimensions = require( './index' ); @@ -24,9 +26,11 @@ import prependSingletonDimensions = require( './index' ); // The function returns an ndarray... { - const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); - prependSingletonDimensions( x, 3 ); // $ExpectType ndarray + prependSingletonDimensions( x, 3 ); // $ExpectType float64ndarray } // The compiler throws an error if the function is not provided a first argument which is an ndarray... @@ -43,7 +47,9 @@ import prependSingletonDimensions = require( './index' ); // The compiler throws an error if the function is not provided a second argument which is a number... { - const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); prependSingletonDimensions( x, '5' ); // $ExpectError prependSingletonDimensions( x, true ); // $ExpectError @@ -56,7 +62,9 @@ import prependSingletonDimensions = require( './index' ); // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); prependSingletonDimensions(); // $ExpectError prependSingletonDimensions( x ); // $ExpectError diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js index 2e46a26a7e67..700a3118ca3e 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return a read-only view of an input ndarray where a specified number of singleton dimensions are prepended. +* Return a read-only view of an input ndarray with a specified number of prepended singleton dimensions. * * @module @stdlib/ndarray/prepend-singleton-dimensions * diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js index b186407da874..d8c806d08cd5 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var base = require( '@stdlib/ndarray/base/prepend-singleton-dimensions' ); var format = require( '@stdlib/string/format' ); @@ -29,7 +29,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns a read-only view of an input ndarray where a specified number of singleton dimensions are prepended. +* Returns a read-only view of an input ndarray with a specified number of prepended singleton dimensions. * * @param {ndarray} x - input array * @param {NonNegativeInteger} n - number of singleton dimensions to prepend @@ -46,11 +46,11 @@ var format = require( '@stdlib/string/format' ); * var y = prependSingletonDimensions( x, 3 ); * // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] */ -function prependSingletonDimensions( x, n ) { +function prependSingletonDimensions( x, n ) { // eslint-disable-line id-length if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); } - if ( !isPositiveInteger( n ) ) { + if ( !isNonNegativeInteger( n ) ) { throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) ); } return base( x, n, false ); diff --git a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json index 5c67eea68acc..c39bdd739f93 100644 --- a/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json +++ b/lib/node_modules/@stdlib/ndarray/prepend-singleton-dimensions/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/prepend-singleton-dimensions", "version": "0.0.0", - "description": "Return a read-only view of an input ndarray where a specified number of singleton dimensions are prepended.", + "description": "Return a read-only view of an input ndarray with a specified number of prepended singleton dimensions.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors",