From db33d47877ba78570cd012fd7264c96c277b1b87 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Thu, 18 Dec 2025 19:58:26 +0530 Subject: [PATCH 1/6] feat: add blas/ext/base/ndarray/dapx --- .../blas/ext/base/ndarray/dapx/README.md | 130 ++++++++++++++++ .../base/ndarray/dapx/benchmark/benchmark.js | 101 ++++++++++++ .../blas/ext/base/ndarray/dapx/docs/repl.txt | 29 ++++ .../base/ndarray/dapx/docs/types/index.d.ts | 49 ++++++ .../ext/base/ndarray/dapx/docs/types/test.ts | 62 ++++++++ .../ext/base/ndarray/dapx/examples/index.js | 34 ++++ .../blas/ext/base/ndarray/dapx/lib/index.js | 47 ++++++ .../blas/ext/base/ndarray/dapx/lib/main.js | 72 +++++++++ .../blas/ext/base/ndarray/dapx/package.json | 76 +++++++++ .../blas/ext/base/ndarray/dapx/test/test.js | 145 ++++++++++++++++++ 10 files changed, 745 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md new file mode 100644 index 000000000000..0c12d760def5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md @@ -0,0 +1,130 @@ + + +# dapx + +> Add a scalar constant to each element in a double-precision floating-point ndarray. + +
+ +## Usage + +```javascript +var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); +``` + +#### dapx( x, alpha ) + +Adds a scalar constant to each element in a double-precision floating-point ndarray. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +dapx( x, 5.0 ); + +var y = x.data; +// returns [ 6.0, 7.0, 8.0, 9.0 ] +``` + +The function has the following parameters: + +- **x**: input ndarray. +- **alpha**: scalar constant. + +Note that indexing is relative to the first index. To introduce an offset, use [`ndarray`][@stdlib/ndarray/ctor] view creation. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +// Initial array: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Create an ndarray view: +var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); + +dapx( x, 5.0 ); + +var y = x.data; +// returns [ 1.0, 2.0, 8.0, 9.0, 10.0 ] +``` + +
+ + + +
+ +## Notes + +- The function **mutates** the input ndarray. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); + +var xbuf = discreteUniform( 10, 0, 100, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); + +console.log( x.data ); + +dapx( x, 5.0 ); + +console.log( x.data ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js new file mode 100644 index 000000000000..560186ffd56c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js @@ -0,0 +1,101 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var pkg = require( './../package.json' ).name; +var dapx = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + + x = new ndarray( 'float64', discreteUniform( len, -100, 100, { + 'dtype': 'float64' + }), [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dapx( x, 5.0 ); + if ( isnanf( z.data[ i % len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( z.data[ i % len ] ) ) { + 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/dapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt new file mode 100644 index 000000000000..068a19cc0b21 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt @@ -0,0 +1,29 @@ +{{alias}}( x, alpha ) + Adds a scalar constant to each element in a double-precision floating- + point ndarray. + + Parameters + ---------- + x: float64ndarray + Input ndarray. + + alpha: number + Scalar constant. + + Returns + ------- + out: float64ndarray + Input ndarray. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + > {{alias}}( x, 5.0 ) + + > x.data + [ 6.0, 7.0, 8.0, 9.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts new file mode 100644 index 000000000000..1b2d43c35a91 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts @@ -0,0 +1,49 @@ +/* +* @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'; + +/** +* Adds a scalar constant to each element in a double-precision floating-point ndarray. +* +* @param x - input ndarray +* @param alpha - scalar constant +* @returns input ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* dapx( x, 5.0 ); +* +* var y = x.data; +* // returns [ 6.0, 7.0, 8.0, 9.0 ] +*/ +declare function dapx( x: float64ndarray, alpha: number ): float64ndarray; + + +// EXPORTS // + +export = dapx; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts new file mode 100644 index 000000000000..2ccdf2db6110 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.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. +*/ + +import dapx = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x: any = null; + dapx( x, 5.0 ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + dapx( 123, 5.0 ); // $ExpectError + dapx( true, 5.0 ); // $ExpectError + dapx( false, 5.0 ); // $ExpectError + dapx( null, 5.0 ); // $ExpectError + dapx( undefined, 5.0 ); // $ExpectError + dapx( '5', 5.0 ); // $ExpectError + dapx( [ '1', '2' ], 5.0 ); // $ExpectError + dapx( {}, 5.0 ); // $ExpectError + dapx( ( x: number ): number => x, 5.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x: any = null; + dapx( x, '5' ); // $ExpectError + dapx( x, true ); // $ExpectError + dapx( x, false ); // $ExpectError + dapx( x, null ); // $ExpectError + dapx( x, undefined ); // $ExpectError + dapx( x, [ '1' ] ); // $ExpectError + dapx( x, {} ); // $ExpectError + dapx( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x: any = null; + dapx(); // $ExpectError + dapx( x ); // $ExpectError + dapx( x, 5.0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js new file mode 100644 index 000000000000..e20b135a6b1e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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/ctor' ); +var dapx = require( './../lib' ); + +var xbuf = discreteUniform( 10, 0, 100, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); + +console.log( x.data ); + +dapx( x, 5.0 ); + +console.log( x.data ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js new file mode 100644 index 000000000000..c5acac898bba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js @@ -0,0 +1,47 @@ +/** +* @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'; + +/** +* Add a scalar constant to each element in a double-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/dapx +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* dapx( x, 5.0 ); +* +* var y = x.data; +* // returns [ 6.0, 7.0, 8.0, 9.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js new file mode 100644 index 000000000000..30369236655c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js @@ -0,0 +1,72 @@ +/** +* @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 strided = require( '@stdlib/blas/ext/base/dapx' ).ndarray; +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); + + +// MAIN // + +/** +* Adds a scalar constant to each element in a double-precision floating-point ndarray. +* +* @param {float64ndarray} x - input ndarray +* @param {number} alpha - scalar constant +* @returns {float64ndarray} input ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* dapx( x, 5.0 ); +* +* var y = x.data; +* // returns [ 6.0, 7.0, 8.0, 9.0 ] +*/ +function ndapx( x, alpha ) { + var buf; + var sx; + var ox; + var N; + + N = numelDimension( x, 0 ); + if ( N <= 0 ) { + return x; + } + buf = getData( x ); + sx = getStride( x, 0 ); + ox = getOffset( x ); + + strided( N, alpha, buf, sx, ox ); + return x; +} + + +// EXPORTS // + +module.exports = ndapx; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/package.json new file mode 100644 index 000000000000..07bfcd990e93 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/dapx", + "version": "0.0.0", + "description": "Add a scalar constant to each element in a double-precision floating-point ndarray.", + "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", + "level 1", + "dapx", + "linear", + "algebra", + "subroutines", + "ndarray", + "vector", + "array", + "multidimensional", + "add", + "constant", + "plus", + "increment", + "augment", + "float64", + "double", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js new file mode 100644 index 000000000000..ed1dd1626ede --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js @@ -0,0 +1,145 @@ +/** +* @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/ctor' ); +var dapx = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dapx, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds a scalar constant to each element in a double-precision floating-point ndarray', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0 ] ); + + dapx( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var xbuf; + var x; + var y; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + y = dapx( x, 5.0 ); + + t.strictEqual( y, x, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with negative strides', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ -1 ], 3, 'row-major' ); + + expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0 ] ); + + dapx( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with an offset', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); + + expected = new Float64Array( [ 1.0, 2.0, 8.0, 9.0, 10.0 ] ); + + dapx( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports zero-length ndarrays', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float64Array( [] ); + x = new ndarray( 'float64', xbuf, [ 0 ], [ 1 ], 0, 'row-major' ); + + expected = new Float64Array( [] ); + + dapx( x, 5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports adding zero', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dapx( x, 0.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative constants', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + expected = new Float64Array( [ -4.0, -3.0, -2.0, -1.0 ] ); + + dapx( x, -5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); From b4175e20fafa22c4ca934c9f677d28772d3d61f4 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Thu, 18 Dec 2025 20:04:36 +0530 Subject: [PATCH 2/6] fix: rename function from ndapx to dapx for consistency --- .../@stdlib/blas/ext/base/ndarray/dapx/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js index 30369236655c..0ec2aec7cb9d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js @@ -48,7 +48,7 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * var y = x.data; * // returns [ 6.0, 7.0, 8.0, 9.0 ] */ -function ndapx( x, alpha ) { +function dapx( x, alpha ) { var buf; var sx; var ox; @@ -69,4 +69,4 @@ function ndapx( x, alpha ) { // EXPORTS // -module.exports = ndapx; +module.exports = dapx; From 25c54a96995112da1884ddc32ebac61bfa705d3e Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 18:21:43 +0530 Subject: [PATCH 3/6] docs: update return annotations to use ndarray instance notation --- .../@stdlib/blas/ext/base/ndarray/dapx/README.md | 12 ++++-------- .../@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt | 4 +--- .../blas/ext/base/ndarray/dapx/docs/types/index.d.ts | 6 ++---- .../@stdlib/blas/ext/base/ndarray/dapx/lib/index.js | 6 ++---- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md index 0c12d760def5..8e3ebe52e833 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md @@ -41,10 +41,8 @@ var ndarray = require( '@stdlib/ndarray/ctor' ); var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -dapx( x, 5.0 ); - -var y = x.data; -// returns [ 6.0, 7.0, 8.0, 9.0 ] +var out = dapx( x, 5.0 ); +// returns [ 6.0, 7.0, 8.0, 9.0 ] ``` The function has the following parameters: @@ -64,10 +62,8 @@ var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); // Create an ndarray view: var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); -dapx( x, 5.0 ); - -var y = x.data; -// returns [ 1.0, 2.0, 8.0, 9.0, 10.0 ] +var out = dapx( x, 5.0 ); +// returns [ 8.0, 9.0, 10.0 ] ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt index 068a19cc0b21..ae2c39b7ad3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt @@ -20,9 +20,7 @@ > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); > {{alias}}( x, 5.0 ) - - > x.data - [ 6.0, 7.0, 8.0, 9.0 ] + [ 6.0, 7.0, 8.0, 9.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts index 1b2d43c35a91..750650badd16 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts @@ -36,10 +36,8 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* dapx( x, 5.0 ); -* -* var y = x.data; -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* var out = dapx( x, 5.0 ); +* // returns [ 6.0, 7.0, 8.0, 9.0 ] */ declare function dapx( x: float64ndarray, alpha: number ): float64ndarray; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js index c5acac898bba..8bb4d737b9ff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js @@ -31,10 +31,8 @@ * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* dapx( x, 5.0 ); -* -* var y = x.data; -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* var out = dapx( x, 5.0 ); +* // returns [ 6.0, 7.0, 8.0, 9.0 ] */ // MODULES // From 15d54c7f766fa5e9d415c0795fc43c90f452ddb9 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 20 Dec 2025 10:35:49 +0530 Subject: [PATCH 4/6] fix: update dapx ndarray API following dcusum pattern --- .../blas/ext/base/ndarray/dapx/README.md | 33 +++++++++--- .../base/ndarray/dapx/benchmark/benchmark.js | 13 +++-- .../blas/ext/base/ndarray/dapx/docs/repl.txt | 18 +++---- .../base/ndarray/dapx/docs/types/index.d.ts | 14 +++-- .../ext/base/ndarray/dapx/docs/types/test.ts | 53 +++++++++---------- .../ext/base/ndarray/dapx/examples/index.js | 7 ++- .../blas/ext/base/ndarray/dapx/lib/main.js | 22 +++++--- .../blas/ext/base/ndarray/dapx/test/test.js | 48 ++++++++++++++--- 8 files changed, 140 insertions(+), 68 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md index 8e3ebe52e833..45011d9ab203 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md @@ -30,31 +30,39 @@ limitations under the License. var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); ``` -#### dapx( x, alpha ) +#### dapx( arrays ) Adds a scalar constant to each element in a double-precision floating-point ndarray. ```javascript var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -var out = dapx( x, 5.0 ); -// returns [ 6.0, 7.0, 8.0, 9.0 ] +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +var out = dapx( [ x, alpha ] ); +// returns + +var bool = ( out === x ); +// returns true ``` The function has the following parameters: -- **x**: input ndarray. -- **alpha**: scalar constant. +- **arrays**: array-like object containing an input ndarray and a zero-dimensional ndarray containing the scalar constant. Note that indexing is relative to the first index. To introduce an offset, use [`ndarray`][@stdlib/ndarray/ctor] view creation. ```javascript var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); // Initial array: var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); @@ -62,8 +70,12 @@ var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); // Create an ndarray view: var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); -var out = dapx( x, 5.0 ); -// returns [ 8.0, 9.0, 10.0 ] +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +var out = dapx( [ x, alpha ] ); +// returns ``` @@ -89,6 +101,7 @@ var out = dapx( x, 5.0 ); ```javascript var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); var xbuf = discreteUniform( 10, 0, 100, { @@ -98,7 +111,11 @@ var x = new ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); console.log( x.data ); -dapx( x, 5.0 ); +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +dapx( [ x, alpha ] ); console.log( x.data ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js index 560186ffd56c..c42df3ef7d05 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js @@ -25,6 +25,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var pkg = require( './../package.json' ).name; var dapx = require( './../lib' ); @@ -39,11 +40,17 @@ var dapx = require( './../lib' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { + var alpha; + var xbuf; var x; - x = new ndarray( 'float64', discreteUniform( len, -100, 100, { + xbuf = discreteUniform( len, -100, 100, { 'dtype': 'float64' - }), [ len ], [ 1 ], 0, 'row-major' ); + }); + x = new ndarray( 'float64', xbuf, [ len ], [ 1 ], 0, 'row-major' ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); return benchmark; @@ -59,7 +66,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - z = dapx( x, 5.0 ); + z = dapx( [ x, alpha ] ); if ( isnanf( z.data[ i % len ] ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt index ae2c39b7ad3e..46c232b6f2ea 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt @@ -1,26 +1,26 @@ -{{alias}}( x, alpha ) +{{alias}}( arrays ) + Adds a scalar constant to each element in a double-precision floating- point ndarray. Parameters ---------- - x: float64ndarray - Input ndarray. - - alpha: number - Scalar constant. + arrays: ArrayLikeObject + Array-like object containing an input ndarray and a zero-dimensional + ndarray containing the scalar constant. Returns ------- - out: float64ndarray + out: ndarray Input ndarray. Examples -------- > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - > {{alias}}( x, 5.0 ) - [ 6.0, 7.0, 8.0, 9.0 ] + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, 'float64', 'row-major' ); + > {{alias}}( [ x, alpha ] ) + See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts index 750650badd16..3a2693bbe459 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/index.d.ts @@ -25,21 +25,25 @@ import { float64ndarray } from '@stdlib/types/ndarray'; /** * Adds a scalar constant to each element in a double-precision floating-point ndarray. * -* @param x - input ndarray -* @param alpha - scalar constant +* @param arrays - array-like object containing an input ndarray and a zero-dimensional ndarray containing the scalar constant * @returns input ndarray * * @example * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var out = dapx( x, 5.0 ); -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var out = dapx( [ x, alpha ] ); +* // returns */ -declare function dapx( x: float64ndarray, alpha: number ): float64ndarray; +declare function dapx( arrays: ArrayLike ): float64ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts index 2ccdf2db6110..635361218eb9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts @@ -16,6 +16,7 @@ * limitations under the License. */ +import zeros = require( '@stdlib/ndarray/zeros' ); import dapx = require( './index' ); @@ -23,40 +24,38 @@ import dapx = require( './index' ); // The function returns an ndarray... { - const x: any = null; - dapx( x, 5.0 ); // $ExpectType float64ndarray -} + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const alpha = zeros( [], { + 'dtype': 'float64' + }); -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - dapx( 123, 5.0 ); // $ExpectError - dapx( true, 5.0 ); // $ExpectError - dapx( false, 5.0 ); // $ExpectError - dapx( null, 5.0 ); // $ExpectError - dapx( undefined, 5.0 ); // $ExpectError - dapx( '5', 5.0 ); // $ExpectError - dapx( [ '1', '2' ], 5.0 ); // $ExpectError - dapx( {}, 5.0 ); // $ExpectError - dapx( ( x: number ): number => x, 5.0 ); // $ExpectError + dapx( [ x, alpha ] ); // $ExpectType float64ndarray } -// The compiler throws an error if the function is provided a second argument which is not a number... +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... { - const x: any = null; - dapx( x, '5' ); // $ExpectError - dapx( x, true ); // $ExpectError - dapx( x, false ); // $ExpectError - dapx( x, null ); // $ExpectError - dapx( x, undefined ); // $ExpectError - dapx( x, [ '1' ] ); // $ExpectError - dapx( x, {} ); // $ExpectError - dapx( x, ( x: number ): number => x ); // $ExpectError + dapx( '10' ); // $ExpectError + dapx( 10 ); // $ExpectError + dapx( true ); // $ExpectError + dapx( false ); // $ExpectError + dapx( null ); // $ExpectError + dapx( undefined ); // $ExpectError + dapx( [] ); // $ExpectError + dapx( {} ); // $ExpectError + dapx( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x: any = null; + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const alpha = zeros( [], { + 'dtype': 'float64' + }); + dapx(); // $ExpectError - dapx( x ); // $ExpectError - dapx( x, 5.0, 10 ); // $ExpectError + dapx( [ x, alpha ], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js index e20b135a6b1e..6e2ee86498c8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js @@ -20,6 +20,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var dapx = require( './../lib' ); var xbuf = discreteUniform( 10, 0, 100, { @@ -29,6 +30,10 @@ var x = new ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); console.log( x.data ); -dapx( x, 5.0 ); +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +dapx( [ x, alpha ] ); console.log( x.data ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js index 0ec2aec7cb9d..3f9ab613f504 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js @@ -25,6 +25,7 @@ var strided = require( '@stdlib/blas/ext/base/dapx' ).ndarray; var getStride = require( '@stdlib/ndarray/base/stride' ); var getOffset = require( '@stdlib/ndarray/base/offset' ); var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); // MAIN // @@ -32,27 +33,32 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); /** * Adds a scalar constant to each element in a double-precision floating-point ndarray. * -* @param {float64ndarray} x - input ndarray -* @param {number} alpha - scalar constant -* @returns {float64ndarray} input ndarray +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a zero-dimensional ndarray containing the scalar constant +* @returns {Object} input ndarray * * @example * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* dapx( x, 5.0 ); +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); * -* var y = x.data; -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* dapx( [ x, alpha ] ); +* // returns */ -function dapx( x, alpha ) { +function dapx( arrays ) { var buf; var sx; var ox; var N; + var x; + + x = arrays[ 0 ]; N = numelDimension( x, 0 ); if ( N <= 0 ) { @@ -62,7 +68,7 @@ function dapx( x, alpha ) { sx = getStride( x, 0 ); ox = getOffset( x ); - strided( N, alpha, buf, sx, ox ); + strided( N, ndarraylike2scalar( arrays[ 1 ] ), buf, sx, ox ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js index ed1dd1626ede..bf78e5c09950 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var ndarray = require( '@stdlib/ndarray/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var dapx = require( './../lib' ); @@ -36,6 +37,7 @@ tape( 'main export is a function', function test( t ) { tape( 'the function adds a scalar constant to each element in a double-precision floating-point ndarray', function test( t ) { var expected; + var alpha; var xbuf; var x; @@ -44,13 +46,16 @@ tape( 'the function adds a scalar constant to each element in a double-precision expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0 ] ); - dapx( x, 5.0 ); + alpha = scalar2ndarray( 5.0, 'float64', 'row-major' ); + + dapx( [ x, alpha ] ); t.deepEqual( x.data, expected, 'returns expected value' ); t.end(); }); tape( 'the function returns the input ndarray', function test( t ) { + var alpha; var xbuf; var x; var y; @@ -58,7 +63,11 @@ tape( 'the function returns the input ndarray', function test( t ) { xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - y = dapx( x, 5.0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + y = dapx( [ x, alpha ] ); t.strictEqual( y, x, 'returns expected value' ); t.end(); @@ -66,6 +75,7 @@ tape( 'the function returns the input ndarray', function test( t ) { tape( 'the function supports ndarrays with negative strides', function test( t ) { var expected; + var alpha; var xbuf; var x; @@ -74,7 +84,11 @@ tape( 'the function supports ndarrays with negative strides', function test( t ) expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0 ] ); - dapx( x, 5.0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); t.deepEqual( x.data, expected, 'returns expected value' ); t.end(); @@ -82,6 +96,7 @@ tape( 'the function supports ndarrays with negative strides', function test( t ) tape( 'the function supports ndarrays with an offset', function test( t ) { var expected; + var alpha; var xbuf; var x; @@ -90,7 +105,11 @@ tape( 'the function supports ndarrays with an offset', function test( t ) { expected = new Float64Array( [ 1.0, 2.0, 8.0, 9.0, 10.0 ] ); - dapx( x, 5.0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); t.deepEqual( x.data, expected, 'returns expected value' ); t.end(); @@ -98,6 +117,7 @@ tape( 'the function supports ndarrays with an offset', function test( t ) { tape( 'the function supports zero-length ndarrays', function test( t ) { var expected; + var alpha; var xbuf; var x; @@ -106,7 +126,11 @@ tape( 'the function supports zero-length ndarrays', function test( t ) { expected = new Float64Array( [] ); - dapx( x, 5.0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); t.deepEqual( x.data, expected, 'returns expected value' ); t.end(); @@ -114,6 +138,7 @@ tape( 'the function supports zero-length ndarrays', function test( t ) { tape( 'the function supports adding zero', function test( t ) { var expected; + var alpha; var xbuf; var x; @@ -122,7 +147,11 @@ tape( 'the function supports adding zero', function test( t ) { expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - dapx( x, 0.0 ); + alpha = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); t.deepEqual( x.data, expected, 'returns expected value' ); t.end(); @@ -130,6 +159,7 @@ tape( 'the function supports adding zero', function test( t ) { tape( 'the function supports negative constants', function test( t ) { var expected; + var alpha; var xbuf; var x; @@ -138,7 +168,11 @@ tape( 'the function supports negative constants', function test( t ) { expected = new Float64Array( [ -4.0, -3.0, -2.0, -1.0 ] ); - dapx( x, -5.0 ); + alpha = scalar2ndarray( -5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); t.deepEqual( x.data, expected, 'returns expected value' ); t.end(); From 78c612ab56a4fcc768513ce93076f628a60baef0 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 20 Dec 2025 10:43:17 +0530 Subject: [PATCH 5/6] fix CI errors --- .../@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt | 2 +- .../@stdlib/blas/ext/base/ndarray/dapx/lib/index.js | 9 +++++++-- .../@stdlib/blas/ext/base/ndarray/dapx/test/test.js | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt index 46c232b6f2ea..ca1dfa374711 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt @@ -18,7 +18,7 @@ -------- > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, 'float64', 'row-major' ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, { 'dtype': 'float64' } ); > {{alias}}( [ x, alpha ] ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js index 8bb4d737b9ff..0144666ea6e9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js @@ -26,13 +26,18 @@ * @example * var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); * * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var out = dapx( x, 5.0 ); -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var out = dapx( [ x, alpha ] ); +* // returns */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js index bf78e5c09950..5f7d8a036158 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js @@ -46,7 +46,9 @@ tape( 'the function adds a scalar constant to each element in a double-precision expected = new Float64Array( [ 6.0, 7.0, 8.0, 9.0 ] ); - alpha = scalar2ndarray( 5.0, 'float64', 'row-major' ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); dapx( [ x, alpha ] ); From e9c2f875fecef1ccf34d42ed82c097125c558112 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Sat, 20 Dec 2025 10:49:15 +0530 Subject: [PATCH 6/6] Fix JSDoc doctest: add variable assignment before returns comment --- .../blas/ext/base/ndarray/dapx/lib/main.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js index 3f9ab613f504..e90e6e95fd3a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js @@ -48,27 +48,16 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); * 'dtype': 'float64' * }); * -* dapx( [ x, alpha ] ); +* var out = dapx( [ x, alpha ] ); * // returns */ function dapx( arrays ) { - var buf; - var sx; - var ox; - var N; - var x; + var x = arrays[ 0 ]; - x = arrays[ 0 ]; - - N = numelDimension( x, 0 ); - if ( N <= 0 ) { + if ( numelDimension( x, 0 ) <= 0 ) { return x; } - buf = getData( x ); - sx = getStride( x, 0 ); - ox = getOffset( x ); - - strided( N, ndarraylike2scalar( arrays[ 1 ] ), buf, sx, ox ); + strided( numelDimension( x, 0 ), ndarraylike2scalar( arrays[ 1 ] ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len return x; }