From 7b4cd51032225e365de8ae2c7274623551d1d7d6 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 16 May 2026 23:09:04 -0700 Subject: [PATCH 1/4] feat: add `blas/ext/base/gaxpb` --- 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 --- --- .../@stdlib/blas/ext/base/gaxpb/README.md | 168 +++++++++ .../ext/base/gaxpb/benchmark/benchmark.js | 103 ++++++ .../base/gaxpb/benchmark/benchmark.ndarray.js | 103 ++++++ .../@stdlib/blas/ext/base/gaxpb/docs/repl.txt | 106 ++++++ .../blas/ext/base/gaxpb/docs/types/index.d.ts | 99 +++++ .../blas/ext/base/gaxpb/docs/types/test.ts | 220 +++++++++++ .../blas/ext/base/gaxpb/examples/index.js | 30 ++ .../blas/ext/base/gaxpb/lib/accessors.js | 71 ++++ .../@stdlib/blas/ext/base/gaxpb/lib/index.js | 57 +++ .../@stdlib/blas/ext/base/gaxpb/lib/main.js | 52 +++ .../blas/ext/base/gaxpb/lib/ndarray.js | 110 ++++++ .../@stdlib/blas/ext/base/gaxpb/package.json | 73 ++++ .../@stdlib/blas/ext/base/gaxpb/test/test.js | 38 ++ .../blas/ext/base/gaxpb/test/test.main.js | 322 ++++++++++++++++ .../blas/ext/base/gaxpb/test/test.ndarray.js | 345 ++++++++++++++++++ 15 files changed, 1897 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md new file mode 100644 index 000000000000..9c2870a6b913 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md @@ -0,0 +1,168 @@ + + +# gaxpb + +> Multiply each element in a strided array by a scalar constant and add a scalar constant. + +
+ +## Usage + +```javascript +var gaxpb = require( '@stdlib/blas/ext/base/gaxpb' ); +``` + +#### gaxpb( N, alpha, beta, x, strideX ) + +Multiplies each element in a strided array `x` by a scalar constant `alpha` and adds a scalar constant `beta`. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +gaxpb( x.length, 5.0, 3.0, x, 1 ); +// x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **alpha**: first scalar constant. +- **beta**: second scalar constant. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to multiply every other element by `alpha` and add `beta`: + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +gaxpb( 4, 5.0, 3.0, x, 2 ); +// x => [ -7.0, 1.0, 18.0, -5.0, 23.0, 0.0, -2.0, -3.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Multiply every other element by 5.0 and add 3.0... +gaxpb( 3, 5.0, 3.0, x1, 2 ); +// x0 => [ 1.0, -7.0, 3.0, -17.0, 5.0, -27.0 ] +``` + +#### gaxpb.ndarray( N, alpha, beta, x, strideX, offsetX ) + +Multiplies each element in a strided array `x` by a scalar constant `alpha` and adds a scalar constant `beta`, using alternative indexing semantics. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, 0 ); +// x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + +gaxpb.ndarray( 3, 5.0, 3.0, x, 1, x.length-3 ); +// x => [ 1.0, -2.0, 3.0, -17.0, 28.0, -27.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `x` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Internally, when `alpha` is `1.0`, the function delegates to [`@stdlib/blas/ext/base/gapx`][@stdlib/blas/ext/base/gapx]. When `beta` is `0.0`, the function delegates to [`@stdlib/blas/base/gscal`][@stdlib/blas/base/gscal]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gaxpb = require( '@stdlib/blas/ext/base/gaxpb' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( x ); + +gaxpb( x.length, 5.0, 3.0, x, 1 ); +console.log( x ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.js new file mode 100644 index 000000000000..d411afaeb0aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gaxpb = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100, 100, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gaxpb( x.length, 5.0, 3.0, x, 1 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + 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( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..b21f91260ba0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/benchmark/benchmark.ndarray.js @@ -0,0 +1,103 @@ +/** +* @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/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gaxpb = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100, 100, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gaxpb( x.length, 5.0, 3.0, x, 1, 0 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + 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( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt new file mode 100644 index 000000000000..b20ada9d2b17 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt @@ -0,0 +1,106 @@ + +{{alias}}( N, alpha, beta, x, strideX ) + Multiplies each element in a strided array by a scalar constant and adds a + scalar constant. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns `x` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + First scalar constant. + + beta: number + Second scalar constant. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + x: Array|TypedArray + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > {{alias}}( x.length, 5.0, 3.0, x, 1 ) + [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > {{alias}}( 4, 5.0, 3.0, x, 2 ) + [ -7.0, 1.0, 18.0, -5.0, 23.0, 0.0, -2.0, -3.0 ] + + // Using view offsets: + > var buf = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + > var x0 = new {{alias:@stdlib/array/float64}}( buf ); + > var offset = x0.BYTES_PER_ELEMENT * 1; + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, offset ); + > {{alias}}( 3, 5.0, 3.0, x1, 2 ) + [ -7.0, 3.0, -17.0, 5.0, -27.0 ] + > x0 + [ 1.0, -7.0, 3.0, -17.0, 5.0, -27.0 ] + + +{{alias}}.ndarray( N, alpha, beta, x, strideX, offsetX ) + Multiplies each element in a strided array by a scalar constant and adds a + scalar constant, using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + First scalar constant. + + beta: number + Second scalar constant. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + x: Array|TypedArray + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; + > {{alias}}.ndarray( x.length, 5.0, 3.0, x, 1, 0 ) + [ -7.0, 8.0, 18.0, -22.0, 23.0, -2.0, -12.0 ] + + // Using an index offset: + > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + > {{alias}}.ndarray( 3, 5.0, 3.0, x, 2, 1 ) + [ 1.0, -7.0, 3.0, -17.0, 5.0, -27.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts new file mode 100644 index 000000000000..cbac858eee23 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts @@ -0,0 +1,99 @@ +/* +* @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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gaxpb`. +*/ +interface Routine { + /** + * Multiplies each element in a strided array by a scalar constant and adds a scalar constant. + * + * @param N - number of indexed elements + * @param alpha - first scalar constant + * @param beta - second scalar constant + * @param x - input array + * @param strideX - stride length + * @returns `x` + * + * @example + * var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + * + * gaxpb( x.length, 5.0, 3.0, x, 1 ); + * // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] + */ + ( N: number, alpha: number, beta: number, x: T, strideX: number ): T; + + /** + * Multiplies each element in a strided array by a scalar constant and adds a scalar constant, using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param alpha - first scalar constant + * @param beta - second scalar constant + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns `x` + * + * @example + * var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + * + * gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, 0 ); + * // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] + */ + ndarray( N: number, alpha: number, beta: number, x: T, strideX: number, offsetX: number ): T; +} + +/** +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* +* @param N - number of indexed elements +* @param alpha - first scalar constant +* @param beta - second scalar constant +* @param x - input array +* @param strideX - stride length +* @returns `x` +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* gaxpb( x.length, 5.0, 3.0, x, 1 ); +* // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, 0 ); +* // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +*/ +declare var gaxpb: Routine; + + +// EXPORTS // + +export = gaxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/test.ts new file mode 100644 index 000000000000..67c5016f5160 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/test.ts @@ -0,0 +1,220 @@ +/* +* @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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import gaxpb = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + + gaxpb( x.length, 5.0, 3.0, x, 1 ); // $ExpectType Float64Array + gaxpb( x.length, 5.0, 3.0, new AccessorArray( x ), 1 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb( '10', 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( true, 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( false, 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( null, 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( undefined, 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( [], 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( {}, 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb( ( x: number ): number => x, 5.0, 3.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb( x.length, '10', 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, true, 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, false, 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, null, 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, undefined, 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, [], 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, {}, 3.0, x, 1 ); // $ExpectError + gaxpb( x.length, ( x: number ): number => x, 3.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb( x.length, 5.0, '10', x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, true, x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, false, x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, null, x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, undefined, x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, [], x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, {}, x, 1 ); // $ExpectError + gaxpb( x.length, 5.0, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + gaxpb( x.length, 5.0, 3.0, 10, 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, '10', 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, true, 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, false, 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, null, 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, undefined, 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, [ '1' ], 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, {}, 1 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb( x.length, 5.0, 3.0, x, '10' ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, true ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, false ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, null ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, undefined ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, [] ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, {} ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gaxpb(); // $ExpectError + gaxpb( x.length ); // $ExpectError + gaxpb( x.length, 5.0 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0 ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x ); // $ExpectError + gaxpb( x.length, 5.0, 3.0, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a numeric array... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, 0 ); // $ExpectType Float64Array + gaxpb.ndarray( x.length, 5.0, 3.0, new AccessorArray( x ), 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( '10', 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( true, 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( false, 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( null, 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( undefined, 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( [], 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( {}, 5.0, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( ( x: number ): number => x, 5.0, 3.0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( x.length, '10', 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, true, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, false, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, null, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, undefined, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, [], 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, {}, 3.0, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, ( x: number ): number => x, 3.0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( x.length, 5.0, '10', x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, true, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, false, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, null, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, undefined, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, [], x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, {}, x, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( x.length, 5.0, 3.0, 10, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, '10', 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, true, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, false, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, null, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, undefined, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, [ '1' ], 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, {}, 1, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( x.length, 5.0, 3.0, x, '10', 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, true, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, false, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, null, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, undefined, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, [], 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, {}, 0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, '10' ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, true ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, false ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, null ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, undefined ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, [] ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, {} ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gaxpb.ndarray(); // $ExpectError + gaxpb.ndarray( x.length ); // $ExpectError + gaxpb.ndarray( x.length, 5.0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1 ); // $ExpectError + gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/examples/index.js new file mode 100644 index 000000000000..addc97dee9e8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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/array/discrete-uniform' ); +var gaxpb = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( x ); + +gaxpb( x.length, 5.0, 3.0, x, 1 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js new file mode 100644 index 000000000000..8dc5e06764b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js @@ -0,0 +1,71 @@ +/** +* @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'; + +// MAIN // + +/** +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - first scalar constant +* @param {number} beta - second scalar constant +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {Object} input array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = gaxpb( 4, 5.0, 3.0, arraylike2object( x ), 2, 1 ); +* // returns {...} +*/ +function gaxpb( N, alpha, beta, x, strideX, offsetX ) { + var xbuf; + var get; + var set; + var ix; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache reference to the element accessors: + get = x.accessors[ 0 ]; + set = x.accessors[ 1 ]; + + ix = offsetX; + for ( i = 0; i < N; i++ ) { + set( xbuf, ix, ( alpha * get( xbuf, ix ) ) + beta ); + ix += strideX; + } + return x; +} + + +// EXPORTS // + +module.exports = gaxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js new file mode 100644 index 000000000000..d56bbaa7d199 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 strided array by a scalar constant and add a scalar constant. +* +* @module @stdlib/blas/ext/base/gaxpb +* +* @example +* var gaxpb = require( '@stdlib/blas/ext/base/gaxpb' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* gaxpb( x.length, 5.0, 3.0, x, 1 ); +* // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +* +* @example +* var gaxpb = require( '@stdlib/blas/ext/base/gaxpb' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* gaxpb.ndarray( x.length, 5.0, 3.0, x, 1, 0 ); +* // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js new file mode 100644 index 000000000000..5670b2069436 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js @@ -0,0 +1,52 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - first scalar constant +* @param {number} beta - second scalar constant +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {NumericArray} input array +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* gaxpb( x.length, 5.0, 3.0, x, 1 ); +* // x => [ -7.0, 8.0, 18.0, -22.0, 23.0, 3.0, -2.0, -12.0 ] +*/ +function gaxpb( N, alpha, beta, x, strideX ) { + return ndarray( N, alpha, beta, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gaxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js new file mode 100644 index 000000000000..25d5194ca4d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js @@ -0,0 +1,110 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var gapx = require( '@stdlib/blas/ext/base/gapx' ).ndarray; +var gscal = require( '@stdlib/blas/base/gscal' ).ndarray; +var accessors = require( './accessors.js' ); + + +// VARIABLES // + +var M = 5; + + +// MAIN // + +/** +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - first scalar constant +* @param {number} beta - second scalar constant +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {NumericArray} input array +* +* @example +* var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; +* +* gaxpb( 3, 5.0, 3.0, x, 1, x.length-3 ); +* // x => [ 1.0, -2.0, 3.0, -17.0, 28.0, -27.0 ] +*/ +function gaxpb( N, alpha, beta, x, strideX, offsetX ) { + var ix; + var m; + var o; + var i; + + if ( N <= 0 ) { + return x; + } + // Fast path: when alpha = 1.0, delegate to gapx (x = x + beta) + if ( alpha === 1.0 ) { + return gapx( N, beta, x, strideX, offsetX ); + } + // Fast path: when beta = 0.0, delegate to gscal (x = alpha * x) + if ( beta === 0.0 ) { + return gscal( N, alpha, x, strideX, offsetX ); + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, alpha, beta, o, strideX, offsetX ); + } + ix = offsetX; + + // Use loop unrolling if the stride is equal to `1`... + if ( strideX === 1 ) { + m = N % M; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + x[ ix ] = ( alpha * x[ ix ] ) + beta; + ix += strideX; + } + } + if ( N < M ) { + return x; + } + for ( i = m; i < N; i += M ) { + x[ ix ] = ( alpha * x[ ix ] ) + beta; + x[ ix+1 ] = ( alpha * x[ ix+1 ] ) + beta; + x[ ix+2 ] = ( alpha * x[ ix+2 ] ) + beta; + x[ ix+3 ] = ( alpha * x[ ix+3 ] ) + beta; + x[ ix+4 ] = ( alpha * x[ ix+4 ] ) + beta; + ix += M; + } + return x; + } + for ( i = 0; i < N; i++ ) { + x[ ix ] = ( alpha * x[ ix ] ) + beta; + ix += strideX; + } + return x; +} + + +// EXPORTS // + +module.exports = gaxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json new file mode 100644 index 000000000000..0ee33ec1e431 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/blas/ext/base/gaxpb", + "version": "0.0.0", + "description": "Multiply each element in a strided array by a scalar constant and add a scalar constant.", + "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", + "linear", + "algebra", + "subroutines", + "multiply", + "add", + "scale", + "transform", + "strided", + "array", + "ndarray", + "vector", + "axpb", + "gaxpb" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.js new file mode 100644 index 000000000000..a03c13436e5c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.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'; + +// MODULES // + +var tape = require( 'tape' ); +var gaxpb = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gaxpb, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gaxpb.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js new file mode 100644 index 000000000000..565026ede2f6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js @@ -0,0 +1,322 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gaxpb = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gaxpb, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gaxpb.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant', function test( t ) { + var expected; + var x; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + expected = [ + 23.0, // 5.0*4.0 + 3.0 + 13.0, // 5.0*2.0 + 3.0 + -12.0, // 5.0*(-3.0) + 3.0 + 28.0, // 5.0*5.0 + 3.0 + -2.0, // 5.0*(-1.0) + 3.0 + 13.0, // 5.0*2.0 + 3.0 + -22.0, // 5.0*(-5.0) + 3.0 + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( x.length, 5.0, 3.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + expected = [ 8.0, 13.0 ]; // [5.0*1.0+3.0, 5.0*2.0+3.0] + + gaxpb( x.length, 5.0, 3.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + expected = [ + 23.0, // 5.0*4.0 + 3.0 + 13.0, // 5.0*2.0 + 3.0 + -12.0, // 5.0*(-3.0) + 3.0 + 28.0, // 5.0*5.0 + 3.0 + -2.0, // 5.0*(-1.0) + 3.0 + 13.0, // 5.0*2.0 + 3.0 + -22.0, // 5.0*(-5.0) + 3.0 + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( x.length, 5.0, 3.0, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + expected = [ 8.0, 13.0 ]; + + gaxpb( x.length, 5.0, 3.0, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = gaxpb( x.length, 5.0, 3.0, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gaxpb( 0, 5.0, 3.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gaxpb( -4, 5.0, 3.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `alpha` equals `1.0`, the function delegates to `gapx` (adds beta to each element)', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + expected = [ 8.0, 1.0, 6.0, 20.0, 9.0, 8.0 ]; // 1.0*x + 5.0 + + gaxpb( x.length, 1.0, 5.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `beta` equals `0.0`, the function delegates to `gscal` (multiplies each element by alpha)', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + expected = [ 15.0, -20.0, 5.0, 75.0, 20.0, 15.0 ]; // 5.0*x + + gaxpb( x.length, 5.0, 0.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + expected = [ + 13.0, // 5.0*2.0 + 3.0 = 13.0 + -3.0, + -22.0, // 5.0*(-5.0) + 3.0 = -22.0 + 7.0, + 33.0 // 5.0*6.0 + 3.0 = 33.0 + ]; + + gaxpb( 3, 5.0, 3.0, x, 2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + expected = [ + 13.0, + -3.0, + -22.0, + 7.0, + 33.0 + ]; + + gaxpb( 3, 5.0, 3.0, toAccessorArray( x ), 2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + expected = [ + 13.0, // 5.0*2.0 + 3.0 + -3.0, + -22.0, // 5.0*(-5.0) + 3.0 + 7.0, + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( 3, 5.0, 3.0, x, -2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + expected = [ + 13.0, + -3.0, + -22.0, + 7.0, + 33.0 + ]; + + gaxpb( 3, 5.0, 3.0, toAccessorArray( x ), -2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + 13.0, // 5.0*2.0 + 3.0 + 3.0, + 23.0, // 5.0*4.0 + 3.0 + 5.0, + 33.0 // 5.0*6.0 + 3.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + gaxpb( 3, 5.0, 3.0, x1, 2 ); + t.deepEqual( x0, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if `stride` is equal to `1`, the function efficiently multiplies by a constant and adds a constant to each element', function test( t ) { + var expected; + var alpha; + var beta; + var x; + var i; + + alpha = 3.0; + beta = 5.0; + x = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = ( alpha * x[ i ] ) + beta; + } + gaxpb( x.length, alpha, beta, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = ( alpha * x[ i ] ) + beta; + } + gaxpb( x.length, alpha, beta, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js new file mode 100644 index 000000000000..d22688511692 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js @@ -0,0 +1,345 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gaxpb = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gaxpb, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gaxpb.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant', function test( t ) { + var expected; + var x; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + expected = [ + 23.0, // 5.0*4.0 + 3.0 + 13.0, // 5.0*2.0 + 3.0 + -12.0, // 5.0*(-3.0) + 3.0 + 28.0, // 5.0*5.0 + 3.0 + -2.0, // 5.0*(-1.0) + 3.0 + 13.0, // 5.0*2.0 + 3.0 + -22.0, // 5.0*(-5.0) + 3.0 + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( x.length, 5.0, 3.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + expected = [ 8.0, 13.0 ]; + + gaxpb( x.length, 5.0, 3.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + expected = [ + 23.0, + 13.0, + -12.0, + 28.0, + -2.0, + 13.0, + -22.0, + 33.0 + ]; + + gaxpb( x.length, 5.0, 3.0, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + expected = [ 8.0, 13.0 ]; + + gaxpb( x.length, 5.0, 3.0, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = gaxpb( x.length, 5.0, 3.0, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gaxpb( 0, 5.0, 3.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gaxpb( -4, 5.0, 3.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `alpha` equals `1.0`, the function delegates to `gapx` (adds beta to each element)', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + expected = [ 8.0, 1.0, 6.0, 20.0, 9.0, 8.0 ]; // 1.0*x + 5.0 + + gaxpb( x.length, 1.0, 5.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `beta` equals `0.0`, the function delegates to `gscal` (multiplies each element by alpha)', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + expected = [ 15.0, -20.0, 5.0, 75.0, 20.0, 15.0 ]; // 5.0*x + + gaxpb( x.length, 5.0, 0.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + expected = [ + 13.0, // 5.0*2.0 + 3.0 + -3.0, + -22.0, // 5.0*(-5.0) + 3.0 + 7.0, + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( 3, 5.0, 3.0, x, 2, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + expected = [ + 13.0, + -3.0, + -22.0, + 7.0, + 33.0 + ]; + + gaxpb( 3, 5.0, 3.0, toAccessorArray( x ), 2, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + expected = [ + 13.0, // 5.0*2.0 + 3.0 + -3.0, + -22.0, // 5.0*(-5.0) + 3.0 + 7.0, + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( 3, 5.0, 3.0, x, -2, x.length-1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + expected = [ + 13.0, + -3.0, + -22.0, + 7.0, + 33.0 + ]; + + gaxpb( 3, 5.0, 3.0, toAccessorArray( x ), -2, x.length-1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an offset parameter', function test( t ) { + var expected; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]; + expected = [ + 1.0, + 13.0, // 5.0*2.0 + 3.0 + 3.0, + 23.0, // 5.0*4.0 + 3.0 + 5.0, + 33.0 // 5.0*6.0 + 3.0 + ]; + + gaxpb( 3, 5.0, 3.0, x, 2, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an offset parameter (accessors)', function test( t ) { + var expected; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]; + expected = [ + 1.0, + 13.0, + 3.0, + 23.0, + 5.0, + 33.0 + ]; + + gaxpb( 3, 5.0, 3.0, toAccessorArray( x ), 2, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if `stride` is equal to `1`, the function efficiently multiplies by a constant and adds a constant to each element', function test( t ) { + var expected; + var alpha; + var beta; + var x; + var i; + + alpha = 3.0; + beta = 5.0; + x = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = ( alpha * x[ i ] ) + beta; + } + gaxpb( x.length, alpha, beta, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = ( alpha * x[ i ] ) + beta; + } + gaxpb( x.length, alpha, beta, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); From 6b9ce84fe6698ec36359dbe72e57dc048ce54255 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 17 May 2026 00:23:38 -0700 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md | 9 ++------- .../@stdlib/blas/ext/base/gaxpb/docs/repl.txt | 4 ++-- .../@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts | 6 +++--- .../@stdlib/blas/ext/base/gaxpb/lib/accessors.js | 8 ++++---- .../@stdlib/blas/ext/base/gaxpb/lib/index.js | 2 +- lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js | 2 +- .../@stdlib/blas/ext/base/gaxpb/lib/ndarray.js | 2 +- .../@stdlib/blas/ext/base/gaxpb/package.json | 2 +- .../@stdlib/blas/ext/base/gaxpb/test/test.main.js | 8 ++++---- .../@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js | 8 ++++---- 10 files changed, 23 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md index 9c2870a6b913..9dc70ad5bc1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md @@ -20,7 +20,7 @@ limitations under the License. # gaxpb -> Multiply each element in a strided array by a scalar constant and add a scalar constant. +> Multiply each element in a strided array by a scalar constant and add a scalar constant to each result.
@@ -76,7 +76,7 @@ gaxpb( 3, 5.0, 3.0, x1, 2 ); #### gaxpb.ndarray( N, alpha, beta, x, strideX, offsetX ) -Multiplies each element in a strided array `x` by a scalar constant `alpha` and adds a scalar constant `beta`, using alternative indexing semantics. +Multiplies each element in a strided array `x` by a scalar constant `alpha` and adds a scalar constant `beta` to each result using alternative indexing semantics. ```javascript var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; @@ -108,7 +108,6 @@ gaxpb.ndarray( 3, 5.0, 3.0, x, 1, x.length-3 ); - If `N <= 0`, both functions return `x` unchanged. - Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). -- Internally, when `alpha` is `1.0`, the function delegates to [`@stdlib/blas/ext/base/gapx`][@stdlib/blas/ext/base/gapx]. When `beta` is `0.0`, the function delegates to [`@stdlib/blas/base/gscal`][@stdlib/blas/base/gscal].
@@ -155,10 +154,6 @@ console.log( x ); [@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor -[@stdlib/blas/ext/base/gapx]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/gapx - -[@stdlib/blas/base/gscal]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/gscal - diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt index b20ada9d2b17..7e726afe9167 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( N, alpha, beta, x, strideX ) Multiplies each element in a strided array by a scalar constant and adds a - scalar constant. + scalar constant to each result. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. @@ -58,7 +58,7 @@ {{alias}}.ndarray( N, alpha, beta, x, strideX, offsetX ) Multiplies each element in a strided array by a scalar constant and adds a - scalar constant, using alternative indexing semantics. + scalar constant to each result using alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts index cbac858eee23..3df8c4dde50f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/docs/types/index.d.ts @@ -32,7 +32,7 @@ type InputArray = NumericArray | Collection | AccessorArrayLike; */ interface Routine { /** - * Multiplies each element in a strided array by a scalar constant and adds a scalar constant. + * Multiplies each element in a strided array by a scalar constant and adds a scalar constant to each result. * * @param N - number of indexed elements * @param alpha - first scalar constant @@ -50,7 +50,7 @@ interface Routine { ( N: number, alpha: number, beta: number, x: T, strideX: number ): T; /** - * Multiplies each element in a strided array by a scalar constant and adds a scalar constant, using alternative indexing semantics. + * Multiplies each element in a strided array by a scalar constant and adds a scalar constant to each result using alternative indexing semantics. * * @param N - number of indexed elements * @param alpha - first scalar constant @@ -70,7 +70,7 @@ interface Routine { } /** -* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant to each result. * * @param N - number of indexed elements * @param alpha - first scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js index 8dc5e06764b2..2e3c8b1d65da 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/accessors.js @@ -21,7 +21,7 @@ // MAIN // /** -* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant to each result. * * @private * @param {PositiveInteger} N - number of indexed elements @@ -38,10 +38,10 @@ * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * -* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; * -* var v = gaxpb( 4, 5.0, 3.0, arraylike2object( x ), 2, 1 ); -* // returns {...} +* var v = gaxpb( 4, 5.0, 3.0, arraylike2object( toAccessorArray( x ) ), 2, 1 ); +* // x => [ 2.0, 8.0, 2.0, -7.0, -2.0, 13.0, 3.0, 23.0 ] */ function gaxpb( N, alpha, beta, x, strideX, offsetX ) { var xbuf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js index d56bbaa7d199..42acf550f5d8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Multiply each element in a strided array by a scalar constant and add a scalar constant. +* Multiply each element in a strided array by a scalar constant and add a scalar constant to each result. * * @module @stdlib/blas/ext/base/gaxpb * diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js index 5670b2069436..0959bfc56b8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/main.js @@ -27,7 +27,7 @@ var ndarray = require( './ndarray.js' ); // MAIN // /** -* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant to each result. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - first scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js index 25d5194ca4d5..238cda8249ad 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/lib/ndarray.js @@ -34,7 +34,7 @@ var M = 5; // MAIN // /** -* Multiplies each element in a strided array by a scalar constant and adds a scalar constant. +* Multiplies each element in a strided array by a scalar constant and adds a scalar constant to each result. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - first scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json index 0ee33ec1e431..0f19cc3a8c88 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/base/gaxpb", "version": "0.0.0", - "description": "Multiply each element in a strided array by a scalar constant and add a scalar constant.", + "description": "Multiply each element in a strided array by a scalar constant and add a scalar constant to each result.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js index 565026ede2f6..e1662fc6a8ea 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js @@ -39,7 +39,7 @@ tape( 'the function has an arity of 5', function test( t ) { t.end(); }); -tape( 'the function multiplies each element by a scalar constant and adds a scalar constant', function test( t ) { +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant to each result', function test( t ) { var expected; var x; @@ -76,7 +76,7 @@ tape( 'the function multiplies each element by a scalar constant and adds a scal t.end(); }); -tape( 'the function multiplies each element by a scalar constant and adds a scalar constant (accessors)', function test( t ) { +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant to each result (accessors)', function test( t ) { var expected; var x; @@ -140,7 +140,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'when `alpha` equals `1.0`, the function delegates to `gapx` (adds beta to each element)', function test( t ) { +tape( 'when `alpha` equals `1.0`, the function add `beta` to each element', function test( t ) { var expected; var x; @@ -153,7 +153,7 @@ tape( 'when `alpha` equals `1.0`, the function delegates to `gapx` (adds beta to t.end(); }); -tape( 'when `beta` equals `0.0`, the function delegates to `gscal` (multiplies each element by alpha)', function test( t ) { +tape( 'when `beta` equals `0.0`, the function multiplies each element by `alpha`', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js index d22688511692..b5c1a872cac6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.ndarray.js @@ -39,7 +39,7 @@ tape( 'the function has an arity of 6', function test( t ) { t.end(); }); -tape( 'the function multiplies each element by a scalar constant and adds a scalar constant', function test( t ) { +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant to each element', function test( t ) { var expected; var x; @@ -76,7 +76,7 @@ tape( 'the function multiplies each element by a scalar constant and adds a scal t.end(); }); -tape( 'the function multiplies each element by a scalar constant and adds a scalar constant (accessors)', function test( t ) { +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant to each element (accessors)', function test( t ) { var expected; var x; @@ -140,7 +140,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'when `alpha` equals `1.0`, the function delegates to `gapx` (adds beta to each element)', function test( t ) { +tape( 'when `alpha` equals `1.0`, the function adds `beta` to each element', function test( t ) { var expected; var x; @@ -153,7 +153,7 @@ tape( 'when `alpha` equals `1.0`, the function delegates to `gapx` (adds beta to t.end(); }); -tape( 'when `beta` equals `0.0`, the function delegates to `gscal` (multiplies each element by alpha)', function test( t ) { +tape( 'when `beta` equals `0.0`, the function multiplies each element by `alpha`', function test( t ) { var expected; var x; From 59e6a2561ed8097226a5e335b1d9460f115c5248 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 17 May 2026 00:28:06 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gaxpb/test/test.main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js index e1662fc6a8ea..5b0d3f8a1603 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/test/test.main.js @@ -178,11 +178,11 @@ tape( 'the function supports specifying a stride', function test( t ) { 6.0 // 2 ]; expected = [ - 13.0, // 5.0*2.0 + 3.0 = 13.0 + 13.0, // 5.0*2.0 + 3.0 = 13.0 -3.0, -22.0, // 5.0*(-5.0) + 3.0 = -22.0 7.0, - 33.0 // 5.0*6.0 + 3.0 = 33.0 + 33.0 // 5.0*6.0 + 3.0 = 33.0 ]; gaxpb( 3, 5.0, 3.0, x, 2 ); From c59762fecb59c4b810b5760fa31b685454a58eaa Mon Sep 17 00:00:00 2001 From: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Date: Sun, 17 May 2026 00:29:04 -0700 Subject: [PATCH 4/4] chore: apply suggestions Co-authored-by: Athan Signed-off-by: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md index 9dc70ad5bc1e..07f6cbab0508 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md @@ -32,7 +32,7 @@ var gaxpb = require( '@stdlib/blas/ext/base/gaxpb' ); #### gaxpb( N, alpha, beta, x, strideX ) -Multiplies each element in a strided array `x` by a scalar constant `alpha` and adds a scalar constant `beta`. +Multiplies each element in a strided array `x` by a scalar constant `alpha` and adds a scalar constant `beta` to each result. ```javascript var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];