From 77e393b178b205bf7e4a1faed6aac1f0c90a36d5 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 27 Sep 2025 00:31:40 +0500 Subject: [PATCH 1/8] feat: add ndarray/shift --- 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/shift/README.md | 190 +++++++ .../ndarray/shift/benchmark/benchmark.js | 190 +++++++ .../@stdlib/ndarray/shift/docs/repl.txt | 38 ++ .../ndarray/shift/docs/types/index.d.ts | 73 +++ .../@stdlib/ndarray/shift/docs/types/test.ts | 90 ++++ .../@stdlib/ndarray/shift/examples/index.js | 39 ++ .../@stdlib/ndarray/shift/lib/index.js | 59 +++ .../@stdlib/ndarray/shift/lib/main.js | 97 ++++ .../@stdlib/ndarray/shift/package.json | 67 +++ .../@stdlib/ndarray/shift/test/test.js | 486 ++++++++++++++++++ 10 files changed, 1329 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/shift/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/shift/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/shift/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/shift/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/shift/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/shift/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/shift/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/shift/README.md b/lib/node_modules/@stdlib/ndarray/shift/README.md new file mode 100644 index 000000000000..615fe4df0a9e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/README.md @@ -0,0 +1,190 @@ + + +# shift + +> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the first element(s) along a specific dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var shift = require( '@stdlib/ndarray/shift' ); +``` + +#### shift( x\[, options] ) + +Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the first element(s) along a specific dimension. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var shape = [ 3, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +var sh = getShape( x ); +// returns [ 3, 2 ] + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = shift( x ); +// returns [ , ] + +arr = ndarray2array( y[ 0 ] ); +// returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +arr = ndarray2array( y[ 1 ] ); +// returns [ [ 1.0, 2.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **options**: function options (_optional_). + +The function supports the following `options`: + +- **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `0`. + +By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along any other input [`ndarray`][@stdlib/ndarray/ctor], provide the `dim` option. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var shape = [ 3, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +var sh = getShape( x ); +// returns [ 3, 2 ] + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var opts = { + 'dim': 1 +}; + +var y = shift( x, opts ); +// returns [ , ] + +arr = ndarray2array( y[ 0 ] ); +// returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] + +arr = ndarray2array( y[ 1 ] ); +// returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var shift = require( '@stdlib/ndarray/shift' ); + +// Create a linear ndarray buffer: +var buf = zeroTo( 27 ); + +// Create an ndarray which is a stack of three 3x3 matrices: +var x = array( buf, { + 'shape': [ 3, 3, 3 ] +}); + +// Perform the operation: +var y = shift( x ); +// returns [ , ] + +console.log( ndarray2array( y[ 0 ] ) ); +console.log( ndarray2array( y[ 1 ] ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/shift/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/shift/benchmark/benchmark.js new file mode 100644 index 000000000000..4d0f3ec6214a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/benchmark/benchmark.js @@ -0,0 +1,190 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var shift = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::1d', 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 = shift( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::2d', 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 = shift( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::3d', 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 = shift( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::4d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 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 = shift( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::5d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 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 = shift( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt new file mode 100644 index 000000000000..6eb5df3d4735 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}( x[, options] ) + Returns an array containing a read-only truncated view of an input ndarray + and a read-only view of the first element(s) along a specific dimension. + + Parameters + ---------- + x: ndarray + Input array. + + options: object (optional) + Options. + + options.dim: integer (optional) + Dimension along which to perform the operation. If provided an integer + less than zero, the dimension index is resolved relative to the last + dimension, with the last dimension corresponding to the value `-1`. + Default `0`. + + Returns + ------- + out: Array + An array containing a read-only truncated view of an input ndarray and a + read-only view of the first element(s) along a specific dimension. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + + > var y = {{alias}}( x ) + [ , ] + > {{alias:@stdlib/ndarray/to-array}}( y[0] ) + [ [ 3, 4 ] ] + > {{alias:@stdlib/ndarray/to-array}}( y[1] ) + [ [ 1, 2 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts new file mode 100644 index 000000000000..0a5dbfcba410 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts @@ -0,0 +1,73 @@ +/* +* @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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Dimension along which to perform the operation (Default: 0). + */ + dim?: number; +} + +/** +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension. +* +* @param x - input array +* @param options - function options +* @param options.dim - dimension along which to perform the operation +* @returns a list of ndarrays +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = shift( x ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* arr = ndarray2array( y[ 1 ] ); +* // returns [ [ 1.0, 2.0 ] ] +*/ +declare function shift( x: T, options?: Options ): [ T, T ]; + + +// EXPORTS // + +export = shift; diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts new file mode 100644 index 000000000000..8a6e2067f86f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts @@ -0,0 +1,90 @@ +/* +* @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 empty = require( '@stdlib/ndarray/base/empty' ); +import shift = require( './index' ); + + +// TESTS // + +// The function returns an array of ndarrays... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + shift( empty( 'float64', sh, order ) ); // $ExpectType [float64ndarray, float64ndarray] + shift( empty( 'complex64', sh, order ) ); // $ExpectType [complex64ndarray, complex64ndarray] + shift( empty( 'uint8', sh, order ) ); // $ExpectType [uint8ndarray, uint8ndarray] + + shift( empty( 'float64', sh, order ), {} ); // $ExpectType [float64ndarray, float64ndarray] + shift( empty( 'complex64', sh, order ), {} ); // $ExpectType [complex64ndarray, complex64ndarray] + shift( empty( 'uint8', sh, order ), {} ); // $ExpectType [uint8ndarray, uint8ndarray] +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + shift( '10' ); // $ExpectError + shift( 10 ); // $ExpectError + shift( false ); // $ExpectError + shift( true ); // $ExpectError + shift( null ); // $ExpectError + shift( [] ); // $ExpectError + shift( {} ); // $ExpectError + shift( ( x: number ): number => x ); // $ExpectError + + shift( '10', {} ); // $ExpectError + shift( 10, {} ); // $ExpectError + shift( false, {} ); // $ExpectError + shift( true, {} ); // $ExpectError + shift( null, {} ); // $ExpectError + shift( [], {} ); // $ExpectError + shift( {}, {} ); // $ExpectError + shift( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + shift( x, '5' ); // $ExpectError + shift( x, false ); // $ExpectError + shift( x, true ); // $ExpectError + shift( x, null ); // $ExpectError + shift( x, [ '5' ] ); // $ExpectError + shift( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument with invalid `dim` option... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + shift( x, { 'dim': '5' } ); // $ExpectError + shift( x, { 'dim': false } ); // $ExpectError + shift( x, { 'dim': true } ); // $ExpectError + shift( x, { 'dim': null } ); // $ExpectError + shift( x, { 'dim': [ '5' ] } ); // $ExpectError + shift( x, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + shift(); + shift( x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/shift/examples/index.js b/lib/node_modules/@stdlib/ndarray/shift/examples/index.js new file mode 100644 index 000000000000..edb845470873 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var shift = require( './../lib' ); + +// Create a linear ndarray buffer: +var buf = zeroTo( 27 ); + +// Create an ndarray: +var x = array( buf, { + 'shape': [ 3, 3, 3 ] +}); +console.log( ndarray2array( x ) ); + +// Perform the operation: +var y = shift( x ); + +console.log( ndarray2array( y[ 0 ] ) ); +console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/index.js b/lib/node_modules/@stdlib/ndarray/shift/lib/index.js new file mode 100644 index 000000000000..0327049760e1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension. +* +* @module @stdlib/ndarray/shift +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var shift = require( '@stdlib/ndarray/shift' ); +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = shift( x ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* arr = ndarray2array( y[ 1 ] ); +* // returns [ [ 1.0, 2.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js new file mode 100644 index 000000000000..c6acaf608c87 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js @@ -0,0 +1,97 @@ +/** +* @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 isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var base = require( '@stdlib/ndarray/base/shift' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension. +* +* @param {ndarray} x - input array +* @param {Object} [options] - function options +* @param {integer} [options.dim=0] - dimension along which to perform the operation +* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {TypeError} options argument must be an object +* * @throws {TypeError} must provide valid options +* @throws {RangeError} dimension index exceeds the number of dimensions +* @returns {Array} a list of ndarrays +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = shift( x ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* arr = ndarray2array( y[ 1 ] ); +* // returns [ [ 1.0, 2.0 ] ] +*/ +function shift( x ) { + var options; + var opts; + + opts = { + 'dim': 0 + }; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( arguments.length > 1 ) { + options = arguments[ 1 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'dim' ) ) { + if ( !isInteger( options.dim ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + } + opts.dim = options.dim; + } + } + return base( x, opts.dim, false ); +} + + +// EXPORTS // + +module.exports = shift; diff --git a/lib/node_modules/@stdlib/ndarray/shift/package.json b/lib/node_modules/@stdlib/ndarray/shift/package.json new file mode 100644 index 000000000000..f9c24f69f06c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ndarray/shift", + "version": "0.0.0", + "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension.", + "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", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "slice", + "shift", + "view", + "remove", + "truncate" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/shift/test/test.js b/lib/node_modules/@stdlib/ndarray/shift/test/test.js new file mode 100644 index 000000000000..dc4f3cacc9d7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/shift/test/test.js @@ -0,0 +1,486 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var shift = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof shift, '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, + NaN, + 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() { + shift( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray(options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + 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() { + shift( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + 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() { + shift( zeros( [ 2, 2 ] ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument with an invalid `dim` option', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + NaN, + 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() { + opts = { + 'dim': value + }; + shift( zeros( [ 2, 2 ] ), opts ); + }; + } +}); + +tape( 'the function throws an error if the dimension index exceeds the number of dimensions', function test( t ) { + var values; + var opts; + var i; + + values = [ + zeros( [ 1 ] ), + zeros( [ 1, 1 ] ), + zeros( [ 1, 1, 1 ] ), + zeros( [ 1, 1, 1, 1 ] ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ], 10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); + t.throws( badValue( values[ i ], -10 ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); + } + t.end(); + + function badValue( x, dim ) { + return function badValue() { + opts = { + 'dim': dim + }; + shift( x, opts ); + }; + } +}); + +tape( 'the function returns an array containing ndarrays (ndims=1)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 6 ]; + st = [ 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = shift( x ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 1, 2, 3, 4, 5 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ 0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=1, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 6 ]; + st = [ 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 0 + }; + + actual = shift( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 1, 2, 3, 4, 5 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ 0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=2)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 4 ]; + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = shift( x ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 4 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=2, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 4 ]; + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 1 + }; + + actual = shift( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 1, 2, 3 ], [ 5, 6, 7 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 0 ], [ 4 ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=3)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 2, 2 ]; + st = [ 4, 2, 1 ]; + o = 0; + ord = 'row-major'; + + /* + * [ + * [ + * [ 0, 1 ], + * [ 2, 3 ] + * ], + * [ + * [ 4, 5 ], + * [ 6, 7 ] + * ] + *]; + */ + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = shift( x ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=3, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 2, 2 ]; + st = [ 4, 2, 1 ]; + o = 0; + ord = 'row-major'; + + /* + * [ + * [ + * [ 0, 1 ], + * [ 2, 3 ] + * ], + * [ + * [ 4, 5 ], + * [ 6, 7 ] + * ] + *]; + */ + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 1 + }; + + actual = shift( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 1, 2 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 1, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 2, 3 ] ], [ [ 6, 7 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0, 1 ] ], [ [ 4, 5 ] ] ], 'returns expected value' ); + + opts = { + 'dim': 2 + }; + actual = shift( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 2, 1 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 2, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 1 ], [ 3 ] ], [ [ 5 ], [ 7 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0 ], [ 2 ] ], [ [ 4 ], [ 6 ] ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns empty views if provided an empty array (ndims=2)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + sh = [ 2, 0 ]; + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = shift( x ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns empty views if provided an empty array (ndims=2, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + sh = [ 2, 0 ]; + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 1 + }; + + actual = shift( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 0 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + + t.end(); +}); From 7827c74a93d6bb9a8f56c68160ad63eb841835bd Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:20:47 +0500 Subject: [PATCH 2/8] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/shift/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/README.md b/lib/node_modules/@stdlib/ndarray/shift/README.md index 615fe4df0a9e..7e5021155a45 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/README.md +++ b/lib/node_modules/@stdlib/ndarray/shift/README.md @@ -82,7 +82,7 @@ The function supports the following `options`: - **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `0`. -By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along any other input [`ndarray`][@stdlib/ndarray/ctor], provide the `dim` option. +By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a desired dimension, provide the `dim` option. ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); From f3dccc9e4822ae702defebaf5e018e5e547c89ad Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:22:13 +0500 Subject: [PATCH 3/8] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/shift/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js index c6acaf608c87..54bd5eb03ea3 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js @@ -39,7 +39,6 @@ var format = require( '@stdlib/string/format' ); * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {TypeError} options argument must be an object * * @throws {TypeError} must provide valid options -* @throws {RangeError} dimension index exceeds the number of dimensions * @returns {Array} a list of ndarrays * * @example From e652244063b5e831e66b8ee3caf9d69b8fc6e435 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 29 Sep 2025 15:15:51 +0500 Subject: [PATCH 4/8] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/shift/README.md | 51 ++++++---------- .../@stdlib/ndarray/shift/docs/repl.txt | 4 +- .../ndarray/shift/docs/types/index.d.ts | 2 +- .../@stdlib/ndarray/shift/examples/index.js | 9 +-- .../@stdlib/ndarray/shift/lib/index.js | 2 +- .../@stdlib/ndarray/shift/lib/main.js | 7 ++- .../@stdlib/ndarray/shift/package.json | 2 +- .../@stdlib/ndarray/shift/test/test.js | 61 ++++++++++++++++++- 8 files changed, 87 insertions(+), 51 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/README.md b/lib/node_modules/@stdlib/ndarray/shift/README.md index 7e5021155a45..8ba600bd5f3a 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/README.md +++ b/lib/node_modules/@stdlib/ndarray/shift/README.md @@ -20,7 +20,7 @@ limitations under the License. # shift -> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the first element(s) along a specific dimension. +> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the first element(s) along a specified dimension. @@ -42,24 +42,17 @@ var shift = require( '@stdlib/ndarray/shift' ); #### shift( x\[, options] ) -Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the first element(s) along a specific dimension. +Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the first element(s) along a specified dimension. ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); -var getShape = require( '@stdlib/ndarray/shape' ); +var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -var shape = [ 3, 2 ]; -var strides = [ 2, 1 ]; -var offset = 0; - -var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], { + 'shape': [ 3, 2 ] +}); // returns -var sh = getShape( x ); -// returns [ 3, 2 ] - var arr = ndarray2array( x ); // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] @@ -82,24 +75,17 @@ The function supports the following `options`: - **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `0`. -By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a desired dimension, provide the `dim` option. +By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a specific dimension, provide the `dim` option. ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); -var getShape = require( '@stdlib/ndarray/shape' ); +var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -var shape = [ 3, 2 ]; -var strides = [ 2, 1 ]; -var offset = 0; - -var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], { + 'shape': [ 3, 2 ] +}); // returns -var sh = getShape( x ); -// returns [ 3, 2 ] - var arr = ndarray2array( x ); // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] @@ -140,20 +126,17 @@ arr = ndarray2array( y[ 1 ] ); ```javascript var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var zeroTo = require( '@stdlib/array/base/zero-to' ); -var shift = require( '@stdlib/ndarray/shift' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pop = require( '@stdlib/ndarray/pop' ); -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray which is a stack of three 3x3 matrices: -var x = array( buf, { +// Create an ndarray: +var x = array( zeroTo( 27 ), { 'shape': [ 3, 3, 3 ] }); +console.log( ndarray2array( x ) ); -// Perform the operation: +// Remove the first stack from a stack of matrices: var y = shift( x ); -// returns [ , ] console.log( ndarray2array( y[ 0 ] ) ); console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt index 6eb5df3d4735..6ea538ebfb94 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x[, options] ) Returns an array containing a read-only truncated view of an input ndarray - and a read-only view of the first element(s) along a specific dimension. + and a read-only view of the first element(s) along a specified dimension. Parameters ---------- @@ -21,7 +21,7 @@ ------- out: Array An array containing a read-only truncated view of an input ndarray and a - read-only view of the first element(s) along a specific dimension. + read-only view of the first element(s) along a specified dimension. Examples -------- diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts index 0a5dbfcba410..0740d7564049 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts @@ -33,7 +33,7 @@ interface Options { } /** -* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension. +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension. * * @param x - input array * @param options - function options diff --git a/lib/node_modules/@stdlib/ndarray/shift/examples/index.js b/lib/node_modules/@stdlib/ndarray/shift/examples/index.js index edb845470873..ec858af5fb3c 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/shift/examples/index.js @@ -20,19 +20,16 @@ var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeroTo = require( '@stdlib/array/zero-to' ); var shift = require( './../lib' ); -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - // Create an ndarray: -var x = array( buf, { +var x = array( zeroTo( 27 ), { 'shape': [ 3, 3, 3 ] }); console.log( ndarray2array( x ) ); -// Perform the operation: +// Remove the first stack from a stack of matrices: var y = shift( x ); console.log( ndarray2array( y[ 0 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/index.js b/lib/node_modules/@stdlib/ndarray/shift/lib/index.js index 0327049760e1..517b8cc63943 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension. +* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension. * * @module @stdlib/ndarray/shift * diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js index 54bd5eb03ea3..99c4c1e226af 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js @@ -31,15 +31,16 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension. +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension. * * @param {ndarray} x - input array * @param {Object} [options] - function options * @param {integer} [options.dim=0] - dimension along which to perform the operation * @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {RangeError} dimension index exceeds the number of dimensions * @throws {TypeError} options argument must be an object * * @throws {TypeError} must provide valid options -* @returns {Array} a list of ndarrays +* @returns {Array} a list of ndarray views * * @example * var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -82,7 +83,7 @@ function shift( x ) { } if ( hasOwnProp( options, 'dim' ) ) { if ( !isInteger( options.dim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'strict', options.strict ) ); } opts.dim = options.dim; } diff --git a/lib/node_modules/@stdlib/ndarray/shift/package.json b/lib/node_modules/@stdlib/ndarray/shift/package.json index f9c24f69f06c..3c9002d93fb4 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/package.json +++ b/lib/node_modules/@stdlib/ndarray/shift/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/shift", "version": "0.0.0", - "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension.", + "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/shift/test/test.js b/lib/node_modules/@stdlib/ndarray/shift/test/test.js index dc4f3cacc9d7..49d70c006847 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/shift/test/test.js @@ -246,6 +246,20 @@ tape( 'the function returns an array containing ndarrays (ndims=1, options)', fu t.deepEqual( ndarray2array( actual[0] ), [ 1, 2, 3, 4, 5 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ 0 ], 'returns expected value' ); + opts = { + 'dim': -1 + }; + actual = shift( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 1, 2, 3, 4, 5 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ 0 ], 'returns expected value' ); + t.end(); }); @@ -298,11 +312,25 @@ tape( 'the function returns an array containing ndarrays (ndims=2, options)', fu x = new ndarray( 'float64', buf, sh, st, o, ord ); opts = { - 'dim': 1 + 'dim': 0 }; actual = shift( x, opts ); + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 4 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 4, 5, 6, 7] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); + + opts = { + 'dim': -1 + }; + actual = shift( x, opts ); + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); @@ -387,10 +415,24 @@ tape( 'the function returns an array containing ndarrays (ndims=3, options)', fu *]; */ x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { - 'dim': 1 + 'dim': 0 }; + actual = shift( x, opts ); + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); + + opts = { + 'dim': -2 + }; actual = shift( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); @@ -468,9 +510,22 @@ tape( 'the function returns empty views if provided an empty array (ndims=2, opt sh = [ 2, 0 ]; x = new ndarray( 'float64', buf, sh, st, o, ord ); opts = { - 'dim': 1 + 'dim': 0 }; + actual = shift( x, opts ); + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + + opts = { + 'dim': -1 + }; actual = shift( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); From 07f68f024df3233d77c700a9cd3bf96508124b66 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:24:02 +0500 Subject: [PATCH 5/8] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/shift/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/README.md b/lib/node_modules/@stdlib/ndarray/shift/README.md index 8ba600bd5f3a..de5d8ca9a279 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/README.md +++ b/lib/node_modules/@stdlib/ndarray/shift/README.md @@ -127,7 +127,7 @@ arr = ndarray2array( y[ 1 ] ); var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var zeroTo = require( '@stdlib/array/zero-to' ); -var pop = require( '@stdlib/ndarray/pop' ); +var shift = require( '@stdlib/ndarray/shift' ); // Create an ndarray: var x = array( zeroTo( 27 ), { From ce2121590d23de0e76c6e38fea121bc4fcac7c0e Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 29 Sep 2025 12:01:14 +0100 Subject: [PATCH 6/8] docs: update description --- 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: na - 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/shift/docs/types/index.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts index 0740d7564049..8d6e4da4a0b6 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts @@ -27,7 +27,11 @@ import { ndarray } from '@stdlib/types/ndarray'; */ interface Options { /** - * Dimension along which to perform the operation (Default: 0). + * Dimension along which to perform the operation. Default: `-1`. + * + * ## Notes + * + * - If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. */ dim?: number; } From 4ae4fb4939d194f67cded8d626e3ca9cf46630dc Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 29 Sep 2025 19:58:44 +0500 Subject: [PATCH 7/8] refactor: apply suggestions form code review --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/shift/README.md | 14 ++++++------- .../@stdlib/ndarray/shift/docs/repl.txt | 6 +++--- .../ndarray/shift/docs/types/index.d.ts | 6 +++--- .../@stdlib/ndarray/shift/examples/index.js | 2 +- .../@stdlib/ndarray/shift/lib/index.js | 4 ++-- .../@stdlib/ndarray/shift/lib/main.js | 6 +++--- .../@stdlib/ndarray/shift/test/test.js | 20 +++++++++---------- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/README.md b/lib/node_modules/@stdlib/ndarray/shift/README.md index de5d8ca9a279..46b2a147dc5f 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/README.md +++ b/lib/node_modules/@stdlib/ndarray/shift/README.md @@ -60,10 +60,10 @@ var y = shift( x ); // returns [ , ] arr = ndarray2array( y[ 0 ] ); -// returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +// returns [ [ 2.0], [ 4.0 ], [ 6.0 ] ] arr = ndarray2array( y[ 1 ] ); -// returns [ [ 1.0, 2.0 ] ] +// returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] ``` The function accepts the following arguments: @@ -73,7 +73,7 @@ The function accepts the following arguments: The function supports the following `options`: -- **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `0`. +- **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a specific dimension, provide the `dim` option. @@ -90,17 +90,17 @@ var arr = ndarray2array( x ); // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] var opts = { - 'dim': 1 + 'dim': 0 }; var y = shift( x, opts ); // returns [ , ] arr = ndarray2array( y[ 0 ] ); -// returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] +// returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] arr = ndarray2array( y[ 1 ] ); -// returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] +// returns [ [ 1.0, 2.0 ] ] ``` @@ -135,7 +135,7 @@ var x = array( zeroTo( 27 ), { }); console.log( ndarray2array( x ) ); -// Remove the first stack from a stack of matrices: +// Remove the first column from each matrix: var y = shift( x ); console.log( ndarray2array( y[ 0 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt index 6ea538ebfb94..b4f3570f69fb 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt @@ -15,7 +15,7 @@ Dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. - Default `0`. + Default `-1`. Returns ------- @@ -30,9 +30,9 @@ > var y = {{alias}}( x ) [ , ] > {{alias:@stdlib/ndarray/to-array}}( y[0] ) - [ [ 3, 4 ] ] + [ [ 2 ], [ 4 ] ] > {{alias:@stdlib/ndarray/to-array}}( y[1] ) - [ [ 1, 2 ] ] + [ [ 1 ], [ 3 ] ] See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts index 8d6e4da4a0b6..80c17a34efcb 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts @@ -27,7 +27,7 @@ import { ndarray } from '@stdlib/types/ndarray'; */ interface Options { /** - * Dimension along which to perform the operation. Default: `-1`. + * Dimension along which to perform the operation (Default: -1). * * ## Notes * @@ -64,10 +64,10 @@ interface Options { * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* // returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] * * arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 1.0, 2.0 ] ] +* // returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] */ declare function shift( x: T, options?: Options ): [ T, T ]; diff --git a/lib/node_modules/@stdlib/ndarray/shift/examples/index.js b/lib/node_modules/@stdlib/ndarray/shift/examples/index.js index ec858af5fb3c..e5537c42d507 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/shift/examples/index.js @@ -29,7 +29,7 @@ var x = array( zeroTo( 27 ), { }); console.log( ndarray2array( x ) ); -// Remove the first stack from a stack of matrices: +// Remove the first column from each matrix: var y = shift( x ); console.log( ndarray2array( y[ 0 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/index.js b/lib/node_modules/@stdlib/ndarray/shift/lib/index.js index 517b8cc63943..5985725cdbee 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/index.js @@ -43,10 +43,10 @@ * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* // returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] * * arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 1.0, 2.0 ] ] +* // returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js index 99c4c1e226af..29c1b6942ac0 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js @@ -61,17 +61,17 @@ var format = require( '@stdlib/string/format' ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* // returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] * * arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 1.0, 2.0 ] ] +* // returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] */ function shift( x ) { var options; var opts; opts = { - 'dim': 0 + 'dim': -1 }; if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/test/test.js b/lib/node_modules/@stdlib/ndarray/shift/test/test.js index 49d70c006847..93e90f15ccd8 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/shift/test/test.js @@ -286,10 +286,10 @@ tape( 'the function returns an array containing ndarrays (ndims=2)', function te t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); - t.deepEqual( getShape( actual[0] ), [ 1, 4 ], 'returns expected value' ); - t.deepEqual( getShape( actual[1] ), [ 1, 4 ], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[0] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[1] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 1, 2, 3 ], [ 5, 6, 7 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 0 ], [ 4 ] ], 'returns expected value' ); t.end(); }); @@ -378,10 +378,10 @@ tape( 'the function returns an array containing ndarrays (ndims=3)', function te t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); - t.deepEqual( getShape( actual[0] ), [ 1, 2, 2 ], 'returns expected value' ); - t.deepEqual( getShape( actual[1] ), [ 1, 2, 2 ], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[0] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 2, 1 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 2, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 1 ], [ 3 ] ], [ [ 5 ], [ 7 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0 ], [ 2 ] ], [ [ 4 ], [ 6 ] ] ], 'returns expected value' ); t.end(); }); @@ -484,8 +484,8 @@ tape( 'the function returns empty views if provided an empty array (ndims=2)', f t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); - t.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' ); - t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 0 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); From 4dd6a4e8cfaa4111c119923af9d07c185da29615 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 30 Sep 2025 00:35:30 +0100 Subject: [PATCH 8/8] 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: na - 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 --- --- lib/node_modules/@stdlib/ndarray/shift/README.md | 4 ++-- lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt | 4 ++-- .../@stdlib/ndarray/shift/docs/types/index.d.ts | 6 +++++- .../@stdlib/ndarray/shift/docs/types/test.ts | 3 ++- lib/node_modules/@stdlib/ndarray/shift/lib/main.js | 10 +++++----- lib/node_modules/@stdlib/ndarray/shift/test/test.js | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/shift/README.md b/lib/node_modules/@stdlib/ndarray/shift/README.md index 46b2a147dc5f..c341f229e3fc 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/README.md +++ b/lib/node_modules/@stdlib/ndarray/shift/README.md @@ -68,14 +68,14 @@ arr = ndarray2array( y[ 1 ] ); The function accepts the following arguments: -- **x**: input ndarray. +- **x**: input ndarray. Must have one or more dimensions. - **options**: function options (_optional_). The function supports the following `options`: - **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. -By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a specific dimension, provide the `dim` option. +By default, the function performs operation along the last dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a specific dimension, provide the `dim` option. ```javascript var array = require( '@stdlib/ndarray/array' ); diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt index b4f3570f69fb..0632b4824050 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/repl.txt @@ -6,7 +6,7 @@ Parameters ---------- x: ndarray - Input array. + Input array. Must have one or more dimensions. options: object (optional) Options. @@ -15,7 +15,7 @@ Dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. - Default `-1`. + Default: -1. Returns ------- diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts index 80c17a34efcb..223ac3dee4bf 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/index.d.ts @@ -27,7 +27,7 @@ import { ndarray } from '@stdlib/types/ndarray'; */ interface Options { /** - * Dimension along which to perform the operation (Default: -1). + * Dimension along which to perform the operation. Default: `-1`. * * ## Notes * @@ -39,6 +39,10 @@ interface Options { /** * Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension. * +* ## Notes +* +* - The input array must have one or more dimensions. +* * @param x - input array * @param options - function options * @param options.dim - dimension along which to perform the operation diff --git a/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts index 8a6e2067f86f..d6bab2682ec7 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/shift/docs/types/test.ts @@ -69,7 +69,7 @@ import shift = require( './index' ); shift( x, ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided an options argument with invalid `dim` option... +// The compiler throws an error if the function is provided an options argument with an invalid `dim` option... { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); @@ -78,6 +78,7 @@ import shift = require( './index' ); shift( x, { 'dim': true } ); // $ExpectError shift( x, { 'dim': null } ); // $ExpectError shift( x, { 'dim': [ '5' ] } ); // $ExpectError + shift( x, { 'dim': {} } ); // $ExpectError shift( x, { 'dim': ( x: number ): number => x } ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js index 29c1b6942ac0..916291112553 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/shift/lib/main.js @@ -35,7 +35,7 @@ var format = require( '@stdlib/string/format' ); * * @param {ndarray} x - input array * @param {Object} [options] - function options -* @param {integer} [options.dim=0] - dimension along which to perform the operation +* @param {integer} [options.dim=-1] - dimension along which to perform the operation * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {RangeError} dimension index exceeds the number of dimensions * @throws {TypeError} options argument must be an object @@ -70,12 +70,12 @@ function shift( x ) { var options; var opts; - opts = { - 'dim': -1 - }; if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); } + opts = { + 'dim': -1 + }; if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { @@ -83,7 +83,7 @@ function shift( x ) { } if ( hasOwnProp( options, 'dim' ) ) { if ( !isInteger( options.dim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'strict', options.dim ) ); } opts.dim = options.dim; } diff --git a/lib/node_modules/@stdlib/ndarray/shift/test/test.js b/lib/node_modules/@stdlib/ndarray/shift/test/test.js index 93e90f15ccd8..7fdfd4442968 100644 --- a/lib/node_modules/@stdlib/ndarray/shift/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/shift/test/test.js @@ -68,7 +68,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a first argument which is not an ndarray(options)', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { var values; var i;