From 5debc3970188469661f1524909e9b9724b749f0a Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Mon, 15 Dec 2025 16:54:51 +0530 Subject: [PATCH 1/6] feat: implement @stdlib/blas/ext/base/ndarray/drev - Add ndarray wrapper for drev function - Implement comprehensive test suite with stride/offset tests - Add documentation (README, REPL, TypeScript types) - Add examples and performance benchmarks - Follow stdlib conventions for BLAS operations --- .../blas/ext/base/ndarray/drev/README.md | 112 ++++++++++ .../base/ndarray/drev/benchmark/benchmark.js | 100 +++++++++ .../blas/ext/base/ndarray/drev/docs/repl.txt | 34 +++ .../base/ndarray/drev/docs/types/index.d.ts | 46 ++++ .../ext/base/ndarray/drev/docs/types/test.ts | 56 +++++ .../ext/base/ndarray/drev/examples/index.js | 33 +++ .../blas/ext/base/ndarray/drev/lib/index.js | 45 ++++ .../blas/ext/base/ndarray/drev/lib/main.js | 56 +++++ .../blas/ext/base/ndarray/drev/package.json | 68 ++++++ .../blas/ext/base/ndarray/drev/test/test.js | 206 ++++++++++++++++++ 10 files changed, 756 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md new file mode 100644 index 000000000000..0fd6e5bbe43e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md @@ -0,0 +1,112 @@ + + +# drev + +> Reverse the elements of a one-dimensional double-precision floating-point ndarray in-place. + +
+ +
+ + + +
+ +## Usage + +```javascript +var drev = require( '@stdlib/blas/ext/base/ndarray/drev' ); +``` + +#### drev( arrays ) + +Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +drev( x ); +// x => [ 3.0, 2.0, 1.0 ] +``` + +The function has the following parameters: + +- **x**: input ndarray. + +
+ + + +
+ +## Notes + +- The function **mutates** the input ndarray. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var drev = require( '@stdlib/blas/ext/base/ndarray/drev' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +drev( x ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js new file mode 100644 index 000000000000..eab40e6b663d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js @@ -0,0 +1,100 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var drev = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + drev( x ); + if ( xbuf[ 0 ] !== xbuf[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( xbuf[ 0 ] !== xbuf[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg + ':len=' + len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt new file mode 100644 index 000000000000..fc07b654a603 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( x ) + Reverses the elements of a one-dimensional double-precision floating-point + ndarray in-place. + + The function mutates the input ndarray. + + Parameters + ---------- + x: ndarray + Input ndarray. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0 ] ); + > var dt = 'float64'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( x ) + + > {{alias:@stdlib/ndarray/to-array}}( x ) + [ 3.0, 2.0, 1.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts new file mode 100644 index 000000000000..96b41f30b234 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @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 { float64ndarray } from '@stdlib/types/ndarray'; + +/** +* Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place. +* +* @param x - input ndarray +* @returns input ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* drev( x ); +* // x => [ 3.0, 2.0, 1.0 ] +*/ +declare function drev( x: float64ndarray ): float64ndarray; + + +// EXPORTS // + +export = drev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts new file mode 100644 index 000000000000..f6e74875a2c9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @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 drev = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const Float64Array = require( '@stdlib/array/float64' ); + const ndarray = require( '@stdlib/ndarray/base/ctor' ); + + const xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + drev( x ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing an ndarray... +{ + drev( 123 ); // $ExpectError + drev( true ); // $ExpectError + drev( false ); // $ExpectError + drev( null ); // $ExpectError + drev( undefined ); // $ExpectError + drev( {} ); // $ExpectError + drev( [ 123 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const Float64Array = require( '@stdlib/array/float64' ); + const ndarray = require( '@stdlib/ndarray/base/ctor' ); + + const xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + + drev(); // $ExpectError + drev( x, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js new file mode 100644 index 000000000000..e9907ca8b709 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var drev = require( './../lib' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +drev( x ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js new file mode 100644 index 000000000000..3300dee29272 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js @@ -0,0 +1,45 @@ +/** +* @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'; + +/** +* Reverse the elements of a one-dimensional double-precision floating-point ndarray in-place. +* +* @module @stdlib/blas/ext/base/ndarray/drev +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var drev = require( '@stdlib/blas/ext/base/ndarray/drev' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* drev( x ); +* // x => [ 3.0, 2.0, 1.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js new file mode 100644 index 000000000000..22893dbb3269 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/drev' ).ndarray; + + +// MAIN // + +/** +* Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place. +* +* @param {ndarray} x - input ndarray +* @returns {ndarray} input ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* drev( x ); +* // x => [ 3.0, 2.0, 1.0 ] +*/ +function drev( x ) { + strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = drev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/package.json new file mode 100644 index 000000000000..d307743bac0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/drev", + "version": "0.0.0", + "description": "Reverse the elements of a one-dimensional double-precision floating-point ndarray in-place.", + "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", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "reverse", + "rev", + "flip", + "ndarray", + "float64", + "double", + "float64array", + "in-place" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js new file mode 100644 index 000000000000..faa1e4ebf2af --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js @@ -0,0 +1,206 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var drev = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float64Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( drev.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function reverses the elements of a one-dimensional ndarray in-place', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + expected = new Float64Array( [ 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + + drev( vector( x, 5, 1, 0 ) ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ -1.0, -2.0, -3.0 ] ); + expected = new Float64Array( [ -3.0, -2.0, -1.0 ] ); + + drev( vector( x, 3, 1, 0 ) ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var x; + var y; + + x = vector( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 3, 1, 0 ); + y = drev( x ); + + t.strictEqual( y, x, 'returns input ndarray' ); + t.end(); +}); + +tape( 'if provided an empty ndarray, the function leaves the ndarray unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [] ); + expected = new Float64Array( [] ); + + drev( vector( x, 0, 1, 0 ) ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an ndarray containing a single element, the function leaves the ndarray unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 1.0 ] ); + expected = new Float64Array( [ 1.0 ] ); + + drev( vector( x, 1, 1, 0 ) ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0, + 7.0, // 3 + 8.0 + ]); + expected = new Float64Array([ + 7.0, // reversed: 3 -> 0 + 2.0, + 5.0, // reversed: 2 -> 1 + 4.0, + 3.0, // reversed: 1 -> 2 + 6.0, + 1.0, // reversed: 0 -> 3 + 8.0 + ]); + + drev( vector( x, 4, 2, 0 ) ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, // 3 + 2.0, + 3.0, // 2 + 4.0, + 5.0, // 1 + 6.0, + 7.0, // 0 + 8.0 + ]); + expected = new Float64Array([ + 7.0, // reversed: 0 -> 3 + 2.0, + 5.0, // reversed: 1 -> 2 + 4.0, + 3.0, // reversed: 2 -> 1 + 6.0, + 1.0, // reversed: 3 -> 0 + 8.0 + ]); + + drev( vector( x, 4, -2, 6 ) ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0, // 2 + 7.0, + 8.0 // 3 + ]); + expected = new Float64Array([ + 1.0, + 8.0, // reversed: 3 -> 0 + 3.0, + 6.0, // reversed: 2 -> 1 + 5.0, + 4.0, // reversed: 1 -> 2 + 7.0, + 2.0 // reversed: 0 -> 3 + ]); + + drev( vector( x, 4, 2, 1 ) ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); From d917005672288502f419101a4781e505dfb16cbc Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Mon, 15 Dec 2025 17:11:09 +0530 Subject: [PATCH 2/6] imports moved to the top --- .../ext/base/ndarray/drev/docs/types/test.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts index f6e74875a2c9..2b31dad7f9ce 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts @@ -16,6 +16,9 @@ * limitations under the License. */ +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); import drev = require( './index' ); @@ -23,34 +26,32 @@ import drev = require( './index' ); // The function returns an ndarray... { - const Float64Array = require( '@stdlib/array/float64' ); - const ndarray = require( '@stdlib/ndarray/base/ctor' ); - - const xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - const x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + const x = zeros( [ 3 ], { + 'dtype': 'float64' + }); drev( x ); // $ExpectType float64ndarray } -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing an ndarray... +// The compiler throws an error if the function is provided a first argument which is not an ndarray... { - drev( 123 ); // $ExpectError + drev( '10' ); // $ExpectError + drev( 10 ); // $ExpectError drev( true ); // $ExpectError drev( false ); // $ExpectError drev( null ); // $ExpectError drev( undefined ); // $ExpectError + drev( [] ); // $ExpectError drev( {} ); // $ExpectError - drev( [ 123 ] ); // $ExpectError + drev( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - const Float64Array = require( '@stdlib/array/float64' ); - const ndarray = require( '@stdlib/ndarray/base/ctor' ); - - const xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - const x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + const x = zeros( [ 3 ], { + 'dtype': 'float64' + }); drev(); // $ExpectError - drev( x, 123 ); // $ExpectError + drev( x, {} ); // $ExpectError } From 7c8432efd1a697e16a1f54a487d22da8bc601bca Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 18:35:40 +0530 Subject: [PATCH 3/6] docs: simplify REPL example to use ndarray instance notation --- .../@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt index fc07b654a603..659fb66e7f77 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt @@ -25,9 +25,7 @@ > var ord = 'row-major'; > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); > {{alias}}( x ) - - > {{alias:@stdlib/ndarray/to-array}}( x ) - [ 3.0, 2.0, 1.0 ] + [ 3.0, 2.0, 1.0 ] See Also -------- From b9e2010fc0f5ff282aae1cac1e1d202e10252811 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sun, 21 Dec 2025 12:30:39 +0530 Subject: [PATCH 4/6] fix: refactor drev to use arrays API pattern --- .../blas/ext/base/ndarray/drev/README.md | 20 +++++--------- .../base/ndarray/drev/benchmark/benchmark.js | 2 +- .../blas/ext/base/ndarray/drev/docs/repl.txt | 21 ++++++--------- .../base/ndarray/drev/docs/types/index.d.ts | 6 ++--- .../ext/base/ndarray/drev/docs/types/test.ts | 26 +++++++------------ .../ext/base/ndarray/drev/examples/index.js | 2 +- .../blas/ext/base/ndarray/drev/lib/index.js | 2 +- .../blas/ext/base/ndarray/drev/lib/main.js | 7 ++--- .../blas/ext/base/ndarray/drev/test/test.js | 16 ++++++------ 9 files changed, 42 insertions(+), 60 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md index 0fd6e5bbe43e..bcf62819c260 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md @@ -43,32 +43,26 @@ Reverses the elements of a one-dimensional double-precision floating-point ndarr ```javascript var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); -drev( x ); +drev( [ x ] ); // x => [ 3.0, 2.0, 1.0 ] + +var arr = ndarray2array( x ); +// returns [ 3.0, 2.0, 1.0 ] ``` The function has the following parameters: -- **x**: input ndarray. +- **arrays**: array-like object containing a single one-dimensional input ndarray. -
- -## Notes - -- The function **mutates** the input ndarray. - -
- - -
## Examples @@ -87,7 +81,7 @@ var xbuf = discreteUniform( 10, -50, 50, { var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -drev( x ); +drev( [ x ] ); console.log( ndarray2array( x ) ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js index eab40e6b663d..930053ec62a8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js @@ -58,7 +58,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - drev( x ); + drev( [ x ] ); if ( xbuf[ 0 ] !== xbuf[ 0 ] ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt index 659fb66e7f77..a4a2f7c26c66 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/repl.txt @@ -1,14 +1,12 @@ -{{alias}}( x ) +{{alias}}( arrays ) Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place. - The function mutates the input ndarray. - Parameters ---------- - x: ndarray - Input ndarray. + arrays: ArrayLikeObject + Array-like object containing a single one-dimensional input ndarray. Returns ------- @@ -18,14 +16,11 @@ Examples -------- > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0 ] ); - > var dt = 'float64'; - > var sh = [ xbuf.length ]; - > var sx = [ 1 ]; - > var ox = 0; - > var ord = 'row-major'; - > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); - > {{alias}}( x ) - [ 3.0, 2.0, 1.0 ] + > var x = {{alias:@stdlib/ndarray/base/ctor}}( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + > {{alias}}( [ x ] ) + + > var data = x.data + [ 3.0, 2.0, 1.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts index 96b41f30b234..01cae4c4e758 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/index.d.ts @@ -25,7 +25,7 @@ import { float64ndarray } from '@stdlib/types/ndarray'; /** * Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place. * -* @param x - input ndarray +* @param arrays - array-like object containing a single one-dimensional input ndarray * @returns input ndarray * * @example @@ -35,10 +35,10 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); * -* drev( x ); +* drev( [ x ] ); * // x => [ 3.0, 2.0, 1.0 ] */ -declare function drev( x: float64ndarray ): float64ndarray; +declare function drev( arrays: [ float64ndarray ] ): float64ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts index 2b31dad7f9ce..6e227d9ada37 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts @@ -16,9 +16,7 @@ * limitations under the License. */ -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray/zeros' ); +import zeros = require( '@stdlib/ndarray/base/zeros' ); import drev = require( './index' ); @@ -26,32 +24,26 @@ import drev = require( './index' ); // The function returns an ndarray... { - const x = zeros( [ 3 ], { - 'dtype': 'float64' - }); - - drev( x ); // $ExpectType float64ndarray + const x = zeros( 'float64', [ 3 ], 'row-major' ); + drev( [ x ] ); // $ExpectType float64ndarray } -// The compiler throws an error if the function is provided a first argument which is not an ndarray... +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarrays... { - drev( '10' ); // $ExpectError - drev( 10 ); // $ExpectError + drev( 123 ); // $ExpectError drev( true ); // $ExpectError drev( false ); // $ExpectError drev( null ); // $ExpectError drev( undefined ); // $ExpectError - drev( [] ); // $ExpectError + drev( '5' ); // $ExpectError + drev( [ '1', '2' ] ); // $ExpectError drev( {} ); // $ExpectError drev( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = zeros( [ 3 ], { - 'dtype': 'float64' - }); - + const x = zeros( 'float64', [ 3 ], 'row-major' ); drev(); // $ExpectError - drev( x, {} ); // $ExpectError + drev( [ x ], 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js index e9907ca8b709..2b6fa317fc31 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/examples/index.js @@ -29,5 +29,5 @@ var xbuf = discreteUniform( 10, -50, 50, { var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -drev( x ); +drev( [ x ] ); console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js index 3300dee29272..2e55128dc396 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js @@ -31,7 +31,7 @@ * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); * -* drev( x ); +* drev( [ x ] ); * // x => [ 3.0, 2.0, 1.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js index 22893dbb3269..a1f3b723f347 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js @@ -32,7 +32,7 @@ var strided = require( '@stdlib/blas/ext/base/drev' ).ndarray; /** * Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place. * -* @param {ndarray} x - input ndarray +* @param {ArrayLikeObject} arrays - array-like object containing a single one-dimensional input ndarray * @returns {ndarray} input ndarray * * @example @@ -42,10 +42,11 @@ var strided = require( '@stdlib/blas/ext/base/drev' ).ndarray; * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); * -* drev( x ); +* drev( [ x ] ); * // x => [ 3.0, 2.0, 1.0 ] */ -function drev( x ) { +function drev( arrays ) { + var x = arrays[ 0 ]; strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js index faa1e4ebf2af..c65dd5dc3504 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js @@ -63,13 +63,13 @@ tape( 'the function reverses the elements of a one-dimensional ndarray in-place' x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); expected = new Float64Array( [ 5.0, 4.0, 3.0, 2.0, 1.0 ] ); - drev( vector( x, 5, 1, 0 ) ); + drev( [ vector( x, 5, 1, 0 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); x = new Float64Array( [ -1.0, -2.0, -3.0 ] ); expected = new Float64Array( [ -3.0, -2.0, -1.0 ] ); - drev( vector( x, 3, 1, 0 ) ); + drev( [ vector( x, 3, 1, 0 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -80,7 +80,7 @@ tape( 'the function returns the input ndarray', function test( t ) { var y; x = vector( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 3, 1, 0 ); - y = drev( x ); + y = drev( [ x ] ); t.strictEqual( y, x, 'returns input ndarray' ); t.end(); @@ -93,7 +93,7 @@ tape( 'if provided an empty ndarray, the function leaves the ndarray unchanged', x = new Float64Array( [] ); expected = new Float64Array( [] ); - drev( vector( x, 0, 1, 0 ) ); + drev( [ vector( x, 0, 1, 0 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -106,7 +106,7 @@ tape( 'if provided an ndarray containing a single element, the function leaves t x = new Float64Array( [ 1.0 ] ); expected = new Float64Array( [ 1.0 ] ); - drev( vector( x, 1, 1, 0 ) ); + drev( [ vector( x, 1, 1, 0 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -137,7 +137,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 8.0 ]); - drev( vector( x, 4, 2, 0 ) ); + drev( [ vector( x, 4, 2, 0 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -168,7 +168,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 8.0 ]); - drev( vector( x, 4, -2, 6 ) ); + drev( [ vector( x, 4, -2, 6 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -199,7 +199,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 2.0 // reversed: 0 -> 3 ]); - drev( vector( x, 4, 2, 1 ) ); + drev( [ vector( x, 4, 2, 1 ) ] ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); From 2d2e698112aa6f4de5749c7177e5f0dcd551f2a0 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Mon, 22 Dec 2025 07:54:57 +0530 Subject: [PATCH 5/6] fix: drev benchmark - use @stdlib/string/format per RFC #8647 --- .../@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js index 930053ec62a8..a2ce822146aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js @@ -24,6 +24,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var drev = require( './../lib' ); From 675c2505a68b284a37431def05492642fa481328 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Mon, 22 Dec 2025 08:00:56 +0530 Subject: [PATCH 6/6] fix: drev benchmark - use @stdlib/string/format per RFC #8647 --- .../@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js index a2ce822146aa..fec4280d6b9a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/benchmark/benchmark.js @@ -94,7 +94,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg + ':len=' + len, f ); + bench( format( '%s:len=%d', pkg, len ), f ); } }