From e4361788561902309c1548708501dae1f55d3227 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 26 Sep 2025 11:26:30 +0500 Subject: [PATCH 01/11] feat: add ndarray/pop --- 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/pop/README.md | 148 ++++++++ .../ndarray/pop/benchmark/benchmark.js | 190 ++++++++++ .../@stdlib/ndarray/pop/docs/repl.txt | 34 ++ .../@stdlib/ndarray/pop/docs/types/index.d.ts | 62 ++++ .../@stdlib/ndarray/pop/docs/types/test.ts | 67 ++++ .../@stdlib/ndarray/pop/examples/index.js | 39 +++ .../@stdlib/ndarray/pop/lib/index.js | 59 ++++ .../@stdlib/ndarray/pop/lib/main.js | 79 +++++ .../@stdlib/ndarray/pop/package.json | 67 ++++ .../@stdlib/ndarray/pop/test/test.js | 328 ++++++++++++++++++ 10 files changed, 1073 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/pop/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/pop/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/pop/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/pop/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/pop/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/pop/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md new file mode 100644 index 000000000000..b613ca5bde7c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -0,0 +1,148 @@ + + +# pop + +> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the last element(s) along a specified dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var pop = require( '@stdlib/ndarray/pop' ); +``` + +#### pop( x, dim ) + +Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specified dimension. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var shape = [ 3, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = pop( x, 0 ); +// 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. 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`. + +
+ + + + + +
+ +
+ + + + + +
+ +## 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/pop' ); + +// Create a linear data buffer: +var buf = zeroTo( 27 ); + +// Create an ndarray: +var x = array( buf, { + 'shape': [ 3, 3, 3 ] +}); +console.log( ndarray2array( x ) ); + +// Remove the last row from each matrix: +var y = pop( x, 1 ); + +console.log( ndarray2array( y[ 0 ] ) ); +console.log( ndarray2array( y[ 1 ] ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js new file mode 100644 index 000000000000..62af96a50f7a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js @@ -0,0 +1,190 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var empty = require( '@stdlib/ndarray/empty' ); +var pkg = require( './../package.json' ).name; +var pop = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::1d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2 ], { 'dtype': 'float64' } ), + empty( [ 2 ], { 'dtype': 'float32' } ), + empty( [ 2 ], { 'dtype': 'int32' } ), + empty( [ 2 ], { 'dtype': 'complex128' } ), + empty( [ 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::2d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::3d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::4d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array of ndarrays' ); + } + } + b.toc(); + if ( !isndarrayLike( v[0] ) || !isndarrayLike( v[1] ) ) { + b.fail( 'should return an array of ndarrays' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::5d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = pop( values[ i%values.length ], 0 ); + 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/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt new file mode 100644 index 000000000000..8fb82b663be1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( x, dim ) + Returns an array containing a read-only truncated view of an input ndarray + and a read-only view of the last element(s) along a specified dimension. + + Parameters + ---------- + x: ndarray + 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`. + + Returns + ------- + out: Array + An array containing a read-only truncated view of an input ndarray and a + read-only 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 ) + [ , ] + > {{alias:@stdlib/ndarray/to-array}}( y[0] ) + [ [ 1 ], [ 3 ] ] + > {{alias:@stdlib/ndarray/to-array}}( y[1] ) + [ [ 2 ], [ 4 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts new file mode 100644 index 000000000000..ef5e06e5d8a3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. +* +* @param x - input array +* @param dim - dimension along which to perform the operation +* @returns a list of ndarrays +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = pop( x, 0 ); +* // 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( x: T, dim: number ): [ T, T ]; + + +// EXPORTS // + +export = pop; diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts new file mode 100644 index 000000000000..a58e613d79a3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts @@ -0,0 +1,67 @@ +/* +* @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 array of ndarrays... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + pop( empty( 'float64', sh, order ), 1 ); // $ExpectType [float64ndarray, float64ndarray] + pop( empty( 'complex64', sh, order ), 1 ); // $ExpectType [complex64ndarray, complex64ndarray] + pop( empty( 'uint8', sh, order ), 1 ); // $ExpectType [uint8ndarray, uint8ndarray] +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + pop( '10', 1 ); // $ExpectError + pop( 10, 1 ); // $ExpectError + pop( false, 1 ); // $ExpectError + pop( true, 1 ); // $ExpectError + pop( null, 1 ); // $ExpectError + pop( [], 1 ); // $ExpectError + pop( {}, 1 ); // $ExpectError + pop( ( x: number ): number => x, 1 ); // $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' ); // $ExpectError + pop( x, false ); // $ExpectError + pop( x, true ); // $ExpectError + pop( x, null ); // $ExpectError + pop( x, undefined ); // $ExpectError + pop( x, [ '5' ] ); // $ExpectError + pop( x, {} ); // $ExpectError + pop( x, ( 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 +} diff --git a/lib/node_modules/@stdlib/ndarray/pop/examples/index.js b/lib/node_modules/@stdlib/ndarray/pop/examples/index.js new file mode 100644 index 000000000000..8d38d7f30e56 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/examples/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var pop = require( './../lib' ); + +// Create a linear data buffer: +var buf = zeroTo( 27 ); + +// Create an ndarray: +var x = array( buf, { + 'shape': [ 3, 3, 3 ] +}); +console.log( ndarray2array( x ) ); + +// Remove the last row from each matrix: +var y = pop( x, 1 ); + +console.log( ndarray2array( y[ 0 ] ) ); +console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js new file mode 100644 index 000000000000..b3125c7766c9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. +* +* @module @stdlib/ndarray/pop +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var pop = require( '@stdlib/ndarray/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 arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = pop( x, 0 ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* arr = ndarray2array( y[ 1 ] ); +* // returns [ [ 5.0, 6.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js new file mode 100644 index 000000000000..eb694a7a6e03 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -0,0 +1,79 @@ +/** +* @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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var base = require( '@stdlib/ndarray/base/pop' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. +* +* @param {ndarray} x - input array +* @param {integer} dim - dimension along which to perform the operation +* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {RangeError} dimension index exceeds the number of dimensions +* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {TypeError} second argument must be an integer +* @returns {Array} a list of ndarray views +* +* @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 ); +* // returns [ , ] +* +* arr = ndarray2array( y[ 0 ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* arr = ndarray2array( y[ 1 ] ); +* // returns [ [ 5.0, 6.0 ] ] +*/ +function pop( x, dim ) { + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + if ( !isInteger( dim ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + } + return base( x, dim, false ); +} + + +// EXPORTS // + +module.exports = pop; diff --git a/lib/node_modules/@stdlib/ndarray/pop/package.json b/lib/node_modules/@stdlib/ndarray/pop/package.json new file mode 100644 index 000000000000..2ba7602006ed --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ndarray/pop", + "version": "0.0.0", + "description": "Return an array containing a read only truncated view of an input ndarray and a read only view of the last element(s) 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/pop/test/test.js b/lib/node_modules/@stdlib/ndarray/pop/test/test.js new file mode 100644 index 000000000000..58ceff9aa9c4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/pop/test/test.js @@ -0,0 +1,328 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var 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 throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + pop( value, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var x; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + x = zeros( [ 2, 2 ] ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + pop( x, value ); + }; + } +}); + +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 read-only ndarrays (ndims=1)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 6 ]; + st = [ 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0 ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 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 read-only ndarrays (ndims=2)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 4 ]; + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0 ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 4 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + + actual = pop( x, 1 ); + + 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 read-only ndarrays (ndims=3)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 2, 2 ]; + st = [ 4, 2, 1 ]; + o = 0; + ord = 'row-major'; + + /* + * [ + * [ + * [ 0, 1 ], + * [ 2, 3 ] + * ], + * [ + * [ 4, 5 ], + * [ 6, 7 ] + * ] + *]; + */ + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = pop( x, 0 ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); + + actual = pop( x, 1 ); + + 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 ); + + 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 empty read-only views if provided an empty array (ndims=2)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + sh = [ 2, 0 ]; + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = 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.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + + 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, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 0 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + + sh = [ 0, 4 ]; + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + 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.deepEqual( getShape( actual[0] ), [ 0, 4 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 0, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], '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] ), [ 0, 3 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 0, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + + t.end(); +}); From 991888e902762f63479c8fd759182308f76ea6b4 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 26 Sep 2025 20:04:39 +0500 Subject: [PATCH 02/11] fix: 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: passed - 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/pop/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/package.json b/lib/node_modules/@stdlib/ndarray/pop/package.json index 2ba7602006ed..7c116aadb7df 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/package.json +++ b/lib/node_modules/@stdlib/ndarray/pop/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/pop", "version": "0.0.0", - "description": "Return an array containing a read only truncated view of an input ndarray and a read only view of the last element(s) along a specified dimension.", + "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 0418c32ee2df00b172bffe142fa131638dc6d2b0 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 26 Sep 2025 21:03:02 +0500 Subject: [PATCH 03/11] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: 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/pop/README.md | 46 ++- .../ndarray/pop/benchmark/benchmark.js | 10 +- .../@stdlib/ndarray/pop/docs/repl.txt | 10 +- .../@stdlib/ndarray/pop/docs/types/index.d.ts | 21 +- .../@stdlib/ndarray/pop/docs/types/test.ts | 54 ++-- .../@stdlib/ndarray/pop/lib/index.js | 6 +- .../@stdlib/ndarray/pop/lib/main.js | 34 ++- .../@stdlib/ndarray/pop/test/test.js | 266 ++++++++++++++---- 8 files changed, 351 insertions(+), 96 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md index b613ca5bde7c..0662d6695a77 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -40,7 +40,7 @@ limitations under the License. var pop = require( '@stdlib/ndarray/pop' ); ``` -#### pop( x, dim ) +#### pop( x\[, options] ) Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specified dimension. @@ -60,20 +60,56 @@ var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); var arr = ndarray2array( x ); // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -var y = pop( x, 0 ); +var y = pop( x ); // returns [ , ] arr = ndarray2array( y[ 0 ] ); -// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +// returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] arr = ndarray2array( y[ 1 ] ); -// returns [ [ 5.0, 6.0 ] ] +// returns [ [ 2.0 ], [ 4.0 ], [ 6.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`. +- **options**: function options. (_optional_) + +The function supports the following `options`: + +- **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. + +By default, the function performs the operation along the last dimension of the input [ndarray][@stdlib/ndarray/ctor]. To perform the operation on a desired dimension, specify the `dim` option. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var shape = [ 3, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var opts = { + 'dim': 0 +}; + +var y = pop( x, opts ); +// returns [ , ] + +arr = ndarray2array( y[ 0 ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +arr = ndarray2array( y[ 1 ] ); +// returns [ [ 5.0, 6.0 ] ] +``` diff --git a/lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js index 62af96a50f7a..ca1803f1c37a 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/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 ); + v = pop( values[ i%values.length ] ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -80,7 +80,7 @@ bench( pkg+'::2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0 ); + v = pop( values[ i%values.length ] ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -112,7 +112,7 @@ bench( pkg+'::3d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0 ); + v = pop( values[ i%values.length ] ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -144,7 +144,7 @@ bench( pkg+'::4d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0 ); + v = pop( values[ i%values.length ] ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } @@ -176,7 +176,7 @@ bench( pkg+'::5d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = pop( values[ i%values.length ], 0 ); + v = pop( values[ i%values.length ] ); if ( typeof v !== 'object' ) { b.fail( 'should return an array of ndarrays' ); } diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt index 8fb82b663be1..0158d57d0bce 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( x, dim ) +{{alias}}( x[, options] ) Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. @@ -8,10 +8,14 @@ x: ndarray Input ndarray. - dim: integer + options: Object (optional) + Options. + + options.dim: integer (optional) Dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. + Default: `-1`. Returns ------- @@ -23,7 +27,7 @@ -------- > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - > var y = {{alias}}( x, 1 ) + > var y = {{alias}}( x ) [ , ] > {{alias:@stdlib/ndarray/to-array}}( y[0] ) [ [ 1 ], [ 3 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts index ef5e06e5d8a3..842406a9287e 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts @@ -22,11 +22,22 @@ import { ndarray } from '@stdlib/types/ndarray'; +/** +* Interface defining function options. +*/ +interface Options { + /** + * Dimension along which to perform the operation. + */ + dim?: number; +} + /** * Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. * * @param x - input array -* @param dim - dimension along which to perform the operation +* @param options - function options +* @param options.dim - dimension along which to perform the operation * @returns a list of ndarrays * * @example @@ -45,16 +56,16 @@ import { ndarray } from '@stdlib/types/ndarray'; * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = pop( x, 0 ); +* var y = pop( x ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* // returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] * * arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 5.0, 6.0 ] ] +* // returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] */ -declare function pop( x: T, dim: number ): [ T, T ]; +declare function pop( x: T, options?: Options ): [ T, T ]; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts index a58e613d79a3..40d04178ab40 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts @@ -27,24 +27,37 @@ import pop = require( './index' ); const order = 'row-major'; const sh = [ 2, 2 ]; - pop( empty( 'float64', sh, order ), 1 ); // $ExpectType [float64ndarray, float64ndarray] - pop( empty( 'complex64', sh, order ), 1 ); // $ExpectType [complex64ndarray, complex64ndarray] - pop( empty( 'uint8', sh, order ), 1 ); // $ExpectType [uint8ndarray, uint8ndarray] + pop( empty( 'float64', sh, order ) ); // $ExpectType [float64ndarray, float64ndarray] + pop( empty( 'complex64', sh, order ) ); // $ExpectType [complex64ndarray, complex64ndarray] + pop( empty( 'uint8', sh, order ) ); // $ExpectType [uint8ndarray, uint8ndarray] + + pop( empty( 'float64', sh, order ), {} ); // $ExpectType [float64ndarray, float64ndarray] + pop( empty( 'complex64', sh, order ), {} ); // $ExpectType [complex64ndarray, complex64ndarray] + pop( empty( 'uint8', sh, order ), {} ); // $ExpectType [uint8ndarray, uint8ndarray] } // The compiler throws an error if the function is provided a first argument which is not an ndarray... { - pop( '10', 1 ); // $ExpectError - pop( 10, 1 ); // $ExpectError - pop( false, 1 ); // $ExpectError - pop( true, 1 ); // $ExpectError - pop( null, 1 ); // $ExpectError - pop( [], 1 ); // $ExpectError - pop( {}, 1 ); // $ExpectError - pop( ( x: number ): number => x, 1 ); // $ExpectError + pop( '10' ); // $ExpectError + pop( 10 ); // $ExpectError + pop( false ); // $ExpectError + pop( true ); // $ExpectError + pop( null ); // $ExpectError + pop( [] ); // $ExpectError + pop( {} ); // $ExpectError + pop( ( x: number ): number => x ); // $ExpectError + + pop( '10', {} ); // $ExpectError + pop( 10, {} ); // $ExpectError + pop( false, {} ); // $ExpectError + pop( true, {} ); // $ExpectError + pop( null, {} ); // $ExpectError + pop( [], {} ); // $ExpectError + pop( {}, {} ); // $ExpectError + pop( ( x: number ): number => x, {} ); // $ExpectError } -// The compiler throws an error if the function is provided a second argument which is not an integer... +// The compiler throws an error if the function is provided a second argument which is not an object... { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); @@ -52,16 +65,25 @@ import pop = require( './index' ); pop( x, false ); // $ExpectError pop( x, true ); // $ExpectError pop( x, null ); // $ExpectError - pop( x, undefined ); // $ExpectError pop( x, [ '5' ] ); // $ExpectError - pop( x, {} ); // $ExpectError pop( x, ( x: number ): number => x ); // $ExpectError } +// The compiler throws an error if the function is provided a second argument with invalid `dim` option... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + pop( x, { 'dim':'5'} ); // $ExpectError + pop( x, { 'dim': false} ); // $ExpectError + pop( x, { 'dim': true} ); // $ExpectError + pop( x, { 'dim': null} ); // $ExpectError + pop( x, { 'dim': [ '5' ]} ); // $ExpectError + pop( x, { 'dim': ( x: number ): number => x } ); // $ExpectError +} + // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - pop( x ); // $ExpectError - pop( x, 1, {} ); // $ExpectError + pop( x, {}, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js index b3125c7766c9..870976083905 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js @@ -39,14 +39,14 @@ * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = pop( x, 0 ); +* var y = pop( x ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* // returns [ [ 1 ], [ 3 ], [ 5 ] ] * * arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 5.0, 6.0 ] ] +* // returns [ [ 2 ], [ 4 ], [ 6 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index eb694a7a6e03..9e42d6cba062 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -20,6 +20,8 @@ // MODULES // +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var base = require( '@stdlib/ndarray/base/pop' ); @@ -32,7 +34,8 @@ var format = require( '@stdlib/string/format' ); * Returns an array containing a read-only truncated view of an input ndarray and a read-only 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 {Object} options - functions options +* @param {integer} options.dim=-1 - dimension along which to perform the operation * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {RangeError} dimension index exceeds the number of dimensions * @throws {TypeError} first argument must be an ndarray having one or more dimensions @@ -54,23 +57,38 @@ var format = require( '@stdlib/string/format' ); * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = pop( x, 0 ); +* var y = pop( x ); * // returns [ , ] * * arr = ndarray2array( y[ 0 ] ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* // returns [ [ 1.0 ], [ 3.0 ], [ 5.0 ] ] * * arr = ndarray2array( y[ 1 ] ); -* // returns [ [ 5.0, 6.0 ] ] +* // returns [ [ 2.0 ], [ 4.0 ], [ 6.0 ] ] */ -function pop( x, dim ) { +function pop( x ) { + var options; + var opts; + + opts = { + 'dim': -1 + }; if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + if ( arguments.length > 1 ) { + options = arguments[ 1 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'dim' ) ) { + if ( !isInteger( options.dim ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'dim', options.dim ) ); + } + opts.dim = options.dim; + } } - return base( x, dim, false ); + return base( x, opts.dim, false ); } diff --git a/lib/node_modules/@stdlib/ndarray/pop/test/test.js b/lib/node_modules/@stdlib/ndarray/pop/test/test.js index 58ceff9aa9c4..3b37991117ab 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/pop/test/test.js @@ -63,12 +63,41 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - pop( value, 0 ); + pop( value ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { +tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + pop( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { var values; var x; var i; @@ -82,7 +111,6 @@ tape( 'the function throws an error if provided a second argument which is not a null, void 0, [], - {}, function noop() {} ]; x = zeros( [ 2, 2 ] ); @@ -99,8 +127,44 @@ tape( 'the function throws an error if provided a second argument which is not a } }); +tape( 'the function throws an error if provided an options argument with an invalid `dim` option', function test( t ) { + var values; + var opts; + var x; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + x = zeros( [ 2, 2 ] ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'dim': value + }; + pop( x, opts ); + }; + } +}); + tape( 'the function throws an error if the dimension index exceeds the number of dimensions', function test( t ) { var values; + var opts; var i; values = [ @@ -117,7 +181,10 @@ tape( 'the function throws an error if the dimension index exceeds the number of function badValue( x, dim ) { return function badValue() { - pop( x, dim, false ); + opts = { + 'dim': dim + }; + pop( x, opts ); }; } }); @@ -139,7 +206,42 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=1)', f x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 0 ); + actual = pop( x ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 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 read-only ndarrays (ndims=1, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 6 ]; + st = [ 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 0 + }; + + actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); @@ -170,7 +272,42 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=2)', f x = new ndarray( 'float64', buf, sh, st, o, ord ); - actual = pop( x, 0 ); + actual = pop( x ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 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 read-only ndarrays (ndims=2, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 4 ]; + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 0 + }; + + actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); @@ -181,22 +318,55 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=2)', f 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 ); + t.end(); +}); + +tape( 'the function returns an array containing read-only ndarrays (ndims=3)', function test( t ) { + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 8, 'float64' ); + sh = [ 2, 2, 2 ]; + st = [ 4, 2, 1 ]; + o = 0; + ord = 'row-major'; + + /* + * [ + * [ + * [ 0, 1 ], + * [ 2, 3 ] + * ], + * [ + * [ 4, 5 ], + * [ 6, 7 ] + * ] + *]; + */ + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = pop( x ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); - t.deepEqual( getShape( actual[0] ), [ 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.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 read-only ndarrays (ndims=3)', function test( t ) { +tape( 'the function returns an array containing read-only ndarrays (ndims=3, options)', function test( t ) { var actual; + var opts; var buf; var ord; var sh; @@ -223,8 +393,11 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=3)', f *]; */ x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 0 + }; - actual = pop( x, 0 ); + actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); @@ -235,18 +408,10 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=3)', f 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 ); - - 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 ); + opts = { + 'dim': 2 + }; + actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); @@ -277,18 +442,7 @@ tape( 'the function returns empty read-only views if provided an empty array (nd sh = [ 2, 0 ]; x = new ndarray( 'float64', buf, sh, st, o, ord ); - 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.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' ); - t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); - - actual = pop( x, 1, false ); + actual = pop( x ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); @@ -299,28 +453,38 @@ tape( 'the function returns empty read-only views if provided an empty array (nd t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); - sh = [ 0, 4 ]; - x = new ndarray( 'float64', buf, sh, st, o, ord ); + t.end(); +}); - actual = pop( x, 0, false ); +tape( 'the function returns empty read-only views if provided an empty array (ndims=2, options)', function test( t ) { + var actual; + var opts; + var buf; + var ord; + var sh; + var st; + var o; + var x; - 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] ), [ 0, 4 ], 'returns expected value' ); - t.deepEqual( getShape( actual[1] ), [ 0, 4 ], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); - t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + buf = zeroTo( 8, 'float64' ); + st = [ 4, 1 ]; + o = 0; + ord = 'row-major'; + + sh = [ 2, 0 ]; + x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { + 'dim': 0 + }; - actual = pop( x, 1, false ); + actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); - t.deepEqual( getShape( actual[0] ), [ 0, 3 ], 'returns expected value' ); - t.deepEqual( getShape( actual[1] ), [ 0, 1 ], 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); From 9b0d519e8020f1bf2d693ffdf5dda6c0e3d5db11 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 26 Sep 2025 21:08:04 +0500 Subject: [PATCH 04/11] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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/pop/README.md | 4 ++-- lib/node_modules/@stdlib/ndarray/pop/examples/index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md index 0662d6695a77..f7a297206539 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -146,8 +146,8 @@ var x = array( buf, { }); console.log( ndarray2array( x ) ); -// Remove the last row from each matrix: -var y = pop( x, 1 ); +// Perform operation: +var y = pop( x ); console.log( ndarray2array( y[ 0 ] ) ); console.log( ndarray2array( y[ 1 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/pop/examples/index.js b/lib/node_modules/@stdlib/ndarray/pop/examples/index.js index 8d38d7f30e56..5b441aa8882e 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/pop/examples/index.js @@ -32,8 +32,8 @@ var x = array( buf, { }); console.log( ndarray2array( x ) ); -// Remove the last row from each matrix: -var y = pop( x, 1 ); +// Perform operation: +var y = pop( x ); console.log( ndarray2array( y[ 0 ] ) ); console.log( ndarray2array( y[ 1 ] ) ); From 3c440555b2a88f8b60de8b5e9b2674b53c683587 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:54:12 +0500 Subject: [PATCH 05/11] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/pop/README.md | 4 ++-- lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt | 2 +- lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/ndarray/pop/lib/index.js | 2 +- lib/node_modules/@stdlib/ndarray/pop/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/pop/package.json | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md index f7a297206539..92da46d443c7 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -20,7 +20,7 @@ limitations under the License. # pop -> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the last element(s) along a specified dimension. +> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the last element(s) along a specific dimension. @@ -42,7 +42,7 @@ var pop = require( '@stdlib/ndarray/pop' ); #### pop( x\[, options] ) -Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specified dimension. +Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specific dimension. ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt index 0158d57d0bce..b9f042ab601c 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x[, options] ) Returns an array containing a read-only truncated view of an input ndarray - and a read-only view of the last element(s) along a specified dimension. + and a read-only view of the last element(s) along a specific dimension. Parameters ---------- diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts index 842406a9287e..e8c7ba458213 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts @@ -33,7 +33,7 @@ interface Options { } /** -* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. * * @param x - input array * @param options - function options diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js index 870976083905..6388ba45c300 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. +* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. * * @module @stdlib/ndarray/pop * diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index 9e42d6cba062..f7c5710a074a 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. * * @param {ndarray} x - input array * @param {Object} options - functions options diff --git a/lib/node_modules/@stdlib/ndarray/pop/package.json b/lib/node_modules/@stdlib/ndarray/pop/package.json index 7c116aadb7df..d0e2e43d1463 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/package.json +++ b/lib/node_modules/@stdlib/ndarray/pop/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/pop", "version": "0.0.0", - "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension.", + "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 6f235fc3f0cfcbeee9e5d1057bfde3f6525273d1 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:54:53 +0500 Subject: [PATCH 06/11] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/pop/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index f7c5710a074a..23c14c8bdc8a 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -39,7 +39,7 @@ var format = require( '@stdlib/string/format' ); * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {RangeError} dimension index exceeds the number of dimensions * @throws {TypeError} first argument must be an ndarray having one or more dimensions -* @throws {TypeError} second argument must be an integer +* @throws {TypeError} options arguments must be an object * @returns {Array} a list of ndarray views * * @example From 7ebf161181e287861d0f6882e349b1341b1d127d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:56:25 +0500 Subject: [PATCH 07/11] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/pop/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index 23c14c8bdc8a..eb6a716c31e5 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -34,8 +34,8 @@ var format = require( '@stdlib/string/format' ); * Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. * * @param {ndarray} x - input array -* @param {Object} options - functions options -* @param {integer} options.dim=-1 - dimension along which to perform the operation +* @param {Object} [options] - functions options +* @param {integer} [options.dim=-1] - dimension along which to perform the operation * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {RangeError} dimension index exceeds the number of dimensions * @throws {TypeError} first argument must be an ndarray having one or more dimensions From a50d96763fd13575ed79d420dc7b4c2d6a1a6cd6 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:57:07 +0500 Subject: [PATCH 08/11] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/pop/lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index eb6a716c31e5..4ee557c7a54a 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -40,6 +40,7 @@ var format = require( '@stdlib/string/format' ); * @throws {RangeError} dimension index exceeds the number of dimensions * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {TypeError} options arguments must be an object +* @throws {TypeError} must provide valid options * @returns {Array} a list of ndarray views * * @example From 42912463e5aff136e651ffd0acc7667e439b4d99 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:19:42 +0500 Subject: [PATCH 09/11] docs: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/pop/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md index 92da46d443c7..375cf307b11f 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -79,7 +79,7 @@ The function supports the following `options`: - **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. -By default, the function performs the operation along the last dimension of the input [ndarray][@stdlib/ndarray/ctor]. To perform the operation on a desired dimension, specify the `dim` option. +By default, the function performs the operation along the last dimension of the input [ndarray][@stdlib/ndarray/ctor]. To perform the operation along a desired dimension, specify the `dim` option. ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); From 4e26b61912d421a255bd955ede628309d1ba11c4 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 29 Sep 2025 01:23:08 +0100 Subject: [PATCH 10/11] docs: revert description change --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/pop/README.md | 4 ++-- lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt | 2 +- lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/ndarray/pop/lib/index.js | 2 +- lib/node_modules/@stdlib/ndarray/pop/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/pop/package.json | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md index 375cf307b11f..80923d99ca41 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -20,7 +20,7 @@ limitations under the License. # pop -> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the last element(s) along a specific dimension. +> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the last element(s) along a specified dimension. @@ -42,7 +42,7 @@ var pop = require( '@stdlib/ndarray/pop' ); #### pop( x\[, options] ) -Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specific dimension. +Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specified dimension. ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt index b9f042ab601c..0158d57d0bce 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x[, options] ) Returns an array containing a read-only truncated view of an input ndarray - and a read-only view of the last element(s) along a specific dimension. + and a read-only view of the last element(s) along a specified dimension. Parameters ---------- diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts index e8c7ba458213..842406a9287e 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts @@ -33,7 +33,7 @@ interface Options { } /** -* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. * * @param x - input array * @param options - function options diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js index 6388ba45c300..870976083905 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. +* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. * * @module @stdlib/ndarray/pop * diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index 4ee557c7a54a..8f71f328d57b 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension. +* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension. * * @param {ndarray} x - input array * @param {Object} [options] - functions options diff --git a/lib/node_modules/@stdlib/ndarray/pop/package.json b/lib/node_modules/@stdlib/ndarray/pop/package.json index d0e2e43d1463..7c116aadb7df 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/package.json +++ b/lib/node_modules/@stdlib/ndarray/pop/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/pop", "version": "0.0.0", - "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specific dimension.", + "description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the last element(s) along a specified dimension.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 8ebf470f5b5918b59b5680b6309fd2da1bafba22 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 29 Sep 2025 01:51:38 +0100 Subject: [PATCH 11/11] chore: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/pop/README.md | 35 ++++------ .../@stdlib/ndarray/pop/docs/repl.txt | 2 +- .../@stdlib/ndarray/pop/docs/types/index.d.ts | 6 +- .../@stdlib/ndarray/pop/docs/types/test.ts | 15 +++-- .../@stdlib/ndarray/pop/examples/index.js | 9 +-- .../@stdlib/ndarray/pop/lib/main.js | 7 +- .../@stdlib/ndarray/pop/test/test.js | 66 +++++++++++++++++-- 7 files changed, 94 insertions(+), 46 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/pop/README.md b/lib/node_modules/@stdlib/ndarray/pop/README.md index 80923d99ca41..50099d440532 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/README.md +++ b/lib/node_modules/@stdlib/ndarray/pop/README.md @@ -45,16 +45,12 @@ var pop = require( '@stdlib/ndarray/pop' ); Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the last element(s) along a specified dimension. ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); -var getShape = require( '@stdlib/ndarray/shape' ); +var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -var shape = [ 3, 2 ]; -var strides = [ 2, 1 ]; -var offset = 0; - -var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], { + 'shape': [ 3, 2 ] +}); // returns var arr = ndarray2array( x ); @@ -79,19 +75,15 @@ The function supports the following `options`: - **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `-1`. -By default, the function performs the operation along the last dimension of the input [ndarray][@stdlib/ndarray/ctor]. To perform the operation along a desired dimension, specify the `dim` option. +By default, the function performs the operation along the last dimension of the input [ndarray][@stdlib/ndarray/ctor]. To perform the operation along a specific dimension, specify the `dim` option. ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); -var getShape = require( '@stdlib/ndarray/shape' ); +var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -var shape = [ 3, 2 ]; -var strides = [ 2, 1 ]; -var offset = 0; - -var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], { + 'shape': [ 3, 2 ] +}); // returns var arr = ndarray2array( x ); @@ -134,19 +126,16 @@ arr = ndarray2array( y[ 1 ] ); ```javascript var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeroTo = require( '@stdlib/array/zero-to' ); var pop = require( '@stdlib/ndarray/pop' ); -// Create a linear data buffer: -var buf = zeroTo( 27 ); - // Create an ndarray: -var x = array( buf, { +var x = array( zeroTo( 27 ), { 'shape': [ 3, 3, 3 ] }); console.log( ndarray2array( x ) ); -// Perform operation: +// Remove the last column from each matrix: var y = pop( x ); console.log( ndarray2array( y[ 0 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt index 0158d57d0bce..11f34fc19788 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/repl.txt @@ -15,7 +15,7 @@ Dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. - Default: `-1`. + Default: -1. Returns ------- diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts index 842406a9287e..62732832caad 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/index.d.ts @@ -27,7 +27,11 @@ import { ndarray } from '@stdlib/types/ndarray'; */ interface Options { /** - * Dimension along which to perform the operation. + * Dimension along which to perform the operation. Default: `-1`. + * + * ## Notes + * + * - If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. */ dim?: number; } diff --git a/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts index 40d04178ab40..a970fd5fb574 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/pop/docs/types/test.ts @@ -62,6 +62,7 @@ import pop = require( './index' ); const x = empty( 'float64', [ 2, 2 ], 'row-major' ); pop( x, '5' ); // $ExpectError + pop( x, 5 ); // $ExpectError pop( x, false ); // $ExpectError pop( x, true ); // $ExpectError pop( x, null ); // $ExpectError @@ -69,15 +70,16 @@ import pop = require( './index' ); pop( x, ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided a second argument with invalid `dim` option... +// The compiler throws an error if the function is provided a second argument with an invalid `dim` option... { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - pop( x, { 'dim':'5'} ); // $ExpectError - pop( x, { 'dim': false} ); // $ExpectError - pop( x, { 'dim': true} ); // $ExpectError - pop( x, { 'dim': null} ); // $ExpectError - pop( x, { 'dim': [ '5' ]} ); // $ExpectError + pop( x, { 'dim': '5' } ); // $ExpectError + pop( x, { 'dim': false } ); // $ExpectError + pop( x, { 'dim': true } ); // $ExpectError + pop( x, { 'dim': null } ); // $ExpectError + pop( x, { 'dim': [ '5' ] } ); // $ExpectError + pop( x, { 'dim': {} } ); // $ExpectError pop( x, { 'dim': ( x: number ): number => x } ); // $ExpectError } @@ -85,5 +87,6 @@ import pop = require( './index' ); { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + pop(); // $ExpectError pop( x, {}, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/pop/examples/index.js b/lib/node_modules/@stdlib/ndarray/pop/examples/index.js index 5b441aa8882e..eb90891a2114 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/pop/examples/index.js @@ -20,19 +20,16 @@ var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeroTo = require( '@stdlib/array/zero-to' ); var pop = require( './../lib' ); -// Create a linear data buffer: -var buf = zeroTo( 27 ); - // Create an ndarray: -var x = array( buf, { +var x = array( zeroTo( 27 ), { 'shape': [ 3, 3, 3 ] }); console.log( ndarray2array( x ) ); -// Perform operation: +// Remove the last column from each matrix: var y = pop( x ); console.log( ndarray2array( y[ 0 ] ) ); diff --git a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js index 8f71f328d57b..b111b07b9ea1 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/pop/lib/main.js @@ -38,7 +38,6 @@ var format = require( '@stdlib/string/format' ); * @param {integer} [options.dim=-1] - dimension along which to perform the operation * @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} first argument must be an ndarray having one or more dimensions * @throws {TypeError} options arguments must be an object * @throws {TypeError} must provide valid options * @returns {Array} a list of ndarray views @@ -71,12 +70,12 @@ function pop( x ) { var options; var opts; - opts = { - 'dim': -1 - }; if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); } + opts = { + 'dim': -1 + }; if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { diff --git a/lib/node_modules/@stdlib/ndarray/pop/test/test.js b/lib/node_modules/@stdlib/ndarray/pop/test/test.js index 3b37991117ab..3cc691e2e7bd 100644 --- a/lib/node_modules/@stdlib/ndarray/pop/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/pop/test/test.js @@ -237,10 +237,24 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=1, opt ord = 'row-major'; x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { 'dim': 0 }; + actual = pop( x, opts ); + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ 0, 1, 2, 3, 4 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ 5 ], 'returns expected value' ); + + opts = { + 'dim': -1 + }; actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); @@ -303,10 +317,10 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=2, opt ord = 'row-major'; x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { 'dim': 0 }; - actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); @@ -318,6 +332,20 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=2, opt t.deepEqual( ndarray2array( actual[0] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ [ 4, 5, 6, 7 ] ], 'returns expected value' ); + opts = { + 'dim': -1 + }; + actual = pop( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ 0, 1, 2 ], [ 4, 5, 6 ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ 3 ], [ 7 ] ], 'returns expected value' ); + t.end(); }); @@ -393,10 +421,10 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=3, opt *]; */ x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { 'dim': 0 }; - actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); @@ -408,6 +436,20 @@ tape( 'the function returns an array containing read-only ndarrays (ndims=3, opt t.deepEqual( ndarray2array( actual[0] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' ); + opts = { + 'dim': -2 + }; + actual = pop( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 1, 2 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 1, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [ [ [ 0, 1 ] ], [ [ 4, 5 ] ] ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [ [ [ 2, 3 ] ], [ [ 6, 7 ] ] ], 'returns expected value' ); + opts = { 'dim': 2 }; @@ -435,11 +477,11 @@ tape( 'the function returns empty read-only views if provided an empty array (nd var x; buf = zeroTo( 8, 'float64' ); + sh = [ 2, 0 ]; st = [ 4, 1 ]; o = 0; ord = 'row-major'; - sh = [ 2, 0 ]; x = new ndarray( 'float64', buf, sh, st, o, ord ); actual = pop( x ); @@ -467,16 +509,16 @@ tape( 'the function returns empty read-only views if provided an empty array (nd var x; buf = zeroTo( 8, 'float64' ); + sh = [ 2, 0 ]; st = [ 4, 1 ]; o = 0; ord = 'row-major'; - sh = [ 2, 0 ]; x = new ndarray( 'float64', buf, sh, st, o, ord ); + opts = { 'dim': 0 }; - actual = pop( x, opts ); t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); @@ -488,5 +530,19 @@ tape( 'the function returns empty read-only views if provided an empty array (nd t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + opts = { + 'dim': -1 + }; + actual = pop( x, opts ); + + t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' ); + t.deepEqual( getShape( actual[0] ), [ 2, 0 ], 'returns expected value' ); + t.deepEqual( getShape( actual[1] ), [ 2, 0 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' ); + t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' ); + t.end(); });