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..07f6cbab0508 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gaxpb/README.md @@ -0,0 +1,163 @@ + + +# gaxpb + +> Multiply each element in a strided array by a scalar constant and add a scalar constant to each result. + +
+ +## 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` to each result. + +```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` 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 ]; + +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]). + +
+ + + +
+ +## 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..7e726afe9167 --- /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 to each result. + + 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 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 + 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..3df8c4dde50f --- /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 to each result. + * + * @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 to each result 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 to each result. +* +* @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..2e3c8b1d65da --- /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 to each result. +* +* @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 = [ 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( 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; + 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..42acf550f5d8 --- /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 to each result. +* +* @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..0959bfc56b8a --- /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 to each result. +* +* @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..238cda8249ad --- /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 to each result. +* +* @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..0f19cc3a8c88 --- /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 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", + "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..5b0d3f8a1603 --- /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 to each result', 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 to each result (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 add `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 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..b5c1a872cac6 --- /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 to each element', 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 to each element (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 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 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(); +});