From bff6b2d44aff1a77249e21017cfc9c1f0d9e659c Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 1 Nov 2026 12:04:31 -0700 Subject: [PATCH] feat: add `blas/ext/base/ghad` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/ghad/README.md | 210 +++++++ .../blas/ext/base/ghad/benchmark/benchmark.js | 105 ++++ .../base/ghad/benchmark/benchmark.ndarray.js | 105 ++++ .../@stdlib/blas/ext/base/ghad/docs/repl.txt | 152 +++++ .../blas/ext/base/ghad/docs/types/index.d.ts | 121 ++++ .../blas/ext/base/ghad/docs/types/test.ts | 418 ++++++++++++++ .../blas/ext/base/ghad/examples/index.js | 36 ++ .../blas/ext/base/ghad/lib/accessors.js | 97 ++++ .../@stdlib/blas/ext/base/ghad/lib/index.js | 61 ++ .../@stdlib/blas/ext/base/ghad/lib/main.js | 58 ++ .../@stdlib/blas/ext/base/ghad/lib/ndarray.js | 128 +++++ .../@stdlib/blas/ext/base/ghad/package.json | 73 +++ .../@stdlib/blas/ext/base/ghad/test/test.js | 38 ++ .../blas/ext/base/ghad/test/test.main.js | 472 +++++++++++++++ .../blas/ext/base/ghad/test/test.ndarray.js | 544 ++++++++++++++++++ 15 files changed, 2618 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/README.md b/lib/node_modules/@stdlib/blas/ext/base/ghad/README.md new file mode 100644 index 000000000000..0eb2f84abda1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/README.md @@ -0,0 +1,210 @@ + + +# ghad + +> Multiply the Hadamard product of strided arrays `x` and `y` by a constant and add the result to a strided array `z` multiplied by a constant. + +
+ +This BLAS extension implements the operation + + + +```math +\mathbf{z} = \alpha \mathbf{x} \odot \mathbf{y} + \beta \mathbf{z} +``` + + + +where `⊙` denotes the [Hadamard product][hadamard-product]. + +
+ + + +
+ +## Usage + +```javascript +var ghad = require( '@stdlib/blas/ext/base/ghad' ); +``` + +#### ghad( N, alpha, x, strideX, y, strideY, beta, z, strideZ ) + +Multiplies the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant. + +```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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + +ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); +// z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **alpha**: first scalar constant. +- **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`. +- **beta**: second scalar constant. +- **z**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideZ**: stride length for `z`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to multiply the Hadamard product of every other element in `x` and `y` by a constant and add the result to every other element in `z` multiplied by a constant: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 2.0, 1.0, 3.0, 1.0, 4.0, 1.0 ]; +var z = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + +ghad( 3, 2.0, x, 2, y, 2, 3.0, z, 2 ); +// z => [ 7.0, 1.0, 21.0, 1.0, 43.0, 1.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, 2.0, 3.0, 4.0, 12.0 ] ); +var z0 = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.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 z1 = new Float64Array( z0.buffer, z0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +ghad( 3, 2.0, x1, 1, y1, 1, 3.0, z1, 1 ); +// z0 => [ 1.0, 1.0, 1.0, 11.0, 21.0, 35.0 ] +``` + + + +#### ghad.ndarray( N, alpha, x, strideX, offsetX, y, strideY, offsetY, beta, z, strideZ, offsetZ ) + + + +Multiplies the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + +ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); +// z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. +- **offsetZ**: starting index for `z`. + +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 multiply the Hadamard product of the last three elements in `x` and `y` by a constant and add the result to the last three elements in `z` multiplied by a constant: + +```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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + +ghad.ndarray( 3, 2.0, x, 1, 2, y, 1, 2, 3.0, z, 1, 2 ); +// z => [ 1.0, 1.0, 51.0, 75.0, 103.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `z` 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 ghad = require( '@stdlib/blas/ext/base/ghad' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, -100, 100, opts ); +var y = discreteUniform( 10, -100, 100, opts ); +var z = discreteUniform( 10, -100, 100, opts ); + +console.log( x ); +console.log( y ); +console.log( z ); + +ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); +console.log( z ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/benchmark/benchmark.js new file mode 100644 index 000000000000..52e842772009 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/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 ghad = 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.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + var z = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); + if ( isnan( out[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ 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/ghad/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..a437113ec302 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/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 ghad = 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.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + var z = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = ghad( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + if ( isnan( out[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ 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/ghad/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/repl.txt new file mode 100644 index 000000000000..2399436bed9d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/repl.txt @@ -0,0 +1,152 @@ + +{{alias}}( N, alpha, x, strideX, y, strideY, beta, z, strideZ ) + Multiplies the Hadamard product of strided arrays `x` and `y` by a constant + and adds the result to a strided array `z` multiplied by a constant. + + 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 `z` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + First scalar constant. + + x: Array|TypedArray + First input array. + + strideX: integer + Stride length for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Stride length for `y`. + + beta: number + Second scalar constant. + + z: Array|TypedArray + Output array. + + strideZ: integer + Stride length for `z`. + + Returns + ------- + z: 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + > {{alias}}( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ) + [ 7.0, 15.0, 27.0, 43.0, 63.0 ] + + // Using `N` and stride parameters: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 2.0, 1.0, 3.0, 1.0, 4.0, 1.0 ]; + > z = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + > {{alias}}( 3, 2.0, x, 2, y, 2, 3.0, z, 2 ) + [ 7.0, 1.0, 21.0, 1.0, 43.0, 1.0 ] + + // Using view offsets: + > var bufX = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var bufY = [ 7.0, 8.0, 2.0, 3.0, 4.0, 12.0 ]; + > var bufZ = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + > var x0 = new {{alias:@stdlib/array/float64}}( bufX ); + > var y0 = new {{alias:@stdlib/array/float64}}( bufY ); + > var z0 = new {{alias:@stdlib/array/float64}}( bufZ ); + > var offsetX = x0.BYTES_PER_ELEMENT * 1; + > var offsetY = y0.BYTES_PER_ELEMENT * 2; + > var offsetZ = z0.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 z1 = new {{alias:@stdlib/array/float64}}( z0.buffer, offsetZ ); + > {{alias}}( 3, 2.0, x1, 1, y1, 1, 3.0, z1, 1 ) + [ 11.0, 21.0, 35.0 ] + > z0 + [ 1.0, 1.0, 1.0, 11.0, 21.0, 35.0 ] + + +{{alias}}.ndarray( N, alpha, x, sx, ox, y, sy, oy, beta, z, sz, oz ) + Multiplies the Hadamard product of strided arrays `x` and `y` by a constant + and adds the result to a strided array `z` multiplied by a constant 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. + + alpha: number + First scalar constant. + + x: Array|TypedArray + First input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + y: Array|TypedArray + Second input array. + + sy: integer + Stride length for `y`. + + oy: integer + Starting index for `y`. + + beta: number + Second scalar constant. + + z: Array|TypedArray + Output array. + + sz: integer + Stride length for `z`. + + oz: integer + Starting index for `z`. + + Returns + ------- + z: 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + > {{alias}}.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ) + [ 7.0, 15.0, 27.0, 43.0, 63.0 ] + + // Using index offsets: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ]; + > z = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]; + > {{alias}}.ndarray( 3, 2.0, x, 1, 3, y, 1, 3, 3.0, z, 1, 3 ) + [ 1.0, 1.0, 1.0, 19.0, 23.0, 27.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/index.d.ts new file mode 100644 index 000000000000..97f0df98016a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `ghad`. +*/ +interface Routine { + /** + * Multiplies the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant. + * + * @param N - number of indexed elements + * @param alpha - first scalar constant + * @param x - first input array + * @param strideX - `x` stride length + * @param y - second input array + * @param strideY - `y` stride length + * @param beta - second scalar constant + * @param z - output array + * @param strideZ - `z` stride length + * @returns `z` + * + * @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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + * + * ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); + * // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] + */ + ( N: number, alpha: number, x: InputArray, strideX: number, y: InputArray, strideY: number, beta: number, z: T, strideZ: number ): T; + + /** + * Multiplies the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param alpha - first scalar constant + * @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 beta - second scalar constant + * @param z - output array + * @param strideZ - `z` stride length + * @param offsetZ - starting index for `z` + * @returns `z` + * + * @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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + * + * ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + * // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] + */ + ndarray( N: number, alpha: number, x: InputArray, strideX: number, offsetX: number, y: InputArray, strideY: number, offsetY: number, beta: number, z: T, strideZ: number, offsetZ: number ): T; +} + +/** +* Multiplies the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant. +* +* @param N - number of indexed elements +* @param alpha - first scalar constant +* @param x - first input array +* @param strideX - `x` stride length +* @param y - second input array +* @param strideY - `y` stride length +* @param beta - second scalar constant +* @param z - output array +* @param strideZ - `z` stride length +* @returns `z` +* +* @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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +*/ +declare var ghad: Routine; + + +// EXPORTS // + +export = ghad; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/test.ts new file mode 100644 index 000000000000..0e9c8da341b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/docs/types/test.ts @@ -0,0 +1,418 @@ +/* +* @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 ghad = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectType Float64Array + ghad( x.length, 2.0, new AccessorArray( x ), 1, new AccessorArray( y ), 1, 3.0, new AccessorArray( z ), 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 z = new Float64Array( 10 ); + + ghad( '10', 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( true, 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( false, 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( null, 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( undefined, 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( [], 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( {}, 2.0, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( ( x: number ): number => x, 2.0, x, 1, y, 1, 3.0, z, 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 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( x.length, '10', x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, true, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, false, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, null, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, undefined, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, [], x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, {}, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, ( x: number ): number => x, x, 1, y, 1, 3.0, z, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( 10, 2.0, 10, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, '10', 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, true, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, false, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, null, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, undefined, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, [ '1' ], 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, {}, 1, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, ( x: number ): number => x, 1, y, 1, 3.0, z, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( x.length, 2.0, x, '10', y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, true, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, false, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, null, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, undefined, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, [], y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, {}, y, 1, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, ( x: number ): number => x, y, 1, 3.0, z, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( 10, 2.0, x, 1, 10, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, '10', 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, true, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, false, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, null, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, undefined, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, [ '1' ], 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, {}, 1, 3.0, z, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, ( x: number ): number => x, 1, 3.0, z, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( x.length, 2.0, x, 1, y, '10', 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, true, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, false, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, null, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, undefined, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, [], 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, {}, 3.0, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, ( x: number ): number => x, 3.0, z, 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 z = new Float64Array( 10 ); + + ghad( x.length, 2.0, x, 1, y, 1, '10', z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, true, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, false, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, null, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, undefined, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, [], z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, {}, z, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, ( x: number ): number => x, z, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ghad( 10, 2.0, x, 1, y, 1, 3.0, 10, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, '10', 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, true, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, false, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, null, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, undefined, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, [ '1' ], 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, {}, 1 ); // $ExpectError + ghad( 10, 2.0, x, 1, y, 1, 3.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, '10' ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, true ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, false ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, null ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, undefined ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, [] ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, {} ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, ( 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 z = new Float64Array( 10 ); + + ghad(); // $ExpectError + ghad( x.length ); // $ExpectError + ghad( x.length, 2.0 ); // $ExpectError + ghad( x.length, 2.0, x ); // $ExpectError + ghad( x.length, 2.0, x, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0 ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z ); // $ExpectError + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 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 z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectType Float64Array + ghad.ndarray( x.length, 2.0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0, 3.0, new AccessorArray( z ), 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 z = new Float64Array( 10 ); + + ghad.ndarray( '10', 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( true, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( false, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( null, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( undefined, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( [], 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( {}, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( ( x: number ): number => x, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 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 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( x.length, '10', x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, true, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, false, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, null, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, undefined, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, [], x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, {}, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, ( x: number ): number => x, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( 10, 2.0, 10, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, '10', 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, true, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, false, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, null, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, undefined, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, [ '1' ], 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, {}, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, ( x: number ): number => x, 1, 0, y, 1, 0, 3.0, z, 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 z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, '10', 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, true, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, false, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, null, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, undefined, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, [], 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, {}, 0, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, ( x: number ): number => x, 0, y, 1, 0, 3.0, z, 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 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, '10', y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, true, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, false, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, null, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, undefined, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, [], y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, {}, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, ( x: number ): number => x, y, 1, 0, 3.0, z, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( 10, 2.0, x, 1, 0, 10, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, '10', 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, true, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, false, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, null, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, undefined, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, [ '1' ], 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, {}, 1, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, ( x: number ): number => x, 1, 0, 3.0, z, 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 z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, 0, y, '10', 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, true, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, false, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, null, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, undefined, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, [], 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, {}, 0, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, ( x: number ): number => x, 0, 3.0, z, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, '10', 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, true, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, false, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, null, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, undefined, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, [], 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, {}, 3.0, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, ( x: number ): number => x, 3.0, z, 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 z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, '10', z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, true, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, false, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, null, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, undefined, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, [], z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, {}, z, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, ( x: number ): number => x, z, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, 10, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, '10', 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, true, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, false, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, null, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, undefined, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, [ '1' ], 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, {}, 1, 0 ); // $ExpectError + ghad.ndarray( 10, 2.0, x, 1, 0, y, 1, 0, 3.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, '10', 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, true, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, false, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, null, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, undefined, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, [], 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, {}, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const z = new Float64Array( 10 ); + + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, '10' ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, true ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, false ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, null ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, undefined ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, [] ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, {} ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 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 z = new Float64Array( 10 ); + + ghad.ndarray(); // $ExpectError + ghad.ndarray( x.length ); // $ExpectError + ghad.ndarray( x.length, 2.0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1 ); // $ExpectError + ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/examples/index.js new file mode 100644 index 000000000000..6b512b856fda --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 ghad = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, -100, 100, opts ); +var y = discreteUniform( 10, -100, 100, opts ); +var z = discreteUniform( 10, -100, 100, opts ); + +console.log( x ); +console.log( y ); +console.log( z ); + +ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); +console.log( z ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/accessors.js new file mode 100644 index 000000000000..1aedfda471c1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/accessors.js @@ -0,0 +1,97 @@ +/** +* @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 the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - first scalar constant +* @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 {number} beta - second scalar constant +* @param {Object} z - output array object +* @param {Collection} z.data - output array data +* @param {Array} z.accessors - array element accessors +* @param {integer} strideZ - `z` stride length +* @param {NonNegativeInteger} offsetZ - starting `z` 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad( x.length, 2.0, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0, 3.0, arraylike2object( toAccessorArray( z ) ), 1, 0 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +*/ +function ghad( N, alpha, x, strideX, offsetX, y, strideY, offsetY, beta, z, strideZ, offsetZ ) { // eslint-disable-line max-len, max-params + var xbuf; + var ybuf; + var zbuf; + var xget; + var yget; + var zget; + var zset; + var ix; + var iy; + var iz; + var i; + + // Cache references to array data: + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + + // Cache references to element accessors: + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + zget = z.accessors[ 0 ]; + zset = z.accessors[ 1 ]; + + ix = offsetX; + iy = offsetY; + iz = offsetZ; + for ( i = 0; i < N; i++ ) { + zset( zbuf, iz, ( alpha * xget( xbuf, ix ) * yget( ybuf, iy ) ) + ( beta * zget( zbuf, iz ) ) ); // eslint-disable-line max-len + ix += strideX; + iy += strideY; + iz += strideZ; + } + return z; +} + + +// EXPORTS // + +module.exports = ghad; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/index.js new file mode 100644 index 000000000000..67cdf3c6b592 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/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'; + +/** +* Multiply the Hadamard product of strided arrays `x` and `y` by a constant and add the result to a strided array `z` multiplied by a constant. +* +* @module @stdlib/blas/ext/base/ghad +* +* @example +* var ghad = require( '@stdlib/blas/ext/base/ghad' ); +* +* 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +* +* @example +* var ghad = require( '@stdlib/blas/ext/base/ghad' ); +* +* 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad.ndarray( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.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/ghad/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/main.js new file mode 100644 index 000000000000..0992986c69e8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/main.js @@ -0,0 +1,58 @@ +/** +* @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 the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - first scalar constant +* @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 {number} beta - second scalar constant +* @param {NumericArray} z - output array +* @param {integer} strideZ - `z` 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +*/ +function ghad( N, alpha, x, strideX, y, strideY, beta, z, strideZ ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), beta, z, strideZ, stride2offset( N, strideZ ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = ghad; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/ndarray.js new file mode 100644 index 000000000000..85b0b8c9b65f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/lib/ndarray.js @@ -0,0 +1,128 @@ +/** +* @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 gscal = require( '@stdlib/blas/base/gscal' ).ndarray; +var accessors = require( './accessors.js' ); + + +// VARIABLES // + +var M = 5; + + +// MAIN // + +/** +* Multiplies the Hadamard product of strided arrays `x` and `y` by a constant and adds the result to a strided array `z` multiplied by a constant using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - first scalar constant +* @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 {number} beta - second scalar constant +* @param {NumericArray} z - output array +* @param {integer} strideZ - `z` stride length +* @param {NonNegativeInteger} offsetZ - starting `z` 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 z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; +* +* ghad( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); +* // z => [ 7.0, 15.0, 27.0, 43.0, 63.0 ] +*/ +function ghad( N, alpha, x, strideX, offsetX, y, strideY, offsetY, beta, z, strideZ, offsetZ ) { // eslint-disable-line max-len, max-params + var ix; + var iy; + var iz; + var ox; + var oy; + var oz; + var m; + var i; + + if ( N <= 0 ) { + return z; + } + // Fast path: when alpha = 0.0, delegate to gscal (z = beta * z) + if ( alpha === 0.0 ) { + return gscal( N, beta, z, strideZ, offsetZ ); + } + ox = arraylike2object( x ); + oy = arraylike2object( y ); + oz = arraylike2object( z ); + if ( ox.accessorProtocol || oy.accessorProtocol || oz.accessorProtocol ) { + accessors( N, alpha, ox, strideX, offsetX, oy, strideY, offsetY, beta, oz, strideZ, offsetZ ); // eslint-disable-line max-len + return z; + } + ix = offsetX; + iy = offsetY; + iz = offsetZ; + + // Use loop unrolling if all strides are equal to `1`... + if ( strideX === 1 && strideY === 1 && strideZ === 1 ) { + m = N % M; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + z[ iz ] = ( alpha * x[ ix ] * y[ iy ] ) + ( beta * z[ iz ] ); + ix += strideX; + iy += strideY; + iz += strideZ; + } + } + if ( N < M ) { + return z; + } + for ( i = m; i < N; i += M ) { + z[ iz ] = ( alpha * x[ ix ] * y[ iy ] ) + ( beta * z[ iz ] ); + z[ iz+1 ] = ( alpha * x[ ix+1 ] * y[ iy+1 ] ) + ( beta * z[ iz+1 ] ); + z[ iz+2 ] = ( alpha * x[ ix+2 ] * y[ iy+2 ] ) + ( beta * z[ iz+2 ] ); + z[ iz+3 ] = ( alpha * x[ ix+3 ] * y[ iy+3 ] ) + ( beta * z[ iz+3 ] ); + z[ iz+4 ] = ( alpha * x[ ix+4 ] * y[ iy+4 ] ) + ( beta * z[ iz+4 ] ); + ix += M; + iy += M; + iz += M; + } + return z; + } + for ( i = 0; i < N; i++ ) { + z[ iz ] = ( alpha * x[ ix ] * y[ iy ] ) + ( beta * z[ iz ] ); + ix += strideX; + iy += strideY; + iz += strideZ; + } + return z; +} + + +// EXPORTS // + +module.exports = ghad; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/package.json b/lib/node_modules/@stdlib/blas/ext/base/ghad/package.json new file mode 100644 index 000000000000..0dd5df79f85a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/blas/ext/base/ghad", + "version": "0.0.0", + "description": "Multiply the Hadamard product of strided arrays `x` and `y` by a constant and add the result to a strided array `z` multiplied by a constant.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "linear", + "algebra", + "subroutines", + "hadamard", + "product", + "multiply", + "multiplication", + "strided", + "array", + "ndarray", + "vector", + "had", + "ghad" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.js new file mode 100644 index 000000000000..168938df916a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/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 ghad = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghad, '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 ghad.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.main.js new file mode 100644 index 000000000000..71b57e1106e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.main.js @@ -0,0 +1,472 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var ghad = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghad, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( ghad.length, 9, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies the Hadamard product of `x` and `y` by a constant and adds the result to `z` multiplied by a constant', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0, // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + 43.0, // ( 2.0 * 4.0 * 5.0 ) + ( 3.0 * 1.0 ) + 63.0 // ( 2.0 * 5.0 * 6.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + x = [ 3.0, 4.0 ]; + y = [ 1.0, 2.0 ]; + z = [ 2.0, 3.0 ]; + expected = [ 12.0, 25.0 ]; + + ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies the Hadamard product of `x` and `y` by a constant and adds the result to `z` multiplied by a constant (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0, // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + 43.0, // ( 2.0 * 4.0 * 5.0 ) + ( 3.0 * 1.0 ) + 63.0 // ( 2.0 * 5.0 * 6.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( x.length, 2.0, toAccessorArray( x ), 1, toAccessorArray( y ), 1, 3.0, toAccessorArray( z ), 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + x = [ 3.0, 4.0 ]; + y = [ 1.0, 2.0 ]; + z = [ 2.0, 3.0 ]; + expected = [ 12.0, 25.0 ]; + + ghad( x.length, 2.0, toAccessorArray( x ), 1, toAccessorArray( y ), 1, 3.0, toAccessorArray( z ), 1 ); + t.deepEqual( z, 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 z; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 5.0, 6.0, 7.0, 8.0, 9.0 ]; + z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + out = ghad( x.length, 2.0, x, 1, y, 1, 3.0, z, 1 ); + + t.strictEqual( out, z, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `z` unchanged', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + z = [ 7.0, 8.0, 9.0 ]; + expected = [ 7.0, 8.0, 9.0 ]; + + ghad( 0, 2.0, x, 1, y, 1, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + ghad( -4, 2.0, x, 1, y, 1, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `alpha` equals `0.0`, the function scales `z` by `beta`', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + z = [ 1.0, 2.0, 3.0 ]; + expected = [ + 3.0, // 3.0 * 1.0 + 6.0, // 3.0 * 2.0 + 9.0 // 3.0 * 3.0 + ]; + + ghad( x.length, 0.0, x, 1, y, 1, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 2, y, 1, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, toAccessorArray( x ), 2, toAccessorArray( y ), 1, 3.0, toAccessorArray( z ), 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 9.0, + 3.0, // 1 + 8.0, + 4.0 // 2 + ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 1, y, 2, 3.0, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 9.0, + 3.0, // 1 + 8.0, + 4.0 // 2 + ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, toAccessorArray( x ), 1, toAccessorArray( y ), 2, 3.0, toAccessorArray( z ), 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `z` stride', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ + 1.0, // 0 + 5.0, + 1.0, // 1 + 6.0, + 1.0 // 2 + ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 5.0, + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 6.0, + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 1, y, 1, 3.0, z, 2 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `z` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ + 1.0, // 0 + 5.0, + 1.0, // 1 + 6.0, + 1.0 // 2 + ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 5.0, + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 6.0, + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, toAccessorArray( x ), 1, toAccessorArray( y ), 1, 3.0, toAccessorArray( z ), 2 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + var z; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 2.0, // 2 + 3.0, // 1 + 4.0 // 0 + ]); + z = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + expected = new Float64Array([ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]); + + ghad( 3, 2.0, x, -2, y, -1, 3.0, z, -1 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]; + y = [ + 2.0, // 2 + 3.0, // 1 + 4.0 // 0 + ]; + z = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + expected = new Float64Array([ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]); + + ghad( 3, 2.0, toAccessorArray( x ), -2, toAccessorArray( y ), -1, 3.0, toAccessorArray( z ), -1 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var y0; + var z0; + var x1; + var y1; + var z1; + + 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, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 12.0 + ]); + z0 = new Float64Array([ + 1.0, + 1.0, + 1.0, + 1.0, // 0 + 1.0, // 1 + 1.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); + z1 = new Float64Array( z0.buffer, z0.BYTES_PER_ELEMENT*3 ); + + expected = new Float64Array([ + 1.0, + 1.0, + 1.0, + 11.0, // ( 2.0 * 2.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 35.0 // ( 2.0 * 4.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]); + + ghad( 3, 2.0, x1, 1, y1, 1, 3.0, z1, 1 ); + t.deepEqual( z0, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if all strides are equal to `1`, the function efficiently multiplies the Hadamard product of `x` and `y` by a constant and adds the result to `z` multiplied by a constant', function test( t ) { + var expected; + var alpha; + var beta; + var x; + var y; + var z; + var i; + + alpha = 2.0; + beta = 3.0; + x = new Float64Array( 100 ); + y = new Float64Array( 100 ); + z = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + z[ i ] = 1.0; + expected[ i ] = ( alpha * x[ i ] * y[ i ] ) + ( beta * z[ i ] ); + } + ghad( x.length, alpha, x, 1, y, 1, beta, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + y = new Float64Array( 240 ); + z = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + z[ i ] = 1.0; + expected[ i ] = ( alpha * x[ i ] * y[ i ] ) + ( beta * z[ i ] ); + } + ghad( x.length, alpha, x, 1, y, 1, beta, z, 1 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.ndarray.js new file mode 100644 index 000000000000..59f880ab0f5b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghad/test/test.ndarray.js @@ -0,0 +1,544 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var ghad = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghad, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', function test( t ) { + t.strictEqual( ghad.length, 12, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies the Hadamard product of `x` and `y` by a constant and adds the result to `z` multiplied by a constant', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0, // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + 43.0, // ( 2.0 * 4.0 * 5.0 ) + ( 3.0 * 1.0 ) + 63.0 // ( 2.0 * 5.0 * 6.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + x = [ 3.0, 4.0 ]; + y = [ 1.0, 2.0 ]; + z = [ 2.0, 3.0 ]; + expected = [ 12.0, 25.0 ]; + + ghad( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies the Hadamard product of `x` and `y` by a constant and adds the result to `z` multiplied by a constant (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 2.0, 3.0, 4.0, 5.0, 6.0 ]; + z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0, // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + 43.0, // ( 2.0 * 4.0 * 5.0 ) + ( 3.0 * 1.0 ) + 63.0 // ( 2.0 * 5.0 * 6.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( x.length, 2.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, 3.0, toAccessorArray( z ), 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + x = [ 3.0, 4.0 ]; + y = [ 1.0, 2.0 ]; + z = [ 2.0, 3.0 ]; + expected = [ 12.0, 25.0 ]; + + ghad( x.length, 2.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, 3.0, toAccessorArray( z ), 1, 0 ); + t.deepEqual( z, 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 z; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 5.0, 6.0, 7.0, 8.0, 9.0 ]; + z = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + out = ghad( x.length, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + + t.strictEqual( out, z, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `z` unchanged', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + z = [ 7.0, 8.0, 9.0 ]; + expected = [ 7.0, 8.0, 9.0 ]; + + ghad( 0, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + ghad( -4, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'when `alpha` equals `0.0`, the function scales `z` by `beta`', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + z = [ 1.0, 2.0, 3.0 ]; + expected = [ + 3.0, // 3.0 * 1.0 + 6.0, // 3.0 * 2.0 + 9.0 // 3.0 * 3.0 + ]; + + ghad( x.length, 0.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 2, 0, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0, 3.0, toAccessorArray( z ), 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 9.0, + 3.0, // 1 + 8.0, + 4.0 // 2 + ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 1, 0, y, 2, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 2.0, // 0 + 9.0, + 3.0, // 1 + 8.0, + 4.0 // 2 + ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0, 3.0, toAccessorArray( z ), 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `z` stride', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ + 1.0, // 0 + 5.0, + 1.0, // 1 + 6.0, + 1.0 // 2 + ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 5.0, + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 6.0, + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 2, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `z` stride (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ + 1.0, // 0 + 5.0, + 1.0, // 1 + 6.0, + 1.0 // 2 + ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 5.0, + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 6.0, + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, 3.0, toAccessorArray( z ), 2, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + var z; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 2.0, // 2 + 3.0, // 1 + 4.0 // 0 + ]); + z = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + expected = new Float64Array([ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]); + + ghad( 3, 2.0, x, -2, 4, y, -1, 2, 3.0, z, -1, 2 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]; + y = [ + 2.0, // 2 + 3.0, // 1 + 4.0 // 0 + ]; + z = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + expected = new Float64Array([ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]); + + ghad( 3, 2.0, toAccessorArray( x ), -2, 4, toAccessorArray( y ), -1, 2, 3.0, toAccessorArray( z ), -1, 2 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ + 0.0, + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 21.0, // ( 2.0 * 3.0 * 3.0 ) + ( 3.0 * 1.0 ) + 43.0 // ( 2.0 * 5.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 2, 1, y, 1, 0, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ + 0.0, + 2.0, // 0 + 3.0, // 1 + 4.0 // 2 + ]; + z = [ 1.0, 1.0, 1.0 ]; + expected = [ + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 1, 0, y, 1, 1, 3.0, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `z` offset', function test( t ) { + var expected; + var x; + var y; + var z; + + x = [ 1.0, 2.0, 3.0 ]; + y = [ 2.0, 3.0, 4.0 ]; + z = [ + 1.0, + 1.0, + 1.0, // 0 + 1.0, // 1 + 1.0 // 2 + ]; + expected = [ + 1.0, + 1.0, + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 1, 0, y, 1, 0, 3.0, z, 1, 2 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var x; + var y; + var z; + + 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 + ]; + z = [ + 1.0, + 1.0, + 1.0, + 1.0, // 0 + 1.0, // 1 + 1.0 // 2 + ]; + expected = [ + 1.0, + 1.0, + 1.0, + 7.0, // ( 2.0 * 1.0 * 2.0 ) + ( 3.0 * 1.0 ) + 15.0, // ( 2.0 * 2.0 * 3.0 ) + ( 3.0 * 1.0 ) + 27.0 // ( 2.0 * 3.0 * 4.0 ) + ( 3.0 * 1.0 ) + ]; + + ghad( 3, 2.0, x, 2, 1, y, 1, 2, 3.0, z, 1, 3 ); + t.deepEqual( z, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if all strides are equal to `1`, the function efficiently multiplies the Hadamard product of `x` and `y` by a constant and adds the result to `z` multiplied by a constant', function test( t ) { + var expected; + var alpha; + var beta; + var x; + var y; + var z; + var i; + + alpha = 2.0; + beta = 3.0; + x = new Float64Array( 100 ); + y = new Float64Array( 100 ); + z = new Float64Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + z[ i ] = 1.0; + expected[ i ] = ( alpha * x[ i ] * y[ i ] ) + ( beta * z[ i ] ); + } + ghad( x.length, alpha, x, 1, 0, y, 1, 0, beta, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + y = new Float64Array( 240 ); + z = new Float64Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + y[ i ] = x.length - i; + z[ i ] = 1.0; + expected[ i ] = ( alpha * x[ i ] * y[ i ] ) + ( beta * z[ i ] ); + } + ghad( x.length, alpha, x, 1, 0, y, 1, 0, beta, z, 1, 0 ); + t.deepEqual( z, expected, 'returns expected value' ); + + t.end(); +});