From b9182c924cf3ce592ae37dc0ae921d52a717a744 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Thu, 20 Aug 2026 03:37:14 +0530 Subject: [PATCH 1/3] feat(blas/ext/base/ndarray/dapx): add ndarray wrapper for dapx --- .../blas/ext/base/ndarray/dapx/README.md | 123 ++++++++ .../base/ndarray/dapx/benchmark/benchmark.js | 107 +++++++ .../blas/ext/base/ndarray/dapx/docs/repl.txt | 33 +++ .../base/ndarray/dapx/docs/types/index.d.ts | 49 ++++ .../ext/base/ndarray/dapx/docs/types/test.ts | 64 +++++ .../ext/base/ndarray/dapx/examples/index.js | 38 +++ .../blas/ext/base/ndarray/dapx/lib/index.js | 48 ++++ .../blas/ext/base/ndarray/dapx/lib/main.js | 73 +++++ .../blas/ext/base/ndarray/dapx/package.json | 72 +++++ .../blas/ext/base/ndarray/dapx/test/test.js | 265 ++++++++++++++++++ 10 files changed, 872 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..f124efb02969 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/README.md @@ -0,0 +1,123 @@ + + +# dapx + +> Add a scalar constant to each element in a one-dimensional double-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); +``` + +#### dapx( arrays ) + +Adds a scalar constant to each element in a one-dimensional double-precision floating-point ndarray. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +dapx( [ x, alpha ] ); +// x => [ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant to add. + +
+ + + +
+ +## Notes + +- The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ 10 ], -100, 100, opts ); +console.log( ndarray2array( x ) ); + +var alpha = scalar2ndarray( 5.0, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +dapx( [ x, alpha ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + 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..423884d3f904 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/benchmark/benchmark.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dapx = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var x; + + x = uniform( [ len ], -100.0, 100.0, options ); + alpha = scalar2ndarray( 5.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dapx( [ x, alpha ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + 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( format( '%s:len=%d', pkg, 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..86bb2bad8181 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( arrays ) + Adds a scalar constant to each element in a one-dimensional double-precision + floating-point ndarray. + + The input ndarray is modified *in-place* (i.e., the input ndarray is + *mutated*). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant to add. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/float64}}( buf ); + > var opts = { 'dtype': 'float64' }; + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, opts ); + > {{alias}}( [ x, alpha ] ) + [ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.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..bf58056939da --- /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) 2026 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, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Adds a scalar constant to each element in a one-dimensional double-precision floating-point ndarray. +* +* @param arrays - array containing a one-dimensional input ndarray and a zero-dimensional ndarray containing the scalar constant to add +* @returns input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var out = dapx( [ x, alpha ] ); +* // returns [ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] +*/ +declare function dapx( arrays: [ float64ndarray, typedndarray ] ): 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..8c5c54644cd6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/docs/types/test.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import dapx = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dapx( '10' as any ); // $ExpectError + dapx( 5 as any ); // $ExpectError + dapx( true as any ); // $ExpectError + dapx( false as any ); // $ExpectError + dapx( null as any ); // $ExpectError + dapx( undefined as any ); // $ExpectError + dapx( [] as any ); // $ExpectError + dapx( {} as any ); // $ExpectError + dapx( ( ( x: number ): number => x ) as any ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx(); // $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 new file mode 100644 index 000000000000..e8eb80237755 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var dapx = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ 10 ], -100, 100, opts ); +console.log( ndarray2array( x ) ); + +var alpha = scalar2ndarray( 5.0, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +dapx( [ x, alpha ] ); +console.log( ndarray2array( x ) ); 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..480b116390fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/index.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 one-dimensional double-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/dapx +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); +* +* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var out = dapx( [ x, alpha ] ); +* // returns [ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.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..c486640408c9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/lib/main.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/dapx' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Adds a scalar constant to each element in a one-dimensional double-precision floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant to add. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var out = dapx( [ x, alpha ] ); +* // returns [ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] +*/ +function dapx( arrays ) { + var alpha; + var x; + + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + + strided( numelDimension( x, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = dapx; 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..e3feb32b6338 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/dapx", + "version": "0.0.0", + "description": "Add a scalar constant to each element in a one-dimensional 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", + "extended", + "ext", + "dapx", + "apx", + "add", + "scalar", + "constant", + "strided", + "array", + "ndarray", + "float64", + "double", + "double-precision" + ], + "__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..61a20ef29f91 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dapx/test/test.js @@ -0,0 +1,265 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var dapx = 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 dapx, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds a scalar constant to each element', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + x = vector( xbuf, 8, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ 9.0, 7.0, 2.0, 10.0, 4.0, 7.0, 0.0, 11.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + xbuf = new Float64Array( [ 1.0, 2.0 ] ); + x = vector( xbuf, 2, 1, 0 ); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ 6.0, 7.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var out; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + alpha = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + out = dapx( [ x, alpha ] ); + t.strictEqual( out, x, 'returns expected value' ); + t.end(); +}); + +tape( 'if the input ndarray is empty, the function returns the input ndarray unchanged', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + x = vector( xbuf, 0, 1, 0 ); + alpha = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if `alpha` equals `0`, the function returns the input ndarray unchanged', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an input ndarray with a non-unit stride', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + x = vector( xbuf, 3, 2, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ + 7.0, // 0 + -3.0, + 0.0, // 1 + 7.0, + 11.0 // 2 + ]); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an input ndarray with a negative stride', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]); + x = vector( xbuf, 3, -2, 4 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ + 7.0, // 2 + -3.0, + 0.0, // 1 + 7.0, + 11.0 // 0 + ]); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an input ndarray with a non-zero offset', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + + xbuf = new Float64Array( [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + x = vector( xbuf, 3, 2, 1 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + dapx( [ x, alpha ] ); + + expected = new Float64Array( [ + 1.0, + 7.0, // 0 + 3.0, + 9.0, // 1 + 5.0, + 11.0 // 2 + ]); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function efficiently adds a constant to each element (stride=1)', function test( t ) { + var expected; + var alpha; + var xbuf; + var x; + var i; + + alpha = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + xbuf = new Float64Array( 100 ); + expected = new Float64Array( 100 ); + for ( i = 0; i < xbuf.length; i++ ) { + xbuf[ i ] = i; + expected[ i ] = i + 3.0; + } + x = vector( xbuf, 100, 1, 0 ); + dapx( [ x, alpha ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + xbuf = new Float64Array( 240 ); + expected = new Float64Array( 240 ); + for ( i = 0; i < xbuf.length; i++ ) { + xbuf[ i ] = i; + expected[ i ] = i + 3.0; + } + x = vector( xbuf, 240, 1, 0 ); + dapx( [ x, alpha ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); From 268f72b83885b3c756b77b4a10a80bc6f7719a1b Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Thu, 20 Aug 2026 04:03:20 +0530 Subject: [PATCH 2/3] Fix lint errors in dapx test.js and test.ts --- .../ext/base/ndarray/dapx/docs/types/test.ts | 18 +++++++++--------- .../blas/ext/base/ndarray/dapx/test/test.js | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) 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 8c5c54644cd6..7ce017eefb53 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 @@ -39,15 +39,15 @@ import dapx = require( './index' ); // The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... { - dapx( '10' as any ); // $ExpectError - dapx( 5 as any ); // $ExpectError - dapx( true as any ); // $ExpectError - dapx( false as any ); // $ExpectError - dapx( null as any ); // $ExpectError - dapx( undefined as any ); // $ExpectError - dapx( [] as any ); // $ExpectError - dapx( {} as any ); // $ExpectError - dapx( ( ( x: number ): number => x ) as any ); // $ExpectError + dapx( '10' ); // $ExpectError + dapx( 5 ); // $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... 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 61a20ef29f91..c138b6374138 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 @@ -81,9 +81,9 @@ tape( 'the function adds a scalar constant to each element', function test( t ) }); tape( 'the function returns the input ndarray', function test( t ) { - var out; var alpha; var xbuf; + var out; var x; xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); @@ -141,7 +141,7 @@ tape( 'the function supports an input ndarray with a non-unit stride', function var xbuf; var x; - xbuf = new Float64Array( [ + xbuf = new Float64Array([ 2.0, // 0 -3.0, -5.0, // 1 @@ -155,7 +155,7 @@ tape( 'the function supports an input ndarray with a non-unit stride', function dapx( [ x, alpha ] ); - expected = new Float64Array( [ + expected = new Float64Array([ 7.0, // 0 -3.0, 0.0, // 1 @@ -172,7 +172,7 @@ tape( 'the function supports an input ndarray with a negative stride', function var xbuf; var x; - xbuf = new Float64Array( [ + xbuf = new Float64Array([ 2.0, // 2 -3.0, -5.0, // 1 @@ -186,7 +186,7 @@ tape( 'the function supports an input ndarray with a negative stride', function dapx( [ x, alpha ] ); - expected = new Float64Array( [ + expected = new Float64Array([ 7.0, // 2 -3.0, 0.0, // 1 @@ -203,7 +203,7 @@ tape( 'the function supports an input ndarray with a non-zero offset', function var xbuf; var x; - xbuf = new Float64Array( [ + xbuf = new Float64Array([ 1.0, 2.0, // 0 3.0, @@ -218,7 +218,7 @@ tape( 'the function supports an input ndarray with a non-zero offset', function dapx( [ x, alpha ] ); - expected = new Float64Array( [ + expected = new Float64Array([ 1.0, 7.0, // 0 3.0, From 2e3b5e8680454c27c86b0d6dabab4f04107506af Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Thu, 20 Aug 2026 23:48:31 +0530 Subject: [PATCH 3/3] Address review comments for dapx PR --- .../@stdlib/blas/ext/base/ndarray/dapx/README.md | 6 ++++-- .../blas/ext/base/ndarray/dapx/docs/repl.txt | 2 +- .../ext/base/ndarray/dapx/docs/types/index.d.ts | 15 ++++++++++++--- .../blas/ext/base/ndarray/dapx/lib/index.js | 6 ++++-- .../blas/ext/base/ndarray/dapx/lib/main.js | 6 ++++-- 5 files changed, 25 insertions(+), 10 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 f124efb02969..99ff2d9ff264 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,12 @@ var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); Adds a scalar constant to each element in a one-dimensional double-precision floating-point ndarray. ```javascript -var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var array = require( '@stdlib/ndarray/array' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +var x = array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ], { + 'dtype': 'float64' +}); var alpha = scalar2ndarray( 5.0, { 'dtype': 'float64' 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 86bb2bad8181..268d66b9d55f 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 @@ -22,8 +22,8 @@ Examples -------- > var buf = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; - > var x = new {{alias:@stdlib/ndarray/vector/float64}}( buf ); > var opts = { 'dtype': 'float64' }; + > var x = {{alias:@stdlib/ndarray/array}}( buf, opts ); > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, opts ); > {{alias}}( [ x, alpha ] ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] 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 bf58056939da..012932d3a311 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,14 +25,23 @@ import { float64ndarray, typedndarray } from '@stdlib/types/ndarray'; /** * Adds a scalar constant to each element in a one-dimensional double-precision floating-point ndarray. * -* @param arrays - array containing a one-dimensional input ndarray and a zero-dimensional ndarray containing the scalar constant to add +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant to add. +* +* @param arrays - array-like object containing ndarrays * @returns input ndarray * * @example -* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var array = require( '@stdlib/ndarray/array' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * -* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* var x = array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ], { +* 'dtype': 'float64' +* }); * * var alpha = scalar2ndarray( 5.0, { * 'dtype': 'float64' 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 480b116390fd..01d51a17410a 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 @@ -24,11 +24,13 @@ * @module @stdlib/blas/ext/base/ndarray/dapx * * @example -* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var array = require( '@stdlib/ndarray/array' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var dapx = require( '@stdlib/blas/ext/base/ndarray/dapx' ); * -* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* var x = array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ], { +* 'dtype': 'float64' +* }); * * var alpha = scalar2ndarray( 5.0, { * 'dtype': 'float64' 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 c486640408c9..b7b0b722e41c 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 @@ -44,10 +44,12 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); * @returns {ndarray} input ndarray * * @example -* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var array = require( '@stdlib/ndarray/array' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * -* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* var x = array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ], { +* 'dtype': 'float64' +* }); * * var alpha = scalar2ndarray( 5.0, { * 'dtype': 'float64'