From 945f942f3a0b742691e78035215e8a93eec7babc Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Thu, 18 Dec 2025 20:19:42 +0530 Subject: [PATCH 1/2] feat: add blas/ext/base/ndarray/sapx --- .../blas/ext/base/ndarray/sapx/README.md | 130 ++++++++++++++++ .../base/ndarray/sapx/benchmark/benchmark.js | 101 ++++++++++++ .../blas/ext/base/ndarray/sapx/docs/repl.txt | 29 ++++ .../base/ndarray/sapx/docs/types/index.d.ts | 49 ++++++ .../ext/base/ndarray/sapx/docs/types/test.ts | 62 ++++++++ .../ext/base/ndarray/sapx/examples/index.js | 34 ++++ .../blas/ext/base/ndarray/sapx/lib/index.js | 47 ++++++ .../blas/ext/base/ndarray/sapx/lib/main.js | 72 +++++++++ .../blas/ext/base/ndarray/sapx/package.json | 76 +++++++++ .../blas/ext/base/ndarray/sapx/test/test.js | 145 ++++++++++++++++++ 10 files changed, 745 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md new file mode 100644 index 000000000000..dd3f777cd6da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md @@ -0,0 +1,130 @@ + + +# sapx + +> Add a scalar constant to each element in a single-precision floating-point ndarray. + +
+ +## Usage + +```javascript +var sapx = require( '@stdlib/blas/ext/base/ndarray/sapx' ); +``` + +#### sapx( x, alpha ) + +Adds a scalar constant to each element in a single-precision floating-point ndarray. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +sapx( 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 Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +// Initial array: +var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Create an ndarray view: +var x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); + +sapx( 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 sapx = require( '@stdlib/blas/ext/base/ndarray/sapx' ); + +var xbuf = discreteUniform( 10, 0, 100, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); + +console.log( x.data ); + +sapx( x, 5.0 ); + +console.log( x.data ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/benchmark/benchmark.js new file mode 100644 index 000000000000..5cb71140a779 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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 sapx = 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( 'float32', discreteUniform( len, -100, 100, { + 'dtype': 'float32' + }), [ 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 = sapx( 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/sapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt new file mode 100644 index 000000000000..2aeb3a4090ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt @@ -0,0 +1,29 @@ +{{alias}}( x, alpha ) + Adds a scalar constant to each element in a single-precision floating- + point ndarray. + + Parameters + ---------- + x: float32ndarray + Input ndarray. + + alpha: number + Scalar constant. + + Returns + ------- + out: float32ndarray + Input ndarray. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var x = {{alias:@stdlib/ndarray/ctor}}( 'float32', 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/sapx/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/index.d.ts new file mode 100644 index 000000000000..8ddf86ac342d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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 { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Adds a scalar constant to each element in a single-precision floating-point ndarray. +* +* @param x - input ndarray +* @param alpha - scalar constant +* @returns input ndarray +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* sapx( x, 5.0 ); +* +* var y = x.data; +* // returns [ 6.0, 7.0, 8.0, 9.0 ] +*/ +declare function sapx( x: float32ndarray, alpha: number ): float32ndarray; + + +// EXPORTS // + +export = sapx; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/test.ts new file mode 100644 index 000000000000..dc65c070e6f0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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 sapx = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x: any = null; + sapx( x, 5.0 ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + sapx( 123, 5.0 ); // $ExpectError + sapx( true, 5.0 ); // $ExpectError + sapx( false, 5.0 ); // $ExpectError + sapx( null, 5.0 ); // $ExpectError + sapx( undefined, 5.0 ); // $ExpectError + sapx( '5', 5.0 ); // $ExpectError + sapx( [ '1', '2' ], 5.0 ); // $ExpectError + sapx( {}, 5.0 ); // $ExpectError + sapx( ( 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; + sapx( x, '5' ); // $ExpectError + sapx( x, true ); // $ExpectError + sapx( x, false ); // $ExpectError + sapx( x, null ); // $ExpectError + sapx( x, undefined ); // $ExpectError + sapx( x, [ '1' ] ); // $ExpectError + sapx( x, {} ); // $ExpectError + sapx( 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; + sapx(); // $ExpectError + sapx( x ); // $ExpectError + sapx( x, 5.0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/examples/index.js new file mode 100644 index 000000000000..87935dcf91ff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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 sapx = require( './../lib' ); + +var xbuf = discreteUniform( 10, 0, 100, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); + +console.log( x.data ); + +sapx( x, 5.0 ); + +console.log( x.data ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js new file mode 100644 index 000000000000..5c0f5d961a1c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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 single-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/sapx +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var sapx = require( '@stdlib/blas/ext/base/ndarray/sapx' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* sapx( 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/sapx/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/main.js new file mode 100644 index 000000000000..5d95516d86df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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/sapx' ).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 single-precision floating-point ndarray. +* +* @param {float32ndarray} x - input ndarray +* @param {number} alpha - scalar constant +* @returns {float32ndarray} input ndarray +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* sapx( x, 5.0 ); +* +* var y = x.data; +* // returns [ 6.0, 7.0, 8.0, 9.0 ] +*/ +function sapx( 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 = sapx; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/package.json new file mode 100644 index 000000000000..feca46b066e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/sapx", + "version": "0.0.0", + "description": "Add a scalar constant to each element in a single-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", + "sapx", + "linear", + "algebra", + "subroutines", + "ndarray", + "vector", + "array", + "multidimensional", + "add", + "constant", + "plus", + "increment", + "augment", + "float32", + "single", + "float32array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/test/test.js new file mode 100644 index 000000000000..8e744ca0aacf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/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 Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var sapx = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sapx, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds a scalar constant to each element in a single-precision floating-point ndarray', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0 ] ); + + sapx( 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + y = sapx( 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 4 ], [ -1 ], 3, 'row-major' ); + + expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0 ] ); + + sapx( 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); + + expected = new Float32Array( [ 1.0, 2.0, 8.0, 9.0, 10.0 ] ); + + sapx( 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 Float32Array( [] ); + x = new ndarray( 'float32', xbuf, [ 0 ], [ 1 ], 0, 'row-major' ); + + expected = new Float32Array( [] ); + + sapx( 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + sapx( 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + expected = new Float32Array( [ -4.0, -3.0, -2.0, -1.0 ] ); + + sapx( x, -5.0 ); + + t.deepEqual( x.data, expected, 'returns expected value' ); + t.end(); +}); From 051ebdc9b6a6652a060b269896ca0cd3c1db03c1 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 18:18:51 +0530 Subject: [PATCH 2/2] docs: update return annotations to use ndarray instance notation --- .../@stdlib/blas/ext/base/ndarray/sapx/README.md | 12 ++++-------- .../@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt | 4 +--- .../blas/ext/base/ndarray/sapx/docs/types/index.d.ts | 6 ++---- .../@stdlib/blas/ext/base/ndarray/sapx/lib/index.js | 6 ++---- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md index dd3f777cd6da..1f2474b8cefb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/README.md @@ -41,10 +41,8 @@ var ndarray = require( '@stdlib/ndarray/ctor' ); var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -sapx( x, 5.0 ); - -var y = x.data; -// returns [ 6.0, 7.0, 8.0, 9.0 ] +var out = sapx( 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 Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); // Create an ndarray view: var x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 2, 'row-major' ); -sapx( x, 5.0 ); - -var y = x.data; -// returns [ 1.0, 2.0, 8.0, 9.0, 10.0 ] +var out = sapx( x, 5.0 ); +// returns [ 8.0, 9.0, 10.0 ] ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt index 2aeb3a4090ab..10084fb05323 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/repl.txt @@ -20,9 +20,7 @@ > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var x = {{alias:@stdlib/ndarray/ctor}}( 'float32', 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/sapx/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/index.d.ts index 8ddf86ac342d..b1358072c89e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/docs/types/index.d.ts @@ -36,10 +36,8 @@ import { float32ndarray } from '@stdlib/types/ndarray'; * var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* sapx( x, 5.0 ); -* -* var y = x.data; -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* var out = sapx( x, 5.0 ); +* // returns [ 6.0, 7.0, 8.0, 9.0 ] */ declare function sapx( x: float32ndarray, alpha: number ): float32ndarray; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js index 5c0f5d961a1c..2dec432194c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sapx/lib/index.js @@ -31,10 +31,8 @@ * var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* sapx( x, 5.0 ); -* -* var y = x.data; -* // returns [ 6.0, 7.0, 8.0, 9.0 ] +* var out = sapx( x, 5.0 ); +* // returns [ 6.0, 7.0, 8.0, 9.0 ] */ // MODULES //