diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/README.md b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/README.md new file mode 100644 index 000000000000..c6e107b7ea04 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/README.md @@ -0,0 +1,212 @@ + + +# gwxpy + +> Add elements of a strided array `x` to the corresponding elements of a strided array `y` and assign the results to elements in a strided array `w`. + +
+ +This BLAS extension implements the operation + + + +```math +\mathbf{w} = \mathbf{x} + \mathbf{y} +``` + + + +This API is a specialized version of the package [`@stdlib/blas/ext/base/gwaxpby`][@stdlib/blas/ext/base/gwaxpby] with `α = 1` and `β = 1` and performs element-wise addition between two vectors with assignment to a third vector. + +
+ + + +
+ +## Usage + +```javascript +var gwxpy = require( '@stdlib/blas/ext/base/gwxpy' ); +``` + +#### gwxpy( N, x, strideX, y, strideY, w, strideW ) + +Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w`. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gwxpy( x.length, x, 1, y, 1, w, 1 ); +// w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: first input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **y**: second input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideY**: stride length for `y`. +- **w**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideW**: stride length for `w`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to add every other element of `x` to every other element of `y` and assign the results to every other element of `w`: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gwxpy( 3, x, 2, y, 2, w, 2 ); +// w => [ 8.0, 0.0, 12.0, 0.0, 16.0, 0.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 arrays... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +var w0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element +var w1 = new Float64Array( w0.buffer, w0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +gwxpy( 3, x1, 1, y1, 1, w1, 1 ); +// w0 => [ 0.0, 0.0, 0.0, 11.0, 13.0, 15.0 ] +``` + + + +#### gwxpy.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, w, strideW, offsetW ) + + + +Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w` using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); +// w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. +- **offsetW**: starting index for `w`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to add the last three elements of `x` to the last three elements of `y` and assign the results to the last three elements of `w`: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gwxpy.ndarray( 3, x, 1, x.length-3, y, 1, y.length-3, w, 1, w.length-3 ); +// w => [ 0.0, 0.0, 11.0, 13.0, 15.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `w` 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 gwxpy = require( '@stdlib/blas/ext/base/gwxpy' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( x ); + +var y = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( y ); + +var w = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( w ); + +gwxpy( x.length, x, 1, y, 1, w, 1 ); +console.log( w ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/benchmark/benchmark.js new file mode 100644 index 000000000000..03f0b72b6d89 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @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 gwxpy = 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 ); + var y = uniform( len, -100, 100, options ); + var w = uniform( len, -100, 100, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = gwxpy( x.length, x, 1, y, 1, w, 1 ); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ 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/gwxpy/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..8fa86e92ad12 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @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 gwxpy = 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 ); + var y = uniform( len, -100, 100, options ); + var w = uniform( len, -100, 100, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ 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/gwxpy/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/repl.txt new file mode 100644 index 000000000000..fcf54684f4ef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/repl.txt @@ -0,0 +1,141 @@ + +{{alias}}( N, x, strideX, y, strideY, w, strideW ) + Adds elements of a strided array `x` to the corresponding elements of a + strided array `y` and assigns the results to elements in a strided array + `w`. + + The `N` and stride parameters determine which elements in the strided arrays + 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 `w` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Stride length for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Stride length for `y`. + + w: Array|TypedArray + Output array. + + strideW: integer + Stride length for `w`. + + Returns + ------- + w: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( x.length, x, 1, y, 1, w, 1 ) + [ 3.0, 5.0, 7.0, 9.0, 11.0 ] + + // Using `N` and stride parameters: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + > w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 3, x, 2, y, 2, w, 2 ) + [ 8.0, 0.0, 12.0, 0.0, 16.0, 0.0 ] + + // Using view offsets: + > var bufX = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var bufY = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + > var bufW = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > var x0 = new {{alias:@stdlib/array/float64}}( bufX ); + > var y0 = new {{alias:@stdlib/array/float64}}( bufY ); + > var w0 = new {{alias:@stdlib/array/float64}}( bufW ); + > var offsetX = x0.BYTES_PER_ELEMENT * 1; + > var offsetY = y0.BYTES_PER_ELEMENT * 2; + > var offsetW = w0.BYTES_PER_ELEMENT * 3; + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, offsetX ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, offsetY ); + > var w1 = new {{alias:@stdlib/array/float64}}( w0.buffer, offsetW ); + > {{alias}}( 3, x1, 1, y1, 1, w1, 1 ) + [ 11.0, 13.0, 15.0 ] + > w0 + [ 0.0, 0.0, 0.0, 11.0, 13.0, 15.0 ] + + +{{alias}}.ndarray( N, x,strideX,offsetX, y,strideY,offsetY, w,strideW,offsetW ) + Adds elements of a strided array `x` to the corresponding elements of a + strided array `y` and assigns the results to elements in a strided array `w` + using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + w: Array|TypedArray + Output array. + + strideW: integer + Stride length for `w`. + + offsetW: integer + Starting index for `w`. + + Returns + ------- + w: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ) + [ 3.0, 5.0, 7.0, 9.0, 11.0 ] + + // Using index offsets: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + > w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, x, 1, 3, y, 1, 3, w, 1, 3 ) + [ 0.0, 0.0, 0.0, 14.0, 16.0, 18.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/types/index.d.ts new file mode 100644 index 000000000000..d19a69b88a1e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/types/index.d.ts @@ -0,0 +1,115 @@ +/* +* @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 `gwxpy`. +*/ +interface Routine { + /** + * Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w`. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param y - second input array + * @param strideY - `y` stride length + * @param w - output array + * @param strideW - `w` stride length + * @returns `w` + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + * var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gwxpy( x.length, x, 1, y, 1, w, 1 ); + * // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] + */ + ( N: number, x: T, strideX: number, y: U, strideY: number, w: V, strideW: number ): V; + + /** + * Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @param w - output array + * @param strideW - `w` stride length + * @param offsetW - starting index for `w` + * @returns `w` + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + * var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + * // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] + */ + ndarray( N: number, x: T, strideX: number, offsetX: number, y: U, strideY: number, offsetY: number, w: V, strideW: number, offsetW: number ): V; +} + +/** +* Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w`. +* +* @param N - number of indexed elements +* @param x - first input array +* @param strideX - `x` stride length +* @param y - second input array +* @param strideY - `y` stride length +* @param w - output array +* @param strideW - `w` stride length +* @returns `w` +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy( x.length, x, 1, y, 1, w, 1 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +*/ +declare var gwxpy: Routine; + + +// EXPORTS // + +export = gwxpy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/types/test.ts new file mode 100644 index 000000000000..4199e6bc3664 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/docs/types/test.ts @@ -0,0 +1,350 @@ +/* +* @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 gwxpy = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy( x.length, x, 1, y, 1, w, 1 ); // $ExpectType Float64Array + gwxpy( x.length, new AccessorArray( x ), 1, new AccessorArray( y ), 1, new AccessorArray( w ), 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy( '10', x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( true, x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( false, x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( null, x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( undefined, x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( [], x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( {}, x, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( ( x: number ): number => x, x, 1, y, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy( 10, 10, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, '10', 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, true, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, false, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, null, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, undefined, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, [ '1' ], 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, {}, 1, y, 1, w, 1 ); // $ExpectError + gwxpy( 10, ( x: number ): number => x, 1, y, 1, w, 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy( x.length, x, '10', y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, true, y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, false, y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, null, y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, undefined, y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, [], y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, {}, y, 1, w, 1 ); // $ExpectError + gwxpy( x.length, x, ( x: number ): number => x, y, 1, w, 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 ); + const w = new Float64Array( 10 ); + + gwxpy( 10, x, 1, 10, 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, '10', 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, true, 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, false, 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, null, 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, undefined, 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, [ '1' ], 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, {}, 1, w, 1 ); // $ExpectError + gwxpy( 10, x, 1, ( x: number ): number => x, 1, w, 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy( x.length, x, 1, y, '10', w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, true, w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, false, w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, null, w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, undefined, w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, [], w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, {}, w, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, ( x: number ): number => x, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + gwxpy( 10, x, 1, y, 1, 10, 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, '10', 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, true, 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, false, 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, null, 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, undefined, 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, [ '1' ], 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, {}, 1 ); // $ExpectError + gwxpy( 10, x, 1, y, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy( x.length, x, 1, y, 1, w, '10' ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, true ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, false ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, null ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, undefined ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, [] ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, {} ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, ( 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy(); // $ExpectError + gwxpy( x.length ); // $ExpectError + gwxpy( x.length, x ); // $ExpectError + gwxpy( x.length, x, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y ); // $ExpectError + gwxpy( x.length, x, 1, y, 1 ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w ); // $ExpectError + gwxpy( x.length, x, 1, y, 1, w, 1, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectType Float64Array + gwxpy.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0, new AccessorArray( w ), 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( '10', x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( true, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( false, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( null, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( undefined, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( [], x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( {}, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( 10, 10, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, '10', 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, true, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, false, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, null, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, undefined, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, [ '1' ], 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, {}, 1, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, ( x: number ): number => x, 1, 0, y, 1, 0, w, 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, '10', 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, true, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, false, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, null, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, undefined, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, [], 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, {}, 0, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, 1, '10', y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, true, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, false, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, null, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, undefined, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, [], y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, {}, y, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( 10, x, 1, 0, 10, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, '10', 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, false, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, null, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, undefined, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, [ '1' ], 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, {}, 1, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, ( x: number ): number => x, 1, 0, w, 1, 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, 1, 0, y, '10', 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, true, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, false, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, null, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, undefined, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, [], 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, {}, 0, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, 1, 0, y, 1, '10', w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, true, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, false, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, null, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, undefined, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, [], w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, {}, w, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, 10, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, '10', 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, true, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, false, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, null, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, undefined, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, {}, 1, 0 ); // $ExpectError + gwxpy.ndarray( 10, x, 1, 0, y, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, '10', 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, true, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, false, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, null, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, undefined, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, [], 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, {}, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, '10' ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, true ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, false ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, null ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, undefined ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, [] ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, {} ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 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 ); + const y = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gwxpy.ndarray(); // $ExpectError + gwxpy.ndarray( x.length ); // $ExpectError + gwxpy.ndarray( x.length, x ); // $ExpectError + gwxpy.ndarray( x.length, x, 1 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1 ); // $ExpectError + gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/examples/index.js new file mode 100644 index 000000000000..5930014df8db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 gwxpy = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( x ); + +var y = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( y ); + +var w = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( w ); + +gwxpy( x.length, x, 1, y, 1, w, 1 ); +console.log( w ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/accessors.js new file mode 100644 index 000000000000..7821a87747f6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/accessors.js @@ -0,0 +1,93 @@ +/** +* @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 // + +/** +* Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w`. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - first input array object +* @param {Collection} x.data - first input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Object} y - second input array object +* @param {Collection} y.data - second input array data +* @param {Array} y.accessors - array element accessors +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {Object} w - output array object +* @param {Collection} w.data - output array data +* @param {Array} w.accessors - array element accessors +* @param {integer} strideW - `w` stride length +* @param {NonNegativeInteger} offsetW - starting `w` index +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy( x.length, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0, arraylike2object( toAccessorArray( w ) ), 1, 0 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +*/ +function gwxpy( N, x, strideX, offsetX, y, strideY, offsetY, w, strideW, offsetW ) { // eslint-disable-line max-len + var xbuf; + var ybuf; + var wbuf; + var xget; + var yget; + var wset; + var ix; + var iy; + var iw; + var i; + + // Cache references to array data: + xbuf = x.data; + ybuf = y.data; + wbuf = w.data; + + // Cache references to element accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + wset = w.accessors[ 1 ]; + + ix = offsetX; + iy = offsetY; + iw = offsetW; + for ( i = 0; i < N; i++ ) { + wset( wbuf, iw, xget( xbuf, ix ) + yget( ybuf, iy ) ); + ix += strideX; + iy += strideY; + iw += strideW; + } + return w; +} + + +// EXPORTS // + +module.exports = gwxpy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/index.js new file mode 100644 index 000000000000..dc36bf8a82de --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Add elements of a strided array `x` to the corresponding elements of a strided array `y` and assign the results to elements in a strided array `w`. +* +* @module @stdlib/blas/ext/base/gwxpy +* +* @example +* var gwxpy = require( '@stdlib/blas/ext/base/gwxpy' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy( x.length, x, 1, y, 1, w, 1 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +* +* @example +* var gwxpy = require( '@stdlib/blas/ext/base/gwxpy' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.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/gwxpy/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/main.js new file mode 100644 index 000000000000..a506714c6331 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 // + +/** +* Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NumericArray} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NumericArray} w - output array +* @param {integer} strideW - `w` stride length +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy( x.length, x, 1, y, 1, w, 1 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +*/ +function gwxpy( N, x, strideX, y, strideY, w, strideW ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), w, strideW, stride2offset( N, strideW ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gwxpy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/ndarray.js new file mode 100644 index 000000000000..9ee72a099831 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/lib/ndarray.js @@ -0,0 +1,121 @@ +/** +* @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 accessors = require( './accessors.js' ); + + +// VARIABLES // + +var M = 5; + + +// MAIN // + +/** +* Adds elements of a strided array `x` to the corresponding elements of a strided array `y` and assigns the results to elements in a strided array `w` using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NumericArray} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {NumericArray} w - output array +* @param {integer} strideW - `w` stride length +* @param {NonNegativeInteger} offsetW - starting `w` index +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); +* // w => [ 3.0, 5.0, 7.0, 9.0, 11.0 ] +*/ +function gwxpy( N, x, strideX, offsetX, y, strideY, offsetY, w, strideW, offsetW ) { // eslint-disable-line max-len + var ix; + var iy; + var iw; + var ox; + var oy; + var ow; + var m; + var i; + + if ( N <= 0 ) { + return w; + } + ox = arraylike2object( x ); + oy = arraylike2object( y ); + ow = arraylike2object( w ); + if ( ox.accessorProtocol || oy.accessorProtocol || ow.accessorProtocol ) { + accessors( N, ox, strideX, offsetX, oy, strideY, offsetY, ow, strideW, offsetW ); // eslint-disable-line max-len + return w; + } + ix = offsetX; + iy = offsetY; + iw = offsetW; + + // Use loop unrolling if all strides are equal to `1`... + if ( strideX === 1 && strideY === 1 && strideW === 1 ) { + m = N % M; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + w[ iw ] = x[ ix ] + y[ iy ]; + ix += strideX; + iy += strideY; + iw += strideW; + } + } + if ( N < M ) { + return w; + } + for ( i = m; i < N; i += M ) { + w[ iw ] = x[ ix ] + y[ iy ]; + w[ iw+1 ] = x[ ix+1 ] + y[ iy+1 ]; + w[ iw+2 ] = x[ ix+2 ] + y[ iy+2 ]; + w[ iw+3 ] = x[ ix+3 ] + y[ iy+3 ]; + w[ iw+4 ] = x[ ix+4 ] + y[ iy+4 ]; + ix += M; + iy += M; + iw += M; + } + return w; + } + for ( i = 0; i < N; i++ ) { + w[ iw ] = x[ ix ] + y[ iy ]; + ix += strideX; + iy += strideY; + iw += strideW; + } + return w; +} + + +// EXPORTS // + +module.exports = gwxpy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/package.json b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/package.json new file mode 100644 index 000000000000..57c54e2ee671 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/blas/ext/base/gwxpy", + "version": "0.0.0", + "description": "Add elements of a strided array `x` to the corresponding elements of a strided array `y` and assign the results to elements in a strided array `w`.", + "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", + "add", + "sum", + "strided", + "array", + "ndarray", + "vector", + "wxpy", + "gwxpy" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.js new file mode 100644 index 000000000000..091565fb45c4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/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 gwxpy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gwxpy, '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 gwxpy.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.main.js new file mode 100644 index 000000000000..b94a65fab0dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.main.js @@ -0,0 +1,446 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gwxpy = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gwxpy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gwxpy.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function adds elements of `x` to the corresponding elements of `y` and assigns the results to elements in `w`', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0, // 3.0 + 4.0 + 9.0, // 4.0 + 5.0 + 11.0 // 5.0 + 6.0 + ]; + + gwxpy( x.length, x, 1, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + y = [ 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ 6.0, 8.0 ]; + + gwxpy( x.length, x, 1, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function adds elements of `x` to the corresponding elements of `y` and assigns the results to elements in `w` (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0, // 3.0 + 4.0 + 9.0, // 4.0 + 5.0 + 11.0 // 5.0 + 6.0 + ]; + + gwxpy( x.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + y = [ 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ 6.0, 8.0 ]; + + gwxpy( x.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 5.0, 6.0, 7.0, 8.0, 9.0 ]; + w = zeros( x.length ); + out = gwxpy( x.length, x, 1, y, 1, w, 1 ); + + t.strictEqual( out, w, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `w` unchanged', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + w = [ 7.0, 8.0, 9.0 ]; + expected = [ 7.0, 8.0, 9.0 ]; + + gwxpy( 0, x, 1, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + gwxpy( -4, x, 1, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 6.0, // 3.0 + 3.0 + 9.0 // 5.0 + 4.0 + ]; + + gwxpy( 3, x, 2, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 6.0, // 3.0 + 3.0 + 9.0 // 5.0 + 4.0 + ]; + + gwxpy( 3, toAccessorArray( x ), 2, toAccessorArray( y ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 30.0, + 3.0, // 1 + 10.0, + 4.0 // 2 + ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 1, y, 2, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 30.0, + 3.0, // 1 + 10.0, + 4.0 // 2 + ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, toAccessorArray( x ), 1, toAccessorArray( y ), 2, toAccessorArray( w ), 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `w` stride', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + w = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 3.0, // 1.0 + 2.0 + 30.0, + 5.0, // 2.0 + 3.0 + 10.0, + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 1, y, 1, w, 2 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `w` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + w = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 3.0, // 1.0 + 2.0 + 30.0, + 5.0, // 2.0 + 3.0 + 10.0, + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( w ), 2 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + var w; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 4.0, // 2 + 3.0, // 1 + 2.0 // 0 + ]); + w = new Float64Array( 3 ); + expected = new Float64Array([ + 5.0, // 1.0 + 4.0 + 6.0, // 3.0 + 3.0 + 7.0 // 5.0 + 2.0 + ]); + + gwxpy( 3, x, -2, y, -1, w, -1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]; + y = [ + 4.0, // 2 + 3.0, // 1 + 2.0 // 0 + ]; + w = new Float64Array( 3 ); + expected = new Float64Array([ + 5.0, // 1.0 + 4.0 + 6.0, // 3.0 + 3.0 + 7.0 // 5.0 + 2.0 + ]); + + gwxpy( 3, toAccessorArray( x ), -2, toAccessorArray( y ), -1, toAccessorArray( w ), -1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var y0; + var w0; + var x1; + var y1; + var w1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, + 6.0 + ]); + y0 = new Float64Array([ + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0, // 2 + 12.0 + ]); + w0 = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); + w1 = new Float64Array( w0.buffer, w0.BYTES_PER_ELEMENT*3 ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 11.0, // 2.0 + 9.0 + 13.0, // 3.0 + 10.0 + 15.0 // 4.0 + 11.0 + ]); + + gwxpy( 3, x1, 1, y1, 1, w1, 1 ); + t.deepEqual( w0, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if all strides are equal to `1`, the function efficiently adds elements of `x` to the corresponding elements of `y` and assigns the results to elements in `w`', function test( t ) { + var expected; + var x; + var y; + var w; + var i; + + x = new Float64Array( 100 ); + y = new Float64Array( 100 ); + w = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + expected[ i ] = x[ i ] + y[ i ]; + } + gwxpy( x.length, x, 1, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + y = new Float64Array( 240 ); + w = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + expected[ i ] = x[ i ] + y[ i ]; + } + gwxpy( x.length, x, 1, y, 1, w, 1 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.ndarray.js new file mode 100644 index 000000000000..8113683d6ebc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwxpy/test/test.ndarray.js @@ -0,0 +1,518 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gwxpy = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gwxpy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gwxpy.length, 10, 'has expected arity' ); + t.end(); +}); + +tape( 'the function adds elements of `x` to the corresponding elements of `y` and assigns the results to elements in `w`', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0, // 3.0 + 4.0 + 9.0, // 4.0 + 5.0 + 11.0 // 5.0 + 6.0 + ]; + + gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + y = [ 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ 6.0, 8.0 ]; + + gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function adds elements of `x` to the corresponding elements of `y` and assigns the results to elements in `w` (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0, // 3.0 + 4.0 + 9.0, // 4.0 + 5.0 + 11.0 // 5.0 + 6.0 + ]; + + gwxpy( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + y = [ 5.0, 6.0 ]; + w = zeros( x.length ); + expected = [ 6.0, 8.0 ]; + + gwxpy( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 5.0, 6.0, 7.0, 8.0, 9.0 ]; + w = zeros( x.length ); + out = gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + + t.strictEqual( out, w, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `w` unchanged', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + w = [ 7.0, 8.0, 9.0 ]; + expected = [ 7.0, 8.0, 9.0 ]; + + gwxpy( 0, x, 1, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + gwxpy( -4, x, 1, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 6.0, // 3.0 + 3.0 + 9.0 // 5.0 + 4.0 + ]; + + gwxpy( 3, x, 2, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 6.0, // 3.0 + 3.0 + 9.0 // 5.0 + 4.0 + ]; + + gwxpy( 3, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 30.0, + 3.0, // 1 + 10.0, + 4.0 // 2 + ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 1, 0, y, 2, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 30.0, + 3.0, // 1 + 10.0, + 4.0 // 2 + ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `w` stride', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + w = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 3.0, // 1.0 + 2.0 + 30.0, + 5.0, // 2.0 + 3.0 + 10.0, + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 1, 0, y, 1, 0, w, 2, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `w` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + w = [ + 0.0, // 0 + 30.0, + 0.0, // 1 + 10.0, + 0.0 // 2 + ]; + expected = [ + 3.0, // 1.0 + 2.0 + 30.0, + 5.0, // 2.0 + 3.0 + 10.0, + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( w ), 2, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]; + y = [ + 4.0, // 2 + 3.0, // 1 + 2.0 // 0 + ]; + w = zeros( 3 ); + expected = [ + 5.0, // 1.0 + 4.0 + 6.0, // 3.0 + 3.0 + 7.0 // 5.0 + 2.0 + ]; + + gwxpy( 3, x, -2, x.length-1, y, -1, y.length-1, w, -1, w.length-1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]; + y = [ + 4.0, // 2 + 3.0, // 1 + 2.0 // 0 + ]; + w = zeros( 3 ); + expected = [ + 5.0, // 1.0 + 4.0 + 6.0, // 3.0 + 3.0 + 7.0 // 5.0 + 2.0 + ]; + + gwxpy( 3, toAccessorArray( x ), -2, x.length-1, toAccessorArray( y ), -1, y.length-1, toAccessorArray( w ), -1, w.length-1 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 0.0, + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 6.0, // 3.0 + 3.0 + 9.0 // 5.0 + 4.0 + ]; + + gwxpy( 3, x, 2, 1, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 0.0, + 2.0, // 0 + 3.0, // 1 + 4.0 // 2 + ]; + w = zeros( 3 ); + expected = [ + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 1, 0, y, 1, 1, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `w` offset', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + w = [ + 0.0, + 0.0, + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + expected = [ + 0.0, + 0.0, + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 1, 0, y, 1, 0, w, 1, 2 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var x; + var y; + var w; + + x = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]; + y = [ + 0.0, + 0.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 0.0 + ]; + w = [ + 0.0, + 0.0, + 0.0, + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]; + expected = [ + 0.0, + 0.0, + 0.0, + 3.0, // 1.0 + 2.0 + 5.0, // 2.0 + 3.0 + 7.0 // 3.0 + 4.0 + ]; + + gwxpy( 3, x, 2, 1, y, 1, 2, w, 1, 3 ); + t.deepEqual( w, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if all strides are equal to `1`, the function efficiently adds elements of `x` to the corresponding elements of `y` and assigns the results to elements in `w`', function test( t ) { + var expected; + var x; + var y; + var w; + var i; + + x = new Float64Array( 100 ); + y = new Float64Array( 100 ); + w = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + expected[ i ] = x[ i ] + y[ i ]; + } + gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + y = new Float64Array( 240 ); + w = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + expected[ i ] = x[ i ] + y[ i ]; + } + gwxpy( x.length, x, 1, 0, y, 1, 0, w, 1, 0 ); + t.deepEqual( w, expected, 'returns expected value' ); + + t.end(); +});