From 5cecf5c17ddd45434f16c92be6f4366eb2900218 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 12:47:35 +0500 Subject: [PATCH 01/20] feat: add ndarray/base/pop --- .../@stdlib/ndarray/base/pop/README.md | 155 +++++++++++ .../ndarray/base/pop/benchmark/benchmark.js | 190 +++++++++++++ .../@stdlib/ndarray/base/pop/docs/repl.txt | 37 +++ .../ndarray/base/pop/docs/types/index.d.ts | 174 ++++++++++++ .../ndarray/base/pop/docs/types/test.ts | 95 +++++++ .../ndarray/base/pop/examples/index.js | 41 +++ .../@stdlib/ndarray/base/pop/lib/index.js | 62 +++++ .../@stdlib/ndarray/base/pop/lib/main.js | 87 ++++++ .../@stdlib/ndarray/base/pop/package.json | 67 +++++ .../@stdlib/ndarray/base/pop/test/test.js | 263 ++++++++++++++++++ 10 files changed, 1171 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/pop/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/README.md b/lib/node_modules/@stdlib/ndarray/base/pop/README.md new file mode 100644 index 000000000000..ecb163c3f5fe --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/README.md @@ -0,0 +1,155 @@ + + +# pop + +> Return an array containing a truncated view of an input ndarray and the last element along a specified dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var pop = require( '@stdlib/ndarray/base/pop' ); +``` + +#### pop( x, dim, strict, writable ) + +Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. + +```javascript +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 sh = x.shape; +// returns [ 3, 2 ] + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = pop( x, 0, false, false ); +// returns [ , ] + +arr = ndarray2array( y[ 0 ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +arr = ndarray2array( y[ 1 ] ); +// returns [ [ 5.0, 6.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **dim**: dimension along which to perform the operation. +- **strict**: boolean indicating whether to enforce strict bounds checking. +- **writable**: boolean indicating whether a returned ndarray should be writable. + +
+ + + + + +
+ +## Notes + +- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. + +
+ + + + + +
+ +## Examples + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var pop = require( '@stdlib/ndarray/base/pop' ); + +// Create a linear ndarray buffer: +var buf = zeroTo( 27 ); + +// Create an ndarray: +var x = array( buf, { + 'shape': [ 3, 3, 3 ] +}); + +// Get the first two rows of each matrix: +var y = pop( x, 1, false, false ); +// returns [ , ] + +console.log( ndarray2array( y[ 0 ] ) ); + +console.log( ndarray2array( y[ 1 ] ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js new file mode 100644 index 000000000000..eb58158f829d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js @@ -0,0 +1,190 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 pop = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::1d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0, false, false ); + 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 */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0, false, false ); + 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 */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0, false, false ); + 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 */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0, false, false ); + 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 */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0, false, false ); + 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/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt new file mode 100644 index 000000000000..8b7275ea40f7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -0,0 +1,37 @@ + +{{alias}}( x, dim, strict, writable ) + Returns an array containing a truncated view of an input ndarray and the + last element along a specified dimension. + + Parameters + ---------- + x: ndarray + Input array. + + dim: integer + Dimension along which to perform the operation. + + strict: boolean + Boolean indicating whether to enforce strict bounds checking. + + writable: boolean + Boolean indicating whether a returned ndarray should be writable. This + parameter only applies to ndarray constructors which support read-only + instances. + + Returns + ------- + out: array + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + + > var y = {{alias}}( x, 1, false, false ) + + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ [ 2 ], [ 4 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts new file mode 100644 index 000000000000..892e8cb3d608 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts @@ -0,0 +1,174 @@ +/* +* @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 { typedndarray, genericndarray } from '@stdlib/types/ndarray'; +import { ComplexLike } from '@stdlib/types/complex'; +import { ArrayLike } from '@stdlib/types/array'; + + +/** +* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* +* @param x - input array +* @param dim - dimension along which to perform the operation +* @param strict - boolean indicating whether to enforce strict bounds checking +* @param writable - boolean indicating whether a returned array should be writable +* @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 = pop( x, 0, false, false ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 5.0, 6.0 ] ] +*/ +declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; + +/** +* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* +* @param x - input array +* @param dim - dimension along which to perform the operation +* @param strict - boolean indicating whether to enforce strict bounds checking +* @param writable - boolean indicating whether a returned array should be writable +* @returns a list of ndarrays +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var shape = [ 2, 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, 7.0, 8.0 ] ] +* +* var y = pop( x, 0, false, false ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 2.0, 3.0 ], [ 7.0, 8.0 ] ] +*/ +declare function pop = typedndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; + +/** +* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* +* @param x - input array +* @param dim - dimension along which to perform the operation +* @param strict - boolean indicating whether to enforce strict bounds checking +* @param writable - boolean indicating whether a returned array should be writable +* @returns a list of ndarrays +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new BooleanArray( [ true, false, true, false, true, false ] ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ [ true, false ], [ true, false ], [ true, false ] ] +* +* var y = pop( x, 0, false, false ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ true, false ], [ true, false ] ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ true, false ] ] +*/ +declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; + +/** +* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* +* @param x - input array +* @param dim - dimension along which to perform the operation +* @param strict - boolean indicating whether to enforce strict bounds checking +* @param writable - boolean indicating whether a returned array should be writable +* @returns 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 = pop( x, 0, false, false ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 5.0, 6.0 ] ] +*/ +declare function pop = genericndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; + + +// EXPORTS // + +export = pop; diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts new file mode 100644 index 000000000000..48154fd235a3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts @@ -0,0 +1,95 @@ +/* +* @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 pop = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + pop( empty( 'float64', sh, order ), 1, false, false ); // $ExpectType Array + pop( empty( 'complex64', sh, order ), 1, false, false ); // $ExpectType Array + pop( empty( 'uint8c', sh, order ), 1, false, false ); // $ExpectType Array +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + pop( '10', 1, false, false ); // $ExpectError + pop( 10, 1, false, false ); // $ExpectError + pop( false, 1, false, false ); // $ExpectError + pop( true, 1, false, false ); // $ExpectError + pop( null, 1, false, false ); // $ExpectError + pop( [], 1, false, false ); // $ExpectError + pop( {}, 1, false, false ); // $ExpectError + pop( ( x: number ): number => x, 1, false, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an integer... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + pop( x, '5', false, false ); // $ExpectError + pop( x, false, false, false ); // $ExpectError + pop( x, true, false, false ); // $ExpectError + pop( x, null, false, false ); // $ExpectError + pop( x, undefined, false, false ); // $ExpectError + pop( x, [ '5' ], false, false ); // $ExpectError + pop( x, {}, false, false ); // $ExpectError + pop( x, ( x: number ): number => x, false, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a boolean... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + pop( x, 1, '5', false ); // $ExpectError + pop( x, 1, 5, false ); // $ExpectError + pop( x, 1, null, false ); // $ExpectError + pop( x, 1, undefined, false ); // $ExpectError + pop( x, 1, [ '5' ], false ); // $ExpectError + pop( x, 1, {}, false ); // $ExpectError + pop( x, 1, ( x: number ): number => x, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a boolean... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + pop( x, 1, false, '5' ); // $ExpectError + pop( x, 1, false, 5 ); // $ExpectError + pop( x, 1, false, null ); // $ExpectError + pop( x, 1, false, undefined ); // $ExpectError + pop( x, 1, false, [ '5' ] ); // $ExpectError + pop( x, 1, false, {} ); // $ExpectError + pop( x, 1, false, ( 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' ); + + pop( x ); // $ExpectError + pop( x, 1 ); // $ExpectError + pop( x, 1, false ); // $ExpectError + pop( x, 1, false, false, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js new file mode 100644 index 000000000000..f32b59df739b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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 pop = 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 ) ); + +// Get the first two rows of each matrix: +var y = pop( x, 1, false, false ); + +console.log( ndarray2array( y[ 0 ] ) ); + +console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js new file mode 100644 index 000000000000..f0db1dda76df --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js @@ -0,0 +1,62 @@ +/** +* @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 truncated view of an input ndarray and the last element along a specified dimension. +* +* @module @stdlib/ndarray/base/pop +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var pop = require( '@stdlib/ndarray/base/pop' ); +* +* 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 = x.shape; +* // returns [ 3, 2 ] +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = pop( x, 0, false, false ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 5.0, 6.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js new file mode 100644 index 000000000000..f4d228331376 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js @@ -0,0 +1,87 @@ +/** +* @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 getShape = require( '@stdlib/ndarray/base/shape' ); +var sliceFrom = require( '@stdlib/ndarray/base/slice-from' ); +var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); + + +// MAIN // + +/** +* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* +* @param {ndarray} x - input array +* @param {integer} dim - dimension along which to perform the operation +* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking +* @param {boolean} writable - boolean indicating whether a returned array should be writable +* @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 sh = x.shape; +* // returns [ 3, 2 ] +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = pop( x, 0, false, false ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 5.0, 6.0 ] ] +*/ +function pop( x, dim, strict, writable ) { + var v0; + var v1; + var sh; + var s; + var i; + + sh = getShape( x ); + s = []; + for ( i = 0; i < sh.length; i++ ) { + s[ i ] = null; + } + s[ dim ] = sh[ dim ] - 1; + v1 = sliceFrom( x, s, strict, writable ); + v0 = sliceTo( x, s, strict, writable ); + return [ v0, v1 ]; +} + + +// EXPORTS // + +module.exports = pop; diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/package.json b/lib/node_modules/@stdlib/ndarray/base/pop/package.json new file mode 100644 index 000000000000..5f66580196d3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ndarray/base/pop", + "version": "0.0.0", + "description": "Return an array containing a truncated view of an input ndarray and the last element along a specified 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", + "pop", + "view", + "remove", + "truncate" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js b/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js new file mode 100644 index 000000000000..d26618a3e934 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js @@ -0,0 +1,263 @@ +/** +* @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. +*/ + +/* eslint-disable object-curly-newline */ + +'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 typedarray = require( '@stdlib/array/typed' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ctor = require( '@stdlib/ndarray/ctor' ); +var pop = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof pop, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=1, strict, readonly)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( zeroTo( 6 ), 'float64' ); + sh = [ 6 ]; + st = [ 1 ]; + o = 0; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0, true, false ); + + 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.strictEqual( actual[0].ndims, 1, 'returns expected value' ); + t.strictEqual( actual[1].ndims, 1, 'returns expected value' ); + t.strictEqual( actual[0].length, 5, 'returns expected value' ); + t.strictEqual( actual[1].length, 1, 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 0, 1, 2, 3, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ 5 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=1, strict, writable)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( zeroTo( 6 ), 'float64' ); + sh = [ 6 ]; + st = [ 1 ]; + o = 0; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0, true, true ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), false, 'returns expected value' ); + t.strictEqual( actual[0].ndims, 1, 'returns expected value' ); + t.strictEqual( actual[1].ndims, 1, 'returns expected value' ); + t.strictEqual( actual[0].length, 5, 'returns expected value' ); + t.strictEqual( actual[1].length, 1, 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 0, 1, 2, 3, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ 5 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=2, strict, readonly)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( zeroTo( 8 ), 'float64' ); + sh = [ 2, 4 ]; + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0, true, false ); + + 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.strictEqual( actual[0].ndims, 2, 'returns expected value' ); + t.strictEqual( actual[1].ndims, 2, 'returns expected value' ); + t.strictEqual( actual[0].length, 4, 'returns expected value' ); + t.strictEqual( actual[1].length, 4, 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=2, strict, writable)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( zeroTo( 8 ), 'float64' ); + sh = [ 2, 4 ]; + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0, true, true ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), false, 'returns expected value' ); + t.strictEqual( actual[0].ndims, 2, 'returns expected value' ); + t.strictEqual( actual[1].ndims, 2, 'returns expected value' ); + t.strictEqual( actual[0].length, 4, 'returns expected value' ); + t.strictEqual( actual[1].length, 4, 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=3, strict, readonly)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( 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 ctor( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 1, true, false ); + + 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.strictEqual( actual[0].ndims, 3, 'returns expected value' ); + t.strictEqual( actual[1].ndims, 3, 'returns expected value' ); + t.strictEqual( actual[0].length, 4, 'returns expected value' ); + t.strictEqual( actual[1].length, 4, 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 0, 1 ] ], [ [ 4, 5 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 2, 3 ] ], [ [ 6, 7 ] ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an array containing ndarrays (ndims=3, strict, writable)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( 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 ctor( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 1, true, true ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), false, 'returns expected value' ); + t.strictEqual( actual[0].ndims, 3, 'returns expected value' ); + t.strictEqual( actual[1].ndims, 3, 'returns expected value' ); + t.strictEqual( actual[0].length, 4, 'returns expected value' ); + t.strictEqual( actual[1].length, 4, 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 0, 1 ] ], [ [ 4, 5 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 2, 3 ] ], [ [ 6, 7 ] ] ], 'returns expected value' ); + + t.end(); +}); From 7ac2f2bc62a6b89e1a103968f9b12795988808ea Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 12:57:45 +0500 Subject: [PATCH 02/20] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/pop/benchmark/benchmark.js | 2 +- lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js index eb58158f829d..2abf254e71f8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js index f0db1dda76df..031a72314d10 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js @@ -48,7 +48,7 @@ * arr = ndarray2array( y[ 0 ] ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* arr = ndarray2array( y[ 0 ] ); +* arr = ndarray2array( y[ 1 ] ); * // returns [ [ 5.0, 6.0 ] ] */ From 62de9a3d46ac31f266d852fddcc6847504ee78ea Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 13:02:40 +0500 Subject: [PATCH 03/20] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/pop/docs/types/index.d.ts | 8 ++++---- lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts index 892e8cb3d608..d0da0c07a448 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts @@ -56,7 +56,7 @@ import { ArrayLike } from '@stdlib/types/array'; * arr = ndarray2array( y[ 0 ] ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* arr = ndarray2array( y[ 0 ] ); +* arr = ndarray2array( y[ 1 ] ); * // returns [ [ 5.0, 6.0 ] ] */ declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; @@ -92,7 +92,7 @@ declare function pop = typedndarray>( x: * arr = ndarray2array( y[ 0 ] ); * // returns [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ] * -* arr = ndarray2array( y[ 0 ] ); +* arr = ndarray2array( y[ 1 ] ); * // returns [ [ 2.0, 3.0 ], [ 7.0, 8.0 ] ] */ declare function pop = typedndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; @@ -128,7 +128,7 @@ declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; @@ -163,7 +163,7 @@ declare function pop = typedndarray>( x * arr = ndarray2array( y[ 0 ] ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* arr = ndarray2array( y[ 0 ] ); +* arr = ndarray2array( y[ 1 ] ); * // returns [ [ 5.0, 6.0 ] ] */ declare function pop = genericndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js index f4d228331376..6d8b0d42766f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js @@ -60,7 +60,7 @@ var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); * arr = ndarray2array( y[ 0 ] ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* arr = ndarray2array( y[ 0 ] ); +* arr = ndarray2array( y[ 1 ] ); * // returns [ [ 5.0, 6.0 ] ] */ function pop( x, dim, strict, writable ) { From c427c6eaa70a02a8a20c069a15fb00c4cf0127ba Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 13:05:48 +0500 Subject: [PATCH 04/20] fix: lint error Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/pop/test/test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js b/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js index d26618a3e934..5cd1ff46cd37 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable object-curly-newline */ - 'use strict'; // MODULES // From 8501c7c45b362e7b6fbd96ac4d44bc2b5a740cdb Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 13:09:45 +0500 Subject: [PATCH 05/20] docs: fix lint error Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt index 8b7275ea40f7..3547324b81dc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -30,7 +30,9 @@ > var y = {{alias}}( x, 1, false, false ) - > {{alias:@stdlib/ndarray/to-array}}( y ) + > {{alias:@stdlib/ndarray/to-array}}( y[0] ) + [ [ 1 ], [ 3 ] ] + > {{alias:@stdlib/ndarray/to-array}}( y[1] ) [ [ 2 ], [ 4 ] ] See Also From f8ab79bcd4539d6c48e3615ec5344d1dad9dcce3 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 14:00:46 +0500 Subject: [PATCH 06/20] docs: fix lint error Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt index 3547324b81dc..66f2343ad5be 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -29,7 +29,7 @@ > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) > var y = {{alias}}( x, 1, false, false ) - + [ , ] > {{alias:@stdlib/ndarray/to-array}}( y[0] ) [ [ 1 ], [ 3 ] ] > {{alias:@stdlib/ndarray/to-array}}( y[1] ) From 92e1c2668c00296af02505e81ad1bd69b775163b Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 14:04:31 +0500 Subject: [PATCH 07/20] docs: fix lint error Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt index 66f2343ad5be..74b8e67aaa5e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -30,7 +30,7 @@ > var y = {{alias}}( x, 1, false, false ) [ , ] - > {{alias:@stdlib/ndarray/to-array}}( y[0] ) + > {{alias:@stdlib/ndarray/to-array}}( y[0] ) [ [ 1 ], [ 3 ] ] > {{alias:@stdlib/ndarray/to-array}}( y[1] ) [ [ 2 ], [ 4 ] ] From 449e600fc90ce40689d39d16948705b686ae4263 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Sep 2025 02:28:18 -0700 Subject: [PATCH 08/20] docs: update comment Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/pop/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/README.md b/lib/node_modules/@stdlib/ndarray/base/pop/README.md index ecb163c3f5fe..ef46adb15ce7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/pop/README.md @@ -112,7 +112,7 @@ var pop = require( '@stdlib/ndarray/base/pop' ); // Create a linear ndarray buffer: var buf = zeroTo( 27 ); -// Create an ndarray: +// Create an ndarray which is a stack of three 3x3 matrices: var x = array( buf, { 'shape': [ 3, 3, 3 ] }); From 6e7f9a9738523d5c1de0ecf8c07c46c136134b9b Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Sep 2025 02:28:36 -0700 Subject: [PATCH 09/20] style: remove empty line Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/pop/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/README.md b/lib/node_modules/@stdlib/ndarray/base/pop/README.md index ef46adb15ce7..c2b29544aac0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/pop/README.md @@ -122,7 +122,6 @@ var y = pop( x, 1, false, false ); // returns [ , ] console.log( ndarray2array( y[ 0 ] ) ); - console.log( ndarray2array( y[ 1 ] ) ); ``` From 726e8fdd8bc865ccf2c6f75b13ee67f6de88cd0c Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Sep 2025 02:29:12 -0700 Subject: [PATCH 10/20] style: add missing spaces Signed-off-by: Athan --- .../@stdlib/ndarray/base/pop/benchmark/benchmark.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js index 2abf254e71f8..1bd15e708562 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js @@ -37,11 +37,11 @@ bench( pkg+'::1d', function benchmark( b ) { /* eslint-disable object-curly-newline */ values = [ - empty( [ 2 ], { 'dtype': 'float64' }), - empty( [ 2 ], { 'dtype': 'float32' }), - empty( [ 2 ], { 'dtype': 'int32' }), - empty( [ 2 ], { 'dtype': 'complex128' }), - empty( [ 2 ], { 'dtype': 'generic' }) + 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 */ From 157c43e44d9d2c3810343027a7ecb31c0a8271ad Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Sep 2025 02:37:18 -0700 Subject: [PATCH 11/20] style: toggle lint rule Signed-off-by: Athan --- .../@stdlib/ndarray/base/pop/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js index 1bd15e708562..8df9f1ca496e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js @@ -34,7 +34,7 @@ bench( pkg+'::1d', function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ empty( [ 2 ], { 'dtype': 'float64' } ), @@ -44,7 +44,7 @@ bench( pkg+'::1d', function benchmark( b ) { empty( [ 2 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { From 06ecf0e30084609d5c8de2e06d65c7b4dd3e1363 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 15:12:23 +0500 Subject: [PATCH 12/20] refactor: apply suggestions from code review --- .../@stdlib/ndarray/base/pop/docs/types/index.d.ts | 8 ++++---- .../@stdlib/ndarray/base/pop/lib/main.js | 12 ++++++++++-- .../@stdlib/ndarray/base/slice-dimension/README.md | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts index d0da0c07a448..74e59bb7723a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts @@ -31,7 +31,7 @@ import { ArrayLike } from '@stdlib/types/array'; * @param x - input array * @param dim - dimension along which to perform the operation * @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable +* @param writable - boolean indicating whether returned arrays should be writable * @returns a list of ndarrays * * @example @@ -67,7 +67,7 @@ declare function pop = typedndarray>( x: * @param x - input array * @param dim - dimension along which to perform the operation * @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable +* @param writable - boolean indicating whether returned arrays should be writable * @returns a list of ndarrays * * @example @@ -103,7 +103,7 @@ declare function pop = typedndarray>( x * @param x - input array * @param dim - dimension along which to perform the operation * @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable +* @param writable - boolean indicating whether returned arrays should be writable * @returns a list of ndarrays * * @example diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js index 6d8b0d42766f..8a35770cf6eb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js @@ -20,6 +20,8 @@ // MODULES // +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); var getShape = require( '@stdlib/ndarray/base/shape' ); var sliceFrom = require( '@stdlib/ndarray/base/slice-from' ); var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); @@ -33,7 +35,7 @@ var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); * @param {ndarray} x - input array * @param {integer} dim - dimension along which to perform the operation * @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable +* @param {boolean} writable - boolean indicating whether returned arrays should be writable * @returns {Array} a list of ndarrays * * @example @@ -67,14 +69,20 @@ function pop( x, dim, strict, writable ) { var v0; var v1; var sh; + var N; var s; var i; + // Retrieve array meta data: sh = getShape( x ); + N = ndims( x ); + + // Resolve view slice: s = []; - for ( i = 0; i < sh.length; i++ ) { + for ( i = 0; i < N; i++ ) { s[ i ] = null; } + dim = normalizeIndex( dim, N -1 ); s[ dim ] = sh[ dim ] - 1; v1 = sliceFrom( x, s, strict, writable ); v0 = sliceTo( x, s, strict, writable ); diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md b/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md index 252ac3c46a4f..fa8ca4366ec7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md @@ -79,10 +79,10 @@ arr = ndarray2array( y ); The function accepts the following arguments: - **x**: input ndarray. -- **dim**: index of dimension along which to slice. 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**: 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`. - **slice**: a [`Slice`][@stdlib/slice/ctor] instance or an integer. If provided an integer less than zero, the corresponding element along the specified dimension is resolved relative to the last element along that dimension. For negative integers, the last element corresponds to the value `-1`. - **strict**: boolean indicating whether to enforce strict bounds checking. -- **writable**: boolean indicating whether a returned ndarray should be writable. +- **writable**: boolean indicating whether returned ndarrays should be writable. From 814fccfc3d3a81d2ac015142a11b62af65cdb2c8 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 20 Sep 2025 15:15:45 +0500 Subject: [PATCH 13/20] fix: remove wrong file Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../ndarray/base/slice-dimension/README.md | 201 ------------------ 1 file changed, 201 deletions(-) delete mode 100644 lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md b/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md deleted file mode 100644 index fa8ca4366ec7..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md +++ /dev/null @@ -1,201 +0,0 @@ - - -# sliceDimension - -> Return a view of an input ndarray when sliced along a specified dimension. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var sliceDimension = require( '@stdlib/ndarray/base/slice-dimension' ); -``` - -#### sliceDimension( x, dim, slice, strict, writable ) - -Returns a view of an input ndarray when sliced along a specified dimension. - -```javascript -var Slice = require( '@stdlib/slice/ctor' ); -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 sh = x.shape; -// returns [ 3, 2 ] - -var arr = ndarray2array( x ); -// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] - -var s = new Slice( null, null, -1 ); -// returns - -var y = sliceDimension( x, 0, s, false, false ); -// returns - -sh = y.shape; -// returns [ 3, 2 ] - -arr = ndarray2array( y ); -// returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] -``` - -The function accepts the following arguments: - -- **x**: input ndarray. -- **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`. -- **slice**: a [`Slice`][@stdlib/slice/ctor] instance or an integer. If provided an integer less than zero, the corresponding element along the specified dimension is resolved relative to the last element along that dimension. For negative integers, the last element corresponds to the value `-1`. -- **strict**: boolean indicating whether to enforce strict bounds checking. -- **writable**: boolean indicating whether returned ndarrays should be writable. - -
- - - - - -
- -## Notes - -- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. - -
- - - - - -
- -## Examples - - - - - -```javascript -var S = require( '@stdlib/slice/ctor' ); -var array = require( '@stdlib/ndarray/array' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var zeroTo = require( '@stdlib/array/base/zero-to' ); -var sliceDimension = require( '@stdlib/ndarray/base/slice-dimension' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var y1 = sliceDimension( x, 0, 0, false, false ); -// returns - -var a1 = ndarray2array( y1 ); -// returns [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var y2 = sliceDimension( x, 0, 1, false, false ); -// returns - -var a2 = ndarray2array( y2 ); -// returns [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var y3 = sliceDimension( x, 0, 2, false, false ); -// returns - -var a3 = ndarray2array( y3 ); -// returns [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse the matrix order: -var s = S( _, _, -1 ); -var y4 = sliceDimension( x, 0, s, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -// returns [...] - -// Get the second rows from each matrix: -var y5 = sliceDimension( x, 1, 1, false, false ); -// returns - -var a5 = ndarray2array( y5 ); -// returns [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var y6 = sliceDimension( x, 2, 1, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -// returns [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - From 98bfd58eafb593ce21aa27f941341092168b51b2 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 15:20:47 +0500 Subject: [PATCH 14/20] fix: restore file --- .../ndarray/base/slice-dimension/README.md | 201 ++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md b/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md new file mode 100644 index 000000000000..252ac3c46a4f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/slice-dimension/README.md @@ -0,0 +1,201 @@ + + +# sliceDimension + +> Return a view of an input ndarray when sliced along a specified dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var sliceDimension = require( '@stdlib/ndarray/base/slice-dimension' ); +``` + +#### sliceDimension( x, dim, slice, strict, writable ) + +Returns a view of an input ndarray when sliced along a specified dimension. + +```javascript +var Slice = require( '@stdlib/slice/ctor' ); +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 sh = x.shape; +// returns [ 3, 2 ] + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var s = new Slice( null, null, -1 ); +// returns + +var y = sliceDimension( x, 0, s, false, false ); +// returns + +sh = y.shape; +// returns [ 3, 2 ] + +arr = ndarray2array( y ); +// returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **dim**: index of dimension along which to slice. 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`. +- **slice**: a [`Slice`][@stdlib/slice/ctor] instance or an integer. If provided an integer less than zero, the corresponding element along the specified dimension is resolved relative to the last element along that dimension. For negative integers, the last element corresponds to the value `-1`. +- **strict**: boolean indicating whether to enforce strict bounds checking. +- **writable**: boolean indicating whether a returned ndarray should be writable. + +
+ + + + + +
+ +## Notes + +- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. + +
+ + + + + +
+ +## Examples + + + + + +```javascript +var S = require( '@stdlib/slice/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var sliceDimension = require( '@stdlib/ndarray/base/slice-dimension' ); + +// Alias `null` to allow for more compact indexing expressions: +var _ = null; + +// Create a linear ndarray buffer: +var buf = zeroTo( 27 ); + +// Create an ndarray: +var x = array( buf, { + 'shape': [ 3, 3, 3 ] +}); + +// Get each matrix... +var y1 = sliceDimension( x, 0, 0, false, false ); +// returns + +var a1 = ndarray2array( y1 ); +// returns [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] + +var y2 = sliceDimension( x, 0, 1, false, false ); +// returns + +var a2 = ndarray2array( y2 ); +// returns [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] + +var y3 = sliceDimension( x, 0, 2, false, false ); +// returns + +var a3 = ndarray2array( y3 ); +// returns [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] + +// Reverse the matrix order: +var s = S( _, _, -1 ); +var y4 = sliceDimension( x, 0, s, false, false ); +// returns + +var a4 = ndarray2array( y4 ); +// returns [...] + +// Get the second rows from each matrix: +var y5 = sliceDimension( x, 1, 1, false, false ); +// returns + +var a5 = ndarray2array( y5 ); +// returns [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] + +// Get the second columns from each matrix: +var y6 = sliceDimension( x, 2, 1, false, false ); +// returns + +var a6 = ndarray2array( y6 ); +// returns [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + From c575a4c069f2ada503d4330aafc2f31fb97af625 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 15:24:30 +0500 Subject: [PATCH 15/20] docs: 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/pop/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/README.md b/lib/node_modules/@stdlib/ndarray/base/pop/README.md index c2b29544aac0..39e6e200155c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/pop/README.md @@ -75,7 +75,7 @@ arr = ndarray2array( y[ 1 ] ); The function accepts the following arguments: - **x**: input ndarray. -- **dim**: dimension along which to perform the operation. +- **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`. - **strict**: boolean indicating whether to enforce strict bounds checking. - **writable**: boolean indicating whether a returned ndarray should be writable. From 7cead76ebec339a1eac5404ac70f159d53ee3bd4 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 15:26:41 +0500 Subject: [PATCH 16/20] docs: 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: na - task: lint_package_json status: na - task: lint_repl_help status: passed - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt index 74b8e67aaa5e..7abbd43f5e04 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -9,7 +9,9 @@ Input array. dim: integer - Dimension along which to perform the operation. + 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`. strict: boolean Boolean indicating whether to enforce strict bounds checking. From 199b4c8744bd976343b046e3ce7e694ee5d81742 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 15:33:46 +0500 Subject: [PATCH 17/20] docs: apply suggestions from code review --- lib/node_modules/@stdlib/ndarray/base/pop/README.md | 4 ++-- .../@stdlib/ndarray/base/pop/docs/repl.txt | 4 ++-- .../@stdlib/ndarray/base/pop/docs/types/index.d.ts | 10 +++++----- lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js | 2 +- lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/base/pop/package.json | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/README.md b/lib/node_modules/@stdlib/ndarray/base/pop/README.md index 39e6e200155c..7f38c1482b24 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/pop/README.md @@ -20,7 +20,7 @@ limitations under the License. # pop -> Return an array containing a truncated view of an input ndarray and the last element along a specified dimension. +> Return an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. @@ -42,7 +42,7 @@ var pop = require( '@stdlib/ndarray/base/pop' ); #### pop( x, dim, strict, writable ) -Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt index 7abbd43f5e04..0d01e9b6c471 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x, dim, strict, writable ) - Returns an array containing a truncated view of an input ndarray and the - last element along a specified dimension. + Returns an array containing a truncated view of an input ndarray and a + complementary view of the last element(s) along a specified dimension. Parameters ---------- diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts index 74e59bb7723a..42f1873d2da4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts @@ -26,7 +26,7 @@ import { ArrayLike } from '@stdlib/types/array'; /** -* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. * * @param x - input array * @param dim - dimension along which to perform the operation @@ -62,7 +62,7 @@ import { ArrayLike } from '@stdlib/types/array'; declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; /** -* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. * * @param x - input array * @param dim - dimension along which to perform the operation @@ -80,7 +80,7 @@ declare function pop = typedndarray>( x: * var strides = [ 2, 1 ]; * var offset = 0; * -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); * // returns * * var arr = ndarray2array( x ); @@ -98,7 +98,7 @@ declare function pop = typedndarray>( x: declare function pop = typedndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; /** -* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. * * @param x - input array * @param dim - dimension along which to perform the operation @@ -134,7 +134,7 @@ declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; /** -* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. * * @param x - input array * @param dim - dimension along which to perform the operation diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js index 031a72314d10..a2268f764480 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* Return an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. * * @module @stdlib/ndarray/base/pop * diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js index 8a35770cf6eb..e85f2a35b492 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js @@ -30,7 +30,7 @@ var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); // MAIN // /** -* Returns an array containing a truncated view of an input ndarray and the last element along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. * * @param {ndarray} x - input array * @param {integer} dim - dimension along which to perform the operation diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/package.json b/lib/node_modules/@stdlib/ndarray/base/pop/package.json index 5f66580196d3..9c299ede5f0b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/pop/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/pop", "version": "0.0.0", - "description": "Return an array containing a truncated view of an input ndarray and the last element along a specified dimension.", + "description": "Return an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 9d1123da589b972d3689b5b68a87bc875302fd8d Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 20 Sep 2025 15:36:13 +0500 Subject: [PATCH 18/20] docs: 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: 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- From c0e5699e76e09dcac53b4bd78780d0190e365a75 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 21 Sep 2025 19:14:44 +0500 Subject: [PATCH 19/20] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js | 3 --- lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js | 3 --- 2 files changed, 6 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js index a2268f764480..bc087a24979c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js @@ -36,9 +36,6 @@ * var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); * // returns * -* var sh = x.shape; -* // returns [ 3, 2 ] -* * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js index e85f2a35b492..9e7672038f4a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js @@ -50,9 +50,6 @@ var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); * var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); * // returns * -* var sh = x.shape; -* // returns [ 3, 2 ] -* * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * From 7de1f33a4d2c56ac6546f8e40a088b8744056ffd Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Sep 2025 00:58:48 -0700 Subject: [PATCH 20/20] chore: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/pop/README.md | 19 +- .../ndarray/base/pop/benchmark/benchmark.js | 66 +++--- .../@stdlib/ndarray/base/pop/docs/repl.txt | 18 +- .../ndarray/base/pop/docs/types/index.d.ts | 119 +---------- .../ndarray/base/pop/docs/types/test.ts | 70 +++--- .../ndarray/base/pop/examples/index.js | 8 +- .../@stdlib/ndarray/base/pop/lib/index.js | 4 +- .../@stdlib/ndarray/base/pop/lib/main.js | 41 ++-- .../@stdlib/ndarray/base/pop/package.json | 2 +- .../@stdlib/ndarray/base/pop/test/test.js | 199 +++++++++++++----- 10 files changed, 262 insertions(+), 284 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/README.md b/lib/node_modules/@stdlib/ndarray/base/pop/README.md index 7f38c1482b24..1951d95c6765 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/pop/README.md @@ -20,7 +20,7 @@ limitations under the License. # pop -> Return an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. +> Return an array containing a truncated view of an input ndarray and a view of the last element(s) along a specified dimension. @@ -40,9 +40,9 @@ limitations under the License. var pop = require( '@stdlib/ndarray/base/pop' ); ``` -#### pop( x, dim, strict, writable ) +#### pop( x, dim, writable ) -Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. +Returns an array containing a truncated view of an input ndarray and a view of the last element(s) along a specified dimension. ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -62,7 +62,7 @@ var sh = x.shape; var arr = ndarray2array( x ); // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -var y = pop( x, 0, false, false ); +var y = pop( x, 0, false ); // returns [ , ] arr = ndarray2array( y[ 0 ] ); @@ -76,7 +76,6 @@ The function accepts the following arguments: - **x**: input ndarray. - **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`. -- **strict**: boolean indicating whether to enforce strict bounds checking. - **writable**: boolean indicating whether a returned ndarray should be writable. @@ -109,17 +108,17 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var zeroTo = require( '@stdlib/array/base/zero-to' ); var pop = require( '@stdlib/ndarray/base/pop' ); -// Create a linear ndarray buffer: +// Create a linear data buffer: var buf = zeroTo( 27 ); -// Create an ndarray which is a stack of three 3x3 matrices: +// Create an ndarray: var x = array( buf, { 'shape': [ 3, 3, 3 ] }); +console.log( ndarray2array( x ) ); -// Get the first two rows of each matrix: -var y = pop( x, 1, false, false ); -// returns [ , ] +// Remove the last row from each matrix: +var y = pop( x, 1, false ); console.log( ndarray2array( y[ 0 ] ) ); console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js index 8df9f1ca496e..efc204cb6f3f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/benchmark/benchmark.js @@ -48,7 +48,7 @@ bench( pkg+'::1d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0, false, false ); + v = pop( values[ i%values.length ], 0, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -66,21 +66,21 @@ bench( pkg+'::2d', function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* 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' }) + 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 */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0, false, false ); + v = pop( values[ i%values.length ], 0, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -98,21 +98,21 @@ bench( pkg+'::3d', function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* 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' }) + 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 */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0, false, false ); + v = pop( values[ i%values.length ], 0, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -130,21 +130,21 @@ bench( pkg+'::4d', function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* 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' }) + 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 */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0, false, false ); + v = pop( values[ i%values.length ], 0, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -162,21 +162,21 @@ bench( pkg+'::5d', function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* 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' }) + 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 */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0, false, false ); + v = pop( values[ i%values.length ], 0, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt index 0d01e9b6c471..fb5202bccbda 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/repl.txt @@ -1,21 +1,18 @@ -{{alias}}( x, dim, strict, writable ) - Returns an array containing a truncated view of an input ndarray and a - complementary view of the last element(s) along a specified dimension. +{{alias}}( x, dim, writable ) + Returns an array containing a truncated view of an input ndarray and a view + of the last element(s) along a specified dimension. Parameters ---------- x: ndarray - Input array. + Input ndarray. dim: integer 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`. - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - writable: boolean Boolean indicating whether a returned ndarray should be writable. This parameter only applies to ndarray constructors which support read-only @@ -23,14 +20,15 @@ Returns ------- - out: array - Output array. + out: Array + An array containing a truncated view of an input ndarray and a view of + the last element(s) along a specified dimension. Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - > var y = {{alias}}( x, 1, false, false ) + > var y = {{alias}}( x, 1, false ) [ , ] > {{alias:@stdlib/ndarray/to-array}}( y[0] ) [ [ 1 ], [ 3 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts index 42f1873d2da4..e35e1b3ebde7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/index.d.ts @@ -20,17 +20,13 @@ /// -import { typedndarray, genericndarray } from '@stdlib/types/ndarray'; -import { ComplexLike } from '@stdlib/types/complex'; -import { ArrayLike } from '@stdlib/types/array'; - +import { ndarray } from '@stdlib/types/ndarray'; /** -* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a view of the last element(s) along a specified dimension. * * @param x - input array * @param dim - dimension along which to perform the operation -* @param strict - boolean indicating whether to enforce strict bounds checking * @param writable - boolean indicating whether returned arrays should be writable * @returns a list of ndarrays * @@ -50,114 +46,7 @@ import { ArrayLike } from '@stdlib/types/array'; * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = pop( x, 0, false, false ); -* // returns [ , ] -* -* arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] -* -* arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 5.0, 6.0 ] ] -*/ -declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; - -/** -* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. -* -* @param x - input array -* @param dim - dimension along which to perform the operation -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether returned arrays should be writable -* @returns a list of ndarrays -* -* @example -* var Complex64Array = require( '@stdlib/array/complex64' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); -* -* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -* var shape = [ 2, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] -* -* var y = pop( x, 0, false, false ); -* // returns [ , ] -* -* arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ] -* -* arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 2.0, 3.0 ], [ 7.0, 8.0 ] ] -*/ -declare function pop = typedndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; - -/** -* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. -* -* @param x - input array -* @param dim - dimension along which to perform the operation -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether returned arrays should be writable -* @returns a list of ndarrays -* -* @example -* var BooleanArray = require( '@stdlib/array/bool' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); -* -* var buffer = new BooleanArray( [ true, false, true, false, true, false ] ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var arr = ndarray2array( x ); -* // returns [ [ true, false ], [ true, false ], [ true, false ] ] -* -* var y = pop( x, 0, false, false ); -* // returns [ , ] -* -* arr = ndarray2array( y[ 0 ] ); -* // returns [ [ true, false ], [ true, false ] ] -* -* arr = ndarray2array( y[ 1 ] ); -* // returns [ [ true, false ] ] -*/ -declare function pop = typedndarray>( x: T, dim: number, strict: boolean, writable: boolean ): ArrayLike; - -/** -* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. -* -* @param x - input array -* @param dim - dimension along which to perform the operation -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether returned arrays should be writable -* @returns 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 = pop( x, 0, false, false ); +* var y = pop( x, 0, false ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); @@ -166,7 +55,7 @@ declare function pop = typedndarray>( x * arr = ndarray2array( y[ 1 ] ); * // returns [ [ 5.0, 6.0 ] ] */ -declare function pop = genericndarray>( x: U, dim: number, strict: boolean, writable: boolean ): ArrayLike; +declare function pop( x: T, dim: number, writable: boolean ): [ T, T ]; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts index 48154fd235a3..f149514367a2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/pop/docs/types/test.ts @@ -22,66 +22,53 @@ import pop = require( './index' ); // TESTS // -// The function returns an ndarray... +// The function returns an array of ndarrays... { const order = 'row-major'; const sh = [ 2, 2 ]; - pop( empty( 'float64', sh, order ), 1, false, false ); // $ExpectType Array - pop( empty( 'complex64', sh, order ), 1, false, false ); // $ExpectType Array - pop( empty( 'uint8c', sh, order ), 1, false, false ); // $ExpectType Array + pop( empty( 'float64', sh, order ), 1, false ); // $ExpectType [float64ndarray, float64ndarray] + pop( empty( 'complex64', sh, order ), 1, false ); // $ExpectType [complex64ndarray, complex64ndarray] + pop( empty( 'uint8', sh, order ), 1, false ); // $ExpectType [uint8ndarray, uint8ndarray] } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { - pop( '10', 1, false, false ); // $ExpectError - pop( 10, 1, false, false ); // $ExpectError - pop( false, 1, false, false ); // $ExpectError - pop( true, 1, false, false ); // $ExpectError - pop( null, 1, false, false ); // $ExpectError - pop( [], 1, false, false ); // $ExpectError - pop( {}, 1, false, false ); // $ExpectError - pop( ( x: number ): number => x, 1, false, false ); // $ExpectError + pop( '10', 1, false ); // $ExpectError + pop( 10, 1, false ); // $ExpectError + pop( false, 1, false ); // $ExpectError + pop( true, 1, false ); // $ExpectError + pop( null, 1, false ); // $ExpectError + pop( [], 1, false ); // $ExpectError + pop( {}, 1, false ); // $ExpectError + pop( ( x: number ): number => x, 1, false ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not an integer... { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - pop( x, '5', false, false ); // $ExpectError - pop( x, false, false, false ); // $ExpectError - pop( x, true, false, false ); // $ExpectError - pop( x, null, false, false ); // $ExpectError - pop( x, undefined, false, false ); // $ExpectError - pop( x, [ '5' ], false, false ); // $ExpectError - pop( x, {}, false, false ); // $ExpectError - pop( x, ( x: number ): number => x, false, false ); // $ExpectError + pop( x, '5', false ); // $ExpectError + pop( x, false, false ); // $ExpectError + pop( x, true, false ); // $ExpectError + pop( x, null, false ); // $ExpectError + pop( x, undefined, false ); // $ExpectError + pop( x, [ '5' ], false ); // $ExpectError + pop( x, {}, false ); // $ExpectError + pop( x, ( x: number ): number => x, false ); // $ExpectError } // The compiler throws an error if the function is provided a third argument which is not a boolean... { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - pop( x, 1, '5', false ); // $ExpectError - pop( x, 1, 5, false ); // $ExpectError - pop( x, 1, null, false ); // $ExpectError - pop( x, 1, undefined, false ); // $ExpectError - pop( x, 1, [ '5' ], false ); // $ExpectError - pop( x, 1, {}, false ); // $ExpectError - pop( x, 1, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - pop( x, 1, false, '5' ); // $ExpectError - pop( x, 1, false, 5 ); // $ExpectError - pop( x, 1, false, null ); // $ExpectError - pop( x, 1, false, undefined ); // $ExpectError - pop( x, 1, false, [ '5' ] ); // $ExpectError - pop( x, 1, false, {} ); // $ExpectError - pop( x, 1, false, ( x: number ): number => x ); // $ExpectError + pop( x, 1, '5' ); // $ExpectError + pop( x, 1, 5 ); // $ExpectError + pop( x, 1, null ); // $ExpectError + pop( x, 1, undefined ); // $ExpectError + pop( x, 1, [ '5' ] ); // $ExpectError + pop( x, 1, {} ); // $ExpectError + pop( x, 1, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -90,6 +77,5 @@ import pop = require( './index' ); pop( x ); // $ExpectError pop( x, 1 ); // $ExpectError - pop( x, 1, false ); // $ExpectError - pop( x, 1, false, false, {} ); // $ExpectError + pop( x, 1, false, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js index f32b59df739b..4f6b198a1b62 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/examples/index.js @@ -23,19 +23,17 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var zeroTo = require( '@stdlib/array/base/zero-to' ); var pop = require( './../lib' ); -// Create a linear ndarray buffer: +// Create a linear data buffer: var buf = zeroTo( 27 ); // Create an ndarray: var x = array( buf, { 'shape': [ 3, 3, 3 ] }); - console.log( ndarray2array( x ) ); -// Get the first two rows of each matrix: -var y = pop( x, 1, false, false ); +// Remove the last row from each matrix: +var y = pop( x, 1, false ); console.log( ndarray2array( y[ 0 ] ) ); - console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js index bc087a24979c..c1a24c7fae96 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. +* Return an array containing a truncated view of an input ndarray and a view of the last element(s) along a specified dimension. * * @module @stdlib/ndarray/base/pop * @@ -39,7 +39,7 @@ * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = pop( x, 0, false, false ); +* var y = pop( x, 0, false ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js index 9e7672038f4a..ade85de2c9f7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js @@ -20,23 +20,25 @@ // MODULES // -var ndims = require( '@stdlib/ndarray/base/ndims' ); var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); var getShape = require( '@stdlib/ndarray/base/shape' ); var sliceFrom = require( '@stdlib/ndarray/base/slice-from' ); var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); +var nulls = require( '@stdlib/array/base/nulls' ); +var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension. +* Returns an array containing a truncated view of an input ndarray and a view of the last element(s) along a specified dimension. * * @param {ndarray} x - input array * @param {integer} dim - dimension along which to perform the operation -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking * @param {boolean} writable - boolean indicating whether returned arrays should be writable -* @returns {Array} a list of ndarrays +* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {RangeError} dimension index exceeds the number of dimensions +* @returns {Array} a list of ndarrays * * @example * var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -53,7 +55,7 @@ var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = pop( x, 0, false, false ); +* var y = pop( x, 0, false ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); @@ -62,27 +64,36 @@ var sliceTo = require( '@stdlib/ndarray/base/slice-to' ); * arr = ndarray2array( y[ 1 ] ); * // returns [ [ 5.0, 6.0 ] ] */ -function pop( x, dim, strict, writable ) { +function pop( x, dim, writable ) { var v0; var v1; var sh; var N; var s; - var i; // Retrieve array meta data: sh = getShape( x ); - N = ndims( x ); + N = sh.length; - // Resolve view slice: - s = []; - for ( i = 0; i < N; i++ ) { - s[ i ] = null; + // Check whether we were provided a zero-dimensional array... + if ( N === 0 ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) ); } - dim = normalizeIndex( dim, N -1 ); + // Normalize the dimension index: + dim = normalizeIndex( dim, N-1 ); + if ( dim === -1 ) { + throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) ); + } + // Define a list of slice arguments: + s = nulls( N ); s[ dim ] = sh[ dim ] - 1; - v1 = sliceFrom( x, s, strict, writable ); - v0 = sliceTo( x, s, strict, writable ); + + // Create a truncated view: + v0 = sliceTo( x, s, true, writable ); + + // Create a view of the last element(s): + v1 = sliceFrom( x, s, true, writable ); + return [ v0, v1 ]; } diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/package.json b/lib/node_modules/@stdlib/ndarray/base/pop/package.json index 9c299ede5f0b..d2077ef38bd9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/pop/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/pop", "version": "0.0.0", - "description": "Return an array containing a truncated view of an input ndarray and a complementary view of the last element(s) along a specified dimension.", + "description": "Return an array containing a truncated view of an input ndarray and a view of the last element(s) along a specified dimension.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js b/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js index 5cd1ff46cd37..dcdabf6c8b4b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/pop/test/test.js @@ -23,10 +23,11 @@ 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 typedarray = require( '@stdlib/array/typed' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getShape = require( '@stdlib/ndarray/shape' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ctor = require( '@stdlib/ndarray/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); var pop = require( './../lib' ); @@ -38,7 +39,49 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns an array containing ndarrays (ndims=1, strict, readonly)', function test( t ) { +tape( 'the function throws an error if provided a zero-dimensional array', function test( t ) { + var values; + var i; + + values = [ + zeros( [] ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); + } + t.end(); + + function badValue( x ) { + return function badValue() { + pop( x, 0, false ); + }; + } +}); + +tape( 'the function throws an error if the dimension index exceeds the number of dimensions', function test( t ) { + var values; + 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() { + pop( x, dim, false ); + }; + } +}); + +tape( 'the function returns an array containing ndarrays (ndims=1, readonly)', function test( t ) { var actual; var buf; var ord; @@ -47,31 +90,29 @@ tape( 'the function returns an array containing ndarrays (ndims=1, strict, reado var o; var x; - buf = typedarray( zeroTo( 6 ), 'float64' ); + buf = zeroTo( 6, 'float64' ); sh = [ 6 ]; st = [ 1 ]; o = 0; ord = 'row-major'; - x = new ctor( 'float64', buf, sh, st, o, ord ); + x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 0, true, false ); + actual = pop( x, 0, false ); 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.strictEqual( actual[0].ndims, 1, 'returns expected value' ); - t.strictEqual( actual[1].ndims, 1, 'returns expected value' ); - t.strictEqual( actual[0].length, 5, 'returns expected value' ); - t.strictEqual( actual[1].length, 1, '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] ), [ 0, 1, 2, 3, 4 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ 5 ], 'returns expected value' ); t.end(); }); -tape( 'the function returns an array containing ndarrays (ndims=1, strict, writable)', function test( t ) { +tape( 'the function returns an array containing ndarrays (ndims=1, writable)', function test( t ) { var actual; var buf; var ord; @@ -80,31 +121,29 @@ tape( 'the function returns an array containing ndarrays (ndims=1, strict, writa var o; var x; - buf = typedarray( zeroTo( 6 ), 'float64' ); + buf = zeroTo( 6, 'float64' ); sh = [ 6 ]; st = [ 1 ]; o = 0; ord = 'row-major'; - x = new ctor( 'float64', buf, sh, st, o, ord ); + x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 0, true, true ); + actual = pop( x, -1, true ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), false, 'returns expected value' ); - t.strictEqual( actual[0].ndims, 1, 'returns expected value' ); - t.strictEqual( actual[1].ndims, 1, 'returns expected value' ); - t.strictEqual( actual[0].length, 5, 'returns expected value' ); - t.strictEqual( actual[1].length, 1, '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] ), [ 0, 1, 2, 3, 4 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ 5 ], 'returns expected value' ); t.end(); }); -tape( 'the function returns an array containing ndarrays (ndims=2, strict, readonly)', function test( t ) { +tape( 'the function returns an array containing ndarrays (ndims=2, readonly)', function test( t ) { var actual; var buf; var ord; @@ -113,31 +152,40 @@ tape( 'the function returns an array containing ndarrays (ndims=2, strict, reado var o; var x; - buf = typedarray( zeroTo( 8 ), 'float64' ); + buf = zeroTo( 8, 'float64' ); sh = [ 2, 4 ]; st = [ 4, 1 ]; o = 0; ord = 'row-major'; - x = new ctor( 'float64', buf, sh, st, o, ord ); + x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 0, true, false ); + actual = pop( x, 0, false ); 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.strictEqual( actual[0].ndims, 2, 'returns expected value' ); - t.strictEqual( actual[1].ndims, 2, 'returns expected value' ); - t.strictEqual( actual[0].length, 4, 'returns expected value' ); - t.strictEqual( actual[1].length, 4, '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] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + actual = pop( x, 1, false ); + + 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] ), [ [ 0, 1, 2 ], [ 4, 5, 6 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 3 ], [ 7 ] ], 'returns expected value' ); + t.end(); }); -tape( 'the function returns an array containing ndarrays (ndims=2, strict, writable)', function test( t ) { +tape( 'the function returns an array containing ndarrays (ndims=2, writable)', function test( t ) { var actual; var buf; var ord; @@ -146,31 +194,40 @@ tape( 'the function returns an array containing ndarrays (ndims=2, strict, writa var o; var x; - buf = typedarray( zeroTo( 8 ), 'float64' ); + buf = zeroTo( 8, 'float64' ); sh = [ 2, 4 ]; st = [ 4, 1 ]; o = 0; ord = 'row-major'; - x = new ctor( 'float64', buf, sh, st, o, ord ); + x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 0, true, true ); + actual = pop( x, -2, true ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), false, 'returns expected value' ); - t.strictEqual( actual[0].ndims, 2, 'returns expected value' ); - t.strictEqual( actual[1].ndims, 2, 'returns expected value' ); - t.strictEqual( actual[0].length, 4, 'returns expected value' ); - t.strictEqual( actual[1].length, 4, '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] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + actual = pop( x, -1, true ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), false, '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] ), [ [ 0, 1, 2 ], [ 4, 5, 6 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 3 ], [ 7 ] ], 'returns expected value' ); + t.end(); }); -tape( 'the function returns an array containing ndarrays (ndims=3, strict, readonly)', function test( t ) { +tape( 'the function returns an array containing ndarrays (ndims=3, readonly)', function test( t ) { var actual; var buf; var ord; @@ -179,7 +236,7 @@ tape( 'the function returns an array containing ndarrays (ndims=3, strict, reado var o; var x; - buf = typedarray( zeroTo( 8 ), 'float64' ); + buf = zeroTo( 8, 'float64' ); sh = [ 2, 2, 2 ]; st = [ 4, 2, 1 ]; o = 0; @@ -197,25 +254,45 @@ tape( 'the function returns an array containing ndarrays (ndims=3, strict, reado * ] *]; */ - x = new ctor( 'float64', buf, sh, st, o, ord ); + x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 1, true, false ); + actual = pop( x, 0, false ); 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.strictEqual( actual[0].ndims, 3, 'returns expected value' ); - t.strictEqual( actual[1].ndims, 3, 'returns expected value' ); - t.strictEqual( actual[0].length, 4, 'returns expected value' ); - t.strictEqual( actual[1].length, 4, '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] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); + + actual = pop( x, 1, false ); + + 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] ), [ [ [ 0, 1 ] ], [ [ 4, 5 ] ] ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ [ [ 2, 3 ] ], [ [ 6, 7 ] ] ], 'returns expected value' ); + actual = pop( x, 2, false ); + + 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] ), [ [ [ 0 ], [ 2 ] ], [ [ 4 ], [ 6 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 1 ], [ 3 ] ], [ [ 5 ], [ 7 ] ] ], 'returns expected value' ); + t.end(); }); -tape( 'the function returns an array containing ndarrays (ndims=3, strict, writable)', function test( t ) { +tape( 'the function returns an array containing ndarrays (ndims=3, writable)', function test( t ) { var actual; var buf; var ord; @@ -224,7 +301,7 @@ tape( 'the function returns an array containing ndarrays (ndims=3, strict, writa var o; var x; - buf = typedarray( zeroTo( 8 ), 'float64' ); + buf = zeroTo( 8, 'float64' ); sh = [ 2, 2, 2 ]; st = [ 4, 2, 1 ]; o = 0; @@ -242,20 +319,40 @@ tape( 'the function returns an array containing ndarrays (ndims=3, strict, writa * ] *]; */ - x = new ctor( 'float64', buf, sh, st, o, ord ); + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, -3, true ); - actual = pop( x, 1, true, true ); + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), false, '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] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); + + actual = pop( x, -2, true ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), false, 'returns expected value' ); - t.strictEqual( actual[0].ndims, 3, 'returns expected value' ); - t.strictEqual( actual[1].ndims, 3, 'returns expected value' ); - t.strictEqual( actual[0].length, 4, 'returns expected value' ); - t.strictEqual( actual[1].length, 4, '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] ), [ [ [ 0, 1 ] ], [ [ 4, 5 ] ] ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ [ [ 2, 3 ] ], [ [ 6, 7 ] ] ], 'returns expected value' ); + actual = pop( x, -1, true ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), false, '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] ), [ [ [ 0 ], [ 2 ] ], [ [ 4 ], [ 6 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 1 ], [ 3 ] ], [ [ 5 ], [ 7 ] ] ], 'returns expected value' ); + t.end(); });