From b591d4831df13805b137f47e000fbef14960a7af Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 23 May 2026 20:46:57 -0700 Subject: [PATCH 1/5] feat: add `blas/ext/base/ndarray/daxpb` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/daxpb/README.md | 112 ++++++++++ .../base/ndarray/daxpb/benchmark/benchmark.js | 95 +++++++++ .../blas/ext/base/ndarray/daxpb/docs/repl.txt | 35 +++ .../base/ndarray/daxpb/docs/types/index.d.ts | 53 +++++ .../ext/base/ndarray/daxpb/docs/types/test.ts | 77 +++++++ .../ext/base/ndarray/daxpb/examples/index.js | 32 +++ .../blas/ext/base/ndarray/daxpb/lib/index.js | 44 ++++ .../blas/ext/base/ndarray/daxpb/lib/main.js | 64 ++++++ .../blas/ext/base/ndarray/daxpb/package.json | 75 +++++++ .../blas/ext/base/ndarray/daxpb/test/test.js | 201 ++++++++++++++++++ 10 files changed, 788 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md new file mode 100644 index 000000000000..2a841f673509 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md @@ -0,0 +1,112 @@ + + +# daxpb + +> Multiply each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and add a scalar constant to each result. + +
+ +
+ + + +
+ +## Usage + +```javascript +var daxpb = require( '@stdlib/blas/ext/base/ndarray/daxpb' ); +``` + +#### daxpb( alpha, beta, arrays ) + +Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant `alpha` and adds a scalar constant `beta` to each result. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); + +var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +// returns [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] + +daxpb( 5.0, 3.0, [ x ] ); +// x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +``` + +The function has the following parameters: + +- **alpha**: first scalar constant. +- **beta**: second scalar constant. +- **arrays**: array-like object containing a one-dimensional input ndarray. + +
+ + + +
+ +## 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var daxpb = require( '@stdlib/blas/ext/base/ndarray/daxpb' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( [ 10 ], -100, 100, opts ); +console.log( ndarray2array( x ) ); + +daxpb( 5.0, 3.0, [ x ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js new file mode 100644 index 000000000000..cd0fe1911676 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js @@ -0,0 +1,95 @@ +/** +* @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 Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var daxpb = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = new Float64Vector( len ); + 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 = daxpb( 5.0, 3.0, [ x ] ); + 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/daxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt new file mode 100644 index 000000000000..d0cc38770f0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( alpha, beta, arrays ) + Multiplies each element in a one-dimensional double-precision + floating-point ndarray by a scalar constant and adds a scalar constant to + each result. + + The input ndarray is modified *in-place* (i.e., the input ndarray is + *mutated*). + + Parameters + ---------- + alpha: number + First scalar constant. + + beta: number + Second scalar constant. + + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = [ -2.0, 1.0, 3.0, -5.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/float64}}( buf ); + > {{alias}}( 5.0, 3.0, [ x ] ) + [ -7.0, 8.0, 18.0, -22.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts new file mode 100644 index 000000000000..89c00192a25b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts @@ -0,0 +1,53 @@ +/* +* @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 } from '@stdlib/types/ndarray'; + +/** +* Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and adds a scalar constant to each result. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* +* @param alpha - first scalar constant +* @param beta - second scalar constant +* @param arrays - array-like object containing a one-dimensional input ndarray +* @returns input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* +* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* // returns [ -2.0, 1.0, 3.0, -5.0 ] +* +* var out = daxpb( 5.0, 3.0, [ x ] ); +* // returns [ -7.0, 8.0, 18.0, -22.0 ] +*/ +declare function daxpb( alpha: number, beta: number, arrays: [ float64ndarray ] ): float64ndarray; + + +// EXPORTS // + +export = daxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts new file mode 100644 index 000000000000..ab1b8441b7fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts @@ -0,0 +1,77 @@ +/* +* @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. +*/ + +import Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +import daxpb = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); + daxpb( 5.0, 3.0, [ x ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); + daxpb( '5', 3.0, [ x ] ); // $ExpectError + daxpb( true, 3.0, [ x ] ); // $ExpectError + daxpb( false, 3.0, [ x ] ); // $ExpectError + daxpb( null, 3.0, [ x ] ); // $ExpectError + daxpb( undefined, 3.0, [ x ] ); // $ExpectError + daxpb( [], 3.0, [ x ] ); // $ExpectError + daxpb( {}, 3.0, [ x ] ); // $ExpectError + daxpb( ( x: number ): number => x, 3.0, [ x ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); + daxpb( 5.0, '3', [ x ] ); // $ExpectError + daxpb( 5.0, true, [ x ] ); // $ExpectError + daxpb( 5.0, false, [ x ] ); // $ExpectError + daxpb( 5.0, null, [ x ] ); // $ExpectError + daxpb( 5.0, undefined, [ x ] ); // $ExpectError + daxpb( 5.0, [], [ x ] ); // $ExpectError + daxpb( 5.0, {}, [ x ] ); // $ExpectError + daxpb( 5.0, ( x: number ): number => x, [ x ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not an array of ndarrays... +{ + daxpb( 5.0, 3.0, '10' ); // $ExpectError + daxpb( 5.0, 3.0, 5 ); // $ExpectError + daxpb( 5.0, 3.0, true ); // $ExpectError + daxpb( 5.0, 3.0, false ); // $ExpectError + daxpb( 5.0, 3.0, null ); // $ExpectError + daxpb( 5.0, 3.0, undefined ); // $ExpectError + daxpb( 5.0, 3.0, [] ); // $ExpectError + daxpb( 5.0, 3.0, {} ); // $ExpectError + daxpb( 5.0, 3.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); + daxpb(); // $ExpectError + daxpb( 5.0 ); // $ExpectError + daxpb( 5.0, 3.0 ); // $ExpectError + daxpb( 5.0, 3.0, [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js new file mode 100644 index 000000000000..aa966600820c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var daxpb = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( [ 10 ], -100, 100, opts ); +console.log( ndarray2array( x ) ); + +daxpb( 5.0, 3.0, [ x ] ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js new file mode 100644 index 000000000000..be37a620a9aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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'; + +/** +* Multiply each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and add a scalar constant to each result. +* +* @module @stdlib/blas/ext/base/ndarray/daxpb +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var daxpb = require( '@stdlib/blas/ext/base/ndarray/daxpb' ); +* +* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* // returns [ -2.0, 1.0, 3.0, -5.0 ] +* +* var out = daxpb( 5.0, 3.0, [ x ] ); +* // returns [ -7.0, 8.0, 18.0, -22.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js new file mode 100644 index 000000000000..3902add0b399 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js @@ -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. +*/ + +'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/daxpb' ).ndarray; + + +// MAIN // + +/** +* Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and adds a scalar constant to each result. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* +* @param {number} alpha - first scalar constant +* @param {number} beta - second scalar constant +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* +* var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* // returns [ -2.0, 1.0, 3.0, -5.0 ] +* +* var out = daxpb( 5.0, 3.0, [ x ] ); +* // returns [ -7.0, 8.0, 18.0, -22.0 ] +*/ +function daxpb( alpha, beta, arrays ) { + var x = arrays[ 0 ]; + strided( numelDimension( x, 0 ), alpha, beta, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = daxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/package.json new file mode 100644 index 000000000000..06a80f6bcbd1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/daxpb", + "version": "0.0.0", + "description": "Multiply each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and add a scalar constant to each result.", + "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", + "daxpb", + "axpb", + "multiply", + "add", + "scalar", + "constant", + "linear", + "combination", + "strided", + "array", + "ndarray", + "float64", + "double", + "double-precision" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js new file mode 100644 index 000000000000..ca4a36c8778a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js @@ -0,0 +1,201 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var daxpb = 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 daxpb, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( daxpb.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + + actual = daxpb( 5.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ -7.0, 8.0, 18.0, -22.0, 23.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function adds `beta` to each element when `alpha` equals `1.0`', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + + actual = daxpb( 1.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, 4.0, 6.0, -2.0, 7.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies each element by `alpha` when `beta` equals `0.0`', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + + actual = daxpb( 5.0, 0.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ -10.0, 5.0, 15.0, -25.0, 20.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + x = vector( xbuf, 4, 2, 0 ); + + actual = daxpb( 5.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ -7.0, 1.0, 18.0, -5.0, 23.0, 0.0, -2.0, -3.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); + x = vector( xbuf, 5, -1, 4 ); + + actual = daxpb( 5.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ -7.0, 8.0, 18.0, -22.0, 23.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -5.0, 4.0, 0.0 ] ); + x = vector( xbuf, 3, 1, 2 ); + + actual = daxpb( 5.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, -2.0, 18.0, -22.0, 23.0, 0.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride and non-zero offset', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, 2.0, 6.0 ] ); + x = vector( xbuf, 5, -2, 9 ); + + actual = daxpb( 5.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, -7.0, 3.0, -22.0, 4.0, 3.0, -1.0, -12.0, 2.0, 33.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + + actual = daxpb( 5.0, 3.0, [ x ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Float64Array( [] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); From 0b551535b8d6eed85ccc6b4aadea7f4744e09d50 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 23 May 2026 20:56:42 -0700 Subject: [PATCH 2/5] chore: fix line breaks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt index d0cc38770f0f..b4e080bbefcc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt @@ -1,8 +1,7 @@ {{alias}}( alpha, beta, arrays ) - Multiplies each element in a one-dimensional double-precision - floating-point ndarray by a scalar constant and adds a scalar constant to - each result. + Multiplies each element in a one-dimensional double-precision floating-point + ndarray by a scalar constant and adds a scalar constant to each result. The input ndarray is modified *in-place* (i.e., the input ndarray is *mutated*). From 1054d44c4f50fe75ba88dca53e3e3f428ef7db3a Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 25 May 2026 16:41:48 -0700 Subject: [PATCH 3/5] chore: apply suggestions from review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/daxpb/README.md | 35 ++++-- .../base/ndarray/daxpb/benchmark/benchmark.js | 20 +++- .../blas/ext/base/ndarray/daxpb/docs/repl.txt | 19 ++-- .../base/ndarray/daxpb/docs/types/index.d.ts | 22 ++-- .../ext/base/ndarray/daxpb/docs/types/test.ts | 77 ++++++------- .../ext/base/ndarray/daxpb/examples/index.js | 11 +- .../blas/ext/base/ndarray/daxpb/lib/index.js | 12 ++- .../blas/ext/base/ndarray/daxpb/lib/main.js | 27 +++-- .../blas/ext/base/ndarray/daxpb/test/test.js | 102 ++++++++++++++---- 9 files changed, 226 insertions(+), 99 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md index 2a841f673509..0b7ccf659c0a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/README.md @@ -36,25 +36,35 @@ limitations under the License. var daxpb = require( '@stdlib/blas/ext/base/ndarray/daxpb' ); ``` -#### daxpb( alpha, beta, arrays ) +#### daxpb( arrays ) -Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant `alpha` and adds a scalar constant `beta` to each result. +Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and adds a scalar constant to each result. ```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 ] ); -// returns [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] -daxpb( 5.0, 3.0, [ x ] ); +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +var beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' +}); + +daxpb( [ x, alpha, beta ] ); // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] ``` The function has the following parameters: -- **alpha**: first scalar constant. -- **beta**: second scalar constant. -- **arrays**: array-like object containing a one-dimensional input ndarray. +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant to multiply. + - a zero-dimensional ndarray containing the scalar constant to add. @@ -78,16 +88,25 @@ The function has the following parameters: ```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/base/ndarraylike2scalar' ); var daxpb = require( '@stdlib/blas/ext/base/ndarray/daxpb' ); var opts = { 'dtype': 'float64' }; + var x = discreteUniform( [ 10 ], -100, 100, opts ); console.log( ndarray2array( x ) ); -daxpb( 5.0, 3.0, [ x ] ); +var alpha = scalar2ndarray( 5.0, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +var beta = scalar2ndarray( 3.0, opts ); +console.log( 'Beta: %d', ndarraylike2scalar( beta ) ); + +daxpb( [ x, alpha, beta ] ); console.log( ndarray2array( x ) ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js index cd0fe1911676..38d1338a63cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/benchmark/benchmark.js @@ -21,13 +21,21 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +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 daxpb = require( './../lib' ); +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + // FUNCTIONS // /** @@ -38,7 +46,13 @@ var daxpb = require( './../lib' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = new Float64Vector( len ); + var alpha; + var beta; + var x; + + x = uniform( [ len ], -100.0, 100.0, options ); + alpha = scalar2ndarray( 5.0, options ); + beta = scalar2ndarray( 3.0, options ); return benchmark; /** @@ -53,7 +67,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = daxpb( 5.0, 3.0, [ x ] ); + out = daxpb( [ x, alpha, beta ] ); if ( typeof out !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt index b4e080bbefcc..5df623d41aa9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( alpha, beta, arrays ) +{{alias}}( arrays ) Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and adds a scalar constant to each result. @@ -8,14 +8,12 @@ Parameters ---------- - alpha: number - First scalar constant. - - beta: number - Second scalar constant. - arrays: ArrayLikeObject - Array-like object containing a one-dimensional input ndarray. + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant to multiply. + - a zero-dimensional ndarray containing the scalar constant to add. Returns ------- @@ -26,7 +24,10 @@ -------- > var buf = [ -2.0, 1.0, 3.0, -5.0 ]; > var x = new {{alias:@stdlib/ndarray/vector/float64}}( buf ); - > {{alias}}( 5.0, 3.0, [ x ] ) + > var s2a = {{alias:@stdlib/ndarray/from-scalar}}; + > var alpha = s2a( 5.0, { 'dtype': 'float64' } ); + > var beta = s2a( 3.0, { 'dtype': 'float64' } ); + > {{alias}}( [ x, alpha, beta ] ) [ -7.0, 8.0, 18.0, -22.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts index 89c00192a25b..acf39fb593a8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { float64ndarray } from '@stdlib/types/ndarray'; +import { float64ndarray, typedndarray } from '@stdlib/types/ndarray'; /** * Multiplies each element in a one-dimensional double-precision floating-point ndarray by a scalar constant and adds a scalar constant to each result. @@ -30,22 +30,30 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * - The function expects the following ndarrays: * * - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant to multiply. +* - a zero-dimensional ndarray containing the scalar constant to add. * -* @param alpha - first scalar constant -* @param beta - second scalar constant -* @param arrays - array-like object containing a one-dimensional input ndarray +* @param arrays - array-like object containing ndarrays * @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 ] ); -* // returns [ -2.0, 1.0, 3.0, -5.0 ] * -* var out = daxpb( 5.0, 3.0, [ x ] ); +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var beta = scalar2ndarray( 3.0, { +* 'dtype': 'float64' +* }); +* +* var out = daxpb( [ x, alpha, beta ] ); * // returns [ -7.0, 8.0, 18.0, -22.0 ] */ -declare function daxpb( alpha: number, beta: number, arrays: [ float64ndarray ] ): float64ndarray; +declare function daxpb( arrays: [ float64ndarray, typedndarray, typedndarray ] ): float64ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts index ab1b8441b7fd..026b5895a9c0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/types/test.ts @@ -16,7 +16,10 @@ * limitations under the License. */ -import Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); import daxpb = require( './index' ); @@ -24,54 +27,44 @@ import daxpb = require( './index' ); // The function returns an ndarray... { - const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); - daxpb( 5.0, 3.0, [ x ] ); // $ExpectType float64ndarray -} + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + const beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); - daxpb( '5', 3.0, [ x ] ); // $ExpectError - daxpb( true, 3.0, [ x ] ); // $ExpectError - daxpb( false, 3.0, [ x ] ); // $ExpectError - daxpb( null, 3.0, [ x ] ); // $ExpectError - daxpb( undefined, 3.0, [ x ] ); // $ExpectError - daxpb( [], 3.0, [ x ] ); // $ExpectError - daxpb( {}, 3.0, [ x ] ); // $ExpectError - daxpb( ( x: number ): number => x, 3.0, [ x ] ); // $ExpectError + daxpb( [ x, alpha, beta ] ); // $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 = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); - daxpb( 5.0, '3', [ x ] ); // $ExpectError - daxpb( 5.0, true, [ x ] ); // $ExpectError - daxpb( 5.0, false, [ x ] ); // $ExpectError - daxpb( 5.0, null, [ x ] ); // $ExpectError - daxpb( 5.0, undefined, [ x ] ); // $ExpectError - daxpb( 5.0, [], [ x ] ); // $ExpectError - daxpb( 5.0, {}, [ x ] ); // $ExpectError - daxpb( 5.0, ( x: number ): number => x, [ x ] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array of ndarrays... -{ - daxpb( 5.0, 3.0, '10' ); // $ExpectError - daxpb( 5.0, 3.0, 5 ); // $ExpectError - daxpb( 5.0, 3.0, true ); // $ExpectError - daxpb( 5.0, 3.0, false ); // $ExpectError - daxpb( 5.0, 3.0, null ); // $ExpectError - daxpb( 5.0, 3.0, undefined ); // $ExpectError - daxpb( 5.0, 3.0, [] ); // $ExpectError - daxpb( 5.0, 3.0, {} ); // $ExpectError - daxpb( 5.0, 3.0, ( x: number ): number => x ); // $ExpectError + daxpb( '10' ); // $ExpectError + daxpb( 5 ); // $ExpectError + daxpb( true ); // $ExpectError + daxpb( false ); // $ExpectError + daxpb( null ); // $ExpectError + daxpb( undefined ); // $ExpectError + daxpb( [] ); // $ExpectError + daxpb( {} ); // $ExpectError + daxpb( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + const beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + daxpb(); // $ExpectError - daxpb( 5.0 ); // $ExpectError - daxpb( 5.0, 3.0 ); // $ExpectError - daxpb( 5.0, 3.0, [ x ], {} ); // $ExpectError + daxpb( [ x, alpha, beta ], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js index aa966600820c..069594c704f1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/examples/index.js @@ -19,14 +19,23 @@ '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/base/ndarraylike2scalar' ); var daxpb = require( './../lib' ); var opts = { 'dtype': 'float64' }; + var x = discreteUniform( [ 10 ], -100, 100, opts ); console.log( ndarray2array( x ) ); -daxpb( 5.0, 3.0, [ x ] ); +var alpha = scalar2ndarray( 5.0, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +var beta = scalar2ndarray( 3.0, opts ); +console.log( 'Beta: %d', ndarraylike2scalar( beta ) ); + +daxpb( [ x, alpha, beta ] ); console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js index be37a620a9aa..4ba4d926221c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/index.js @@ -25,12 +25,20 @@ * * @example * var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); * var daxpb = require( '@stdlib/blas/ext/base/ndarray/daxpb' ); * * var x = new Float64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); -* // returns [ -2.0, 1.0, 3.0, -5.0 ] * -* var out = daxpb( 5.0, 3.0, [ x ] ); +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var beta = scalar2ndarray( 3.0, { +* 'dtype': 'float64' +* }); +* +* var out = daxpb( [ x, alpha, beta ] ); * // returns [ -7.0, 8.0, 18.0, -22.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js index 3902add0b399..6bc6732bae1f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/lib/main.js @@ -25,6 +25,7 @@ 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/daxpb' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); // MAIN // @@ -37,23 +38,37 @@ var strided = require( '@stdlib/blas/ext/base/daxpb' ).ndarray; * - The function expects the following ndarrays: * * - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant to multiply. +* - a zero-dimensional ndarray containing the scalar constant to add. * -* @param {number} alpha - first scalar constant -* @param {number} beta - second scalar constant * @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 ] ); -* // returns [ -2.0, 1.0, 3.0, -5.0 ] * -* var out = daxpb( 5.0, 3.0, [ x ] ); +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var beta = scalar2ndarray( 3.0, { +* 'dtype': 'float64' +* }); +* +* var out = daxpb( [ x, alpha, beta ] ); * // returns [ -7.0, 8.0, 18.0, -22.0 ] */ -function daxpb( alpha, beta, arrays ) { - var x = arrays[ 0 ]; +function daxpb( arrays ) { + var alpha; + var beta; + var x; + + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + beta = ndarraylike2scalar( arrays[ 2 ] ); strided( numelDimension( x, 0 ), alpha, beta, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js index ca4a36c8778a..b09e5365ceed 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js @@ -22,6 +22,7 @@ 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 daxpb = require( './../lib' ); @@ -51,21 +52,24 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( daxpb.length, 3, 'returns expected value' ); - t.end(); -}); - tape( 'the function multiplies each element by a scalar constant and adds a scalar constant', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); x = vector( xbuf, 5, 1, 0 ); - - actual = daxpb( 5.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ -7.0, 8.0, 18.0, -22.0, 23.0 ] ); @@ -77,13 +81,21 @@ tape( 'the function multiplies each element by a scalar constant and adds a scal tape( 'the function adds `beta` to each element when `alpha` equals `1.0`', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); x = vector( xbuf, 5, 1, 0 ); - - actual = daxpb( 1.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 1.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ 1.0, 4.0, 6.0, -2.0, 7.0 ] ); @@ -95,13 +107,21 @@ tape( 'the function adds `beta` to each element when `alpha` equals `1.0`', func tape( 'the function multiplies each element by `alpha` when `beta` equals `0.0`', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); x = vector( xbuf, 5, 1, 0 ); - - actual = daxpb( 5.0, 0.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ -10.0, 5.0, 15.0, -25.0, 20.0 ] ); @@ -113,13 +133,21 @@ tape( 'the function multiplies each element by `alpha` when `beta` equals `0.0`' tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); x = vector( xbuf, 4, 2, 0 ); - - actual = daxpb( 5.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ -7.0, 1.0, 18.0, -5.0, 23.0, 0.0, -2.0, -3.0 ] ); @@ -131,13 +159,21 @@ tape( 'the function supports an input ndarray having a non-unit stride', functio tape( 'the function supports an input ndarray having a negative stride', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); x = vector( xbuf, 5, -1, 4 ); - - actual = daxpb( 5.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ -7.0, 8.0, 18.0, -22.0, 23.0 ] ); @@ -149,13 +185,21 @@ tape( 'the function supports an input ndarray having a negative stride', functio tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -5.0, 4.0, 0.0 ] ); x = vector( xbuf, 3, 1, 2 ); - - actual = daxpb( 5.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ 1.0, -2.0, 18.0, -22.0, 23.0, 0.0 ] ); @@ -167,13 +211,21 @@ tape( 'the function supports an input ndarray having a non-zero offset', functio tape( 'the function supports an input ndarray having a negative stride and non-zero offset', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, 2.0, 6.0 ] ); x = vector( xbuf, 5, -2, 9 ); - - actual = daxpb( 5.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [ 1.0, -7.0, 3.0, -22.0, 4.0, 3.0, -1.0, -12.0, 2.0, 33.0 ] ); @@ -185,13 +237,21 @@ tape( 'the function supports an input ndarray having a negative stride and non-z tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) { var expected; var actual; + var alpha; + var beta; var xbuf; var x; xbuf = new Float64Array( [] ); x = vector( xbuf, 0, 1, 0 ); - - actual = daxpb( 5.0, 3.0, [ x ] ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + beta = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + + actual = daxpb( [ x, alpha, beta ] ); t.strictEqual( actual, x, 'returns expected value' ); expected = new Float64Array( [] ); From d7b5e11c4589489cc28d994967091c854beeb7ec Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 26 May 2026 03:19:37 -0700 Subject: [PATCH 4/5] test: remove unnecessary tests Signed-off-by: Athan --- .../blas/ext/base/ndarray/daxpb/test/test.js | 78 ------------------- 1 file changed, 78 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js index b09e5365ceed..5d68439f006f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/test/test.js @@ -78,58 +78,6 @@ tape( 'the function multiplies each element by a scalar constant and adds a scal t.end(); }); -tape( 'the function adds `beta` to each element when `alpha` equals `1.0`', function test( t ) { - var expected; - var actual; - var alpha; - var beta; - var xbuf; - var x; - - xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); - x = vector( xbuf, 5, 1, 0 ); - alpha = scalar2ndarray( 1.0, { - 'dtype': 'float64' - }); - beta = scalar2ndarray( 3.0, { - 'dtype': 'float64' - }); - - actual = daxpb( [ x, alpha, beta ] ); - t.strictEqual( actual, x, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 4.0, 6.0, -2.0, 7.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function multiplies each element by `alpha` when `beta` equals `0.0`', function test( t ) { - var expected; - var actual; - var alpha; - var beta; - var xbuf; - var x; - - xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); - x = vector( xbuf, 5, 1, 0 ); - alpha = scalar2ndarray( 5.0, { - 'dtype': 'float64' - }); - beta = scalar2ndarray( 0.0, { - 'dtype': 'float64' - }); - - actual = daxpb( [ x, alpha, beta ] ); - t.strictEqual( actual, x, 'returns expected value' ); - - expected = new Float64Array( [ -10.0, 5.0, 15.0, -25.0, 20.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - t.end(); -}); - tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { var expected; var actual; @@ -208,32 +156,6 @@ tape( 'the function supports an input ndarray having a non-zero offset', functio t.end(); }); -tape( 'the function supports an input ndarray having a negative stride and non-zero offset', function test( t ) { - var expected; - var actual; - var alpha; - var beta; - var xbuf; - var x; - - xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, 2.0, 6.0 ] ); - x = vector( xbuf, 5, -2, 9 ); - alpha = scalar2ndarray( 5.0, { - 'dtype': 'float64' - }); - beta = scalar2ndarray( 3.0, { - 'dtype': 'float64' - }); - - actual = daxpb( [ x, alpha, beta ] ); - t.strictEqual( actual, x, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, -7.0, 3.0, -22.0, 4.0, 3.0, -1.0, -12.0, 2.0, 33.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - t.end(); -}); - tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) { var expected; var actual; From 615ff492a7aa9448f6a726f2d07b1149ebb7a28b Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 26 May 2026 03:22:44 -0700 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt index 5df623d41aa9..a1b7fb59ca56 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/daxpb/docs/repl.txt @@ -24,9 +24,9 @@ -------- > var buf = [ -2.0, 1.0, 3.0, -5.0 ]; > var x = new {{alias:@stdlib/ndarray/vector/float64}}( buf ); - > var s2a = {{alias:@stdlib/ndarray/from-scalar}}; - > var alpha = s2a( 5.0, { 'dtype': 'float64' } ); - > var beta = s2a( 3.0, { 'dtype': 'float64' } ); + > var opts = { 'dtype': 'float64' }; + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, opts ); + > var beta = {{alias:@stdlib/ndarray/from-scalar}}( 3.0, opts ); > {{alias}}( [ x, alpha, beta ] ) [ -7.0, 8.0, 18.0, -22.0 ]