diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/README.md b/lib/node_modules/@stdlib/blas/base/zdotu/README.md new file mode 100644 index 000000000000..5ab45d19ef9c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/README.md @@ -0,0 +1,216 @@ + + +# zdotu + +> Calculate the dot product of two double-precision complex floating-point vectors. + +
+ +The [dot product][dot-product] (or scalar product) is defined as + + + +```math +\mathbf{x}\cdot\mathbf{y} = \sum_{i=0}^{N-1} x_i y_i = x_0 y_0 + x_1 y_1 + \ldots + x_{N-1} y_{N-1} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var zdotu = require( '@stdlib/blas/base/zdotu' ); +``` + +#### zdotu( N, x, strideX, y, strideY ) + +Calculates the dot product of vectors `x` and `y`. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); + +var z = zdotu( 3, x, 1, y, 1 ); +// returns [ -52.0, 82.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Complex128Array`][@stdlib/array/complex128]. +- **strideX**: stride kength for `x`. +- **y**: input [`Complex128Array`][@stdlib/array/complex128]. +- **strideY**: stride kength for `y`. + +The `N` and strides parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order, + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var y = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +var z = zdotu( 2, x, 2, y, -1 ); +// returns [ -2.0, 14.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +// Initial arrays... +var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Create offset views... +var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3th element + +var z = zdotu( 1, x1, 1, y1, 1 ); +// returns [ -15.0, 80.0 ] +``` + +#### zdotu.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Calculates the dot product of `x` and `y` using alternative indexing semantics. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); + +var z = zdotu.ndarray( x.length, x, 1, 0, y, 1, 0 ); +// returns [ -52.0, 82.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +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 calculate the dot product of every other value in `x` starting from the second value with the last 2 elements in `y` in reverse order + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var y = new Complex128Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ); // eslint-disable-line max-len + +var z = zdotu.ndarray( 2, x, 2, 1, y, -1, y.length-1 ); +// returns [ -40.0, 310.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `0.0 + 0.0i`. +- `zdotu()` corresponds to the [BLAS][blas] level 1 function [`zdotu`][zdotu]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var zdotu = require( '@stdlib/blas/base/zdotu' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var y = filledarrayBy( 10, 'complex128', rand ); +console.log( y.toString() ); + +// Compute the dot product: +var out = zdotu( x.length, x, 1, y, -1 ); +console.log( out.toString() ); + +// Compute the dot product using alternative indexing semantics: +out = zdotu.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( out.toString() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/zdotu/benchmark/benchmark.js new file mode 100644 index 000000000000..7af8eca78568 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/benchmark/benchmark.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var zdotu = require( './../lib/zdotu.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var x; + var y; + + x = new Complex128Array( uniform( N*2, -100.0, 100.0, options ) ); + y = new Complex128Array( uniform( N*2, -100.0, 100.0, options ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = zdotu( x.length, x, 1, y, 1 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + f = createBenchmark( N ); + bench( pkg+':size='+N, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotu/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..9909434edaff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/benchmark/benchmark.ndarray.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var zdotu = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var x; + var y; + + x = new Complex128Array( uniform( N*2, -100.0, 100.0, options ) ); + y = new Complex128Array( uniform( N*2, -100.0, 100.0, options ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = zdotu( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + f = createBenchmark( N ); + bench( pkg+':ndarray:size='+N, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/zdotu/docs/repl.txt new file mode 100644 index 000000000000..4903798457fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/docs/repl.txt @@ -0,0 +1,109 @@ + +{{alias}}( N, x, strideX, y, strideY ) + Calculate the dot product of two double-precision complex floating-point + vectors. + + 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 a + typed array view. + + If `N <= 0`, the function returns `0 + 0i`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex128Array + First input array. + + strideX: integer + Stride length for `x`. + + y: Complex128Array + Second input array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + out: Complex128 + Scalar constant. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, 7.0, 8.0, 9.0 ] ); + > var z = {{alias}}( x.length, x, 1, y, 1 ) + [ -20.0, 78.0 ] + + // Advanced indexing: + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > var z = {{alias}}( 2, x, 2, y, -1 ) + [ -2.0, 14.0 ] + + // Using typed array views: + > var x0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var y0 = new {{alias:@stdlib/array/complex128}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > var x1 = new {{alias:@stdlib/array/complex128}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/complex128}}( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); + > var z = {{alias}}( 1, x1, 1, y1, 1 ) + [ -15.0, 80.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Computes the dot product of two double-precision complex floating-point + vectors using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing based on a starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex128Array + First input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Complex128Array + Second input array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + out: Complex128 + Second input array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, 7.0, 8.0, 9.0 ] ); + > var z = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + [ -20.0, 78.0 ] + + // Advanced indexing: + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > var z = {{alias}}.ndarray( 1, x, 2, 1, y, -1, y.length-1 ) + [ -1.0, 7.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/zdotu/docs/types/index.d.ts new file mode 100644 index 000000000000..e5e409ec02a1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/docs/types/index.d.ts @@ -0,0 +1,108 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 { Complex128Array } from '@stdlib/types/array'; +import { Complex128 } from '@stdlib/types/complex'; + +/** +* Interface describing `zdotu`. +*/ +interface Routine { + /** + * Calculates the dot product of vectors `x` and `y`. + * + * @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 + * @returns dot product + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); + * var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); + * + * var z = zdotu( 3, x, 1, y, 1 ); + * // returns [ -52.0, 82.0 ] + */ + ( N: number, x: Complex128Array, strideX: number, y: Complex128Array, strideY: number ): Complex128; + + /** + * Calculates the dot product of vectors `x` and `y` 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` + * @returns dot product + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); + * var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); + * + * var z = zdotu.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * // returns [ -52.0, 82.0 ] + */ + ndarray( N: number, x: Complex128Array, strideX: number, offsetX: number, y: Complex128Array, strideY: number, offsetY: number ): Complex128; +} + +/** +* Computes the dot product of two double-precision complex floating-point vectors. +* +* @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 +* @returns dot product +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +* var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); +* +* var z = zdotu( 3, x, 1, y, 1 ); +* // returns [ -52.0, 82.0 ] +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +* var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); +* +* var z = zdotu.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns [ -52.0, 82.0 ] +*/ +declare var zdotu: Routine; + + +// EXPORTS // + +export = zdotu; diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/zdotu/docs/types/test.ts new file mode 100644 index 000000000000..13ad5d3d526e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/docs/types/test.ts @@ -0,0 +1,249 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128Array = require( '@stdlib/array/complex128' ); +import zdotu = require( './index' ); + + +// TESTS // + +// The function returns Complex128... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu( x.length, x, 1, y, 1 ); // $ExpectType Complex128 +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu( '10', x, 1, y, 1 ); // $ExpectError + zdotu( true, x, 1, y, 1 ); // $ExpectError + zdotu( false, x, 1, y, 1 ); // $ExpectError + zdotu( null, x, 1, y, 1 ); // $ExpectError + zdotu( undefined, x, 1, y, 1 ); // $ExpectError + zdotu( [], x, 1, y, 1 ); // $ExpectError + zdotu( {}, x, 1, y, 1 ); // $ExpectError + zdotu( ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu( x.length, 10, 1, y, 1 ); // $ExpectError + zdotu( x.length, '10', 1, y, 1 ); // $ExpectError + zdotu( x.length, true, 1, y, 1 ); // $ExpectError + zdotu( x.length, false, 1, y, 1 ); // $ExpectError + zdotu( x.length, null, 1, y, 1 ); // $ExpectError + zdotu( x.length, undefined, 1, y, 1 ); // $ExpectError + zdotu( x.length, [ '1' ], 1, y, 1 ); // $ExpectError + zdotu( x.length, {}, 1, y, 1 ); // $ExpectError + zdotu( x.length, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu( x.length, x, '10', y, 1 ); // $ExpectError + zdotu( x.length, x, true, y, 1 ); // $ExpectError + zdotu( x.length, x, false, y, 1 ); // $ExpectError + zdotu( x.length, x, null, y, 1 ); // $ExpectError + zdotu( x.length, x, undefined, y, 1 ); // $ExpectError + zdotu( x.length, x, [], y, 1 ); // $ExpectError + zdotu( x.length, x, {}, y, 1 ); // $ExpectError + zdotu( x.length, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + zdotu( x.length, x, 1, 10, 1 ); // $ExpectError + zdotu( x.length, x, 1, '10', 1 ); // $ExpectError + zdotu( x.length, x, 1, true, 1 ); // $ExpectError + zdotu( x.length, x, 1, false, 1 ); // $ExpectError + zdotu( x.length, x, 1, null, 1 ); // $ExpectError + zdotu( x.length, x, 1, undefined, 1 ); // $ExpectError + zdotu( x.length, x, 1, [], 1 ); // $ExpectError + zdotu( x.length, x, 1, {}, 1 ); // $ExpectError + zdotu( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu( x.length, x, 1, y, '10' ); // $ExpectError + zdotu( x.length, x, 1, y, true ); // $ExpectError + zdotu( x.length, x, 1, y, false ); // $ExpectError + zdotu( x.length, x, 1, y, null ); // $ExpectError + zdotu( x.length, x, 1, y, undefined ); // $ExpectError + zdotu( x.length, x, 1, y, [] ); // $ExpectError + zdotu( x.length, x, 1, y, {} ); // $ExpectError + zdotu( x.length, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu(); // $ExpectError + zdotu( x.length ); // $ExpectError + zdotu( x.length, x ); // $ExpectError + zdotu( x.length, x, 1 ); // $ExpectError + zdotu( x.length, x, 1, y ); // $ExpectError + zdotu( x.length, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Complex128... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType Complex128 +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( '10', x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( [], x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, 10, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, '10', 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, [], 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 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 Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, x, '10', 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, undefined, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, [], 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, ( x: number ): number => x, 0, y, 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 Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, x, 1, '10', y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, undefined, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, [], y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, [], 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 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 Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, x, 1, 0, y, '10', 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, undefined, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, [], 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray( x.length, x, 1, 0, y, 1, '10' ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, undefined ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, [] ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 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 Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotu.ndarray(); // $ExpectError + zdotu.ndarray( x.length ); // $ExpectError + zdotu.ndarray( x.length, x ); // $ExpectError + zdotu.ndarray( x.length, x, 1 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + zdotu.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/examples/index.js b/lib/node_modules/@stdlib/blas/base/zdotu/examples/index.js new file mode 100644 index 000000000000..ba66b69ae7d8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/base/discrete-uniform' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var zdotu = require( './../lib' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var y = filledarrayBy( 10, 'complex128', rand ); +console.log( y.toString() ); + +// Compute the dot product: +var out = zdotu( x.length, x, 1, y, -1 ); +console.log( out.toString() ); + +// Compute the dot product using alternative indexing semantics: +out = zdotu.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( out.toString() ); diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/lib/index.js b/lib/node_modules/@stdlib/blas/base/zdotu/lib/index.js new file mode 100644 index 000000000000..b09075b87a51 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/lib/index.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* BLAS level 1 routine to compute the dot product of two double-precision complex floating-point vectors. +* +* @module @stdlib/blas/base/zdotu +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var zdotu = require( '@stdlib/blas/base/zdotu' ); +* +* var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +* var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); +* +* var z = zdotu( 3, x, 1, y, 1 ); +* // returns [ -52.0, 82.0 ] +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var zdotu = require( '@stdlib/blas/base/zdotu' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var y = new Complex128Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ); +* +* var z = zdotu.ndarray( 2, x, 2, 1, y, -1, y.length-1 ); +* // returns [ -40.0, 310.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var zdotu; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + zdotu = main; +} else { + zdotu = tmp; +} + + +// EXPORTS // + +module.exports = zdotu; + +// exports: { "ndarray": "zdotu.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/lib/main.js b/lib/node_modules/@stdlib/blas/base/zdotu/lib/main.js new file mode 100644 index 000000000000..d4a91228eca1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var zdotu = require( './zdotu.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( zdotu, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = zdotu; diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotu/lib/ndarray.js new file mode 100644 index 000000000000..8aa5f4c33bfb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/lib/ndarray.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var muladd = require( '@stdlib/complex/float64/base/mul-add' ); + + +// MAIN // + +/** +* Calculates the dot product of two double-precision complex floating-point vectors. +* +* @param {integer} N - number of indexed elements +* @param {Complex128Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Complex128Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {Complex128} dot product +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +* var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); +* +* var z = zdotu( 3, x, 1, 0, y, 1, 0 ); +* // returns [ -52.0, 82.0 ] +*/ +function zdotu( N, x, strideX, offsetX, y, strideY, offsetY ) { + var dot; + var ix; + var iy; + var i; + + dot = new Complex128( 0.0, 0.0 ); + if ( N <= 0 ) { + return dot; + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + dot = muladd( x.get( ix ), y.get( iy ), dot ); + ix += strideX; + iy += strideY; + } + return dot; +} + + +// EXPORTS // + +module.exports = zdotu; diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/lib/zdotu.js b/lib/node_modules/@stdlib/blas/base/zdotu/lib/zdotu.js new file mode 100644 index 000000000000..3ca8b6c14682 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/lib/zdotu.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 // + +/** +* Calculates the dot product of two double-precision complex floating-point vectors. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex128Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {Complex128Array} y - second input array +* @param {integer} strideY - `y` stride length +* @returns {Complex128} dot product +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] ); +* var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] ); +* +* var z = zdotu( 3, x, 1, y, 1 ); +* // returns [ -52.0, 82.0 ] +*/ +function zdotu( N, x, strideX, y, strideY ) { + var ix = stride2offset( N, strideX ); + var iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); +} + + +// EXPORTS // + +module.exports = zdotu; diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/package.json b/lib/node_modules/@stdlib/blas/base/zdotu/package.json new file mode 100644 index 000000000000..c61886a6aaa6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/package.json @@ -0,0 +1,82 @@ +{ + "name": "@stdlib/blas/base/zdotu", + "version": "0.0.0", + "description": "Calculate the dot product of two double-precision complex floating-point vectors.", + "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", + "level 1", + "linear", + "algebra", + "subroutines", + "zdotu", + "dot", + "product", + "dot product", + "scalar", + "scalar product", + "inner", + "inner product", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex128", + "double", + "float64", + "float64array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/test/test.js b/lib/node_modules/@stdlib/blas/base/zdotu/test/test.js new file mode 100644 index 000000000000..31ca4e686e59 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var zdotu = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zdotu, '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 zdotu.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var zdotu = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( zdotu, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var zdotu; + var main; + + main = require( './../lib/zdotu.js' ); + + zdotu = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( zdotu, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotu/test/test.ndarray.js new file mode 100644 index 000000000000..1b98d6c18ca7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/test/test.ndarray.js @@ -0,0 +1,239 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isSameComplex128 = require( '@stdlib/assert/is-same-complex128' ); +var zdotu = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zdotu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( zdotu.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the dot product of two double-precision complex floating-point vectors `x` and `y`', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + dot = zdotu( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual(isSameComplex128( dot, new Complex128( 3, 70 ) ), true, 'returns expected value' ); + + x = new Complex128Array( [ 3.0, -4.0, 1.0, 2.0 ] ); + y = new Complex128Array( [ 1.0, -2.0, 3.0, 8.0 ] ); + + dot = zdotu( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -18, 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array( [ 3.0, -4.0, 1.0, 7.0 ] ); + y = new Complex128Array( [ 1.0, -2.0, 3.0, -3.0 ] ); + + dot = zdotu( 0, x, 1, 0, y, 1, 0 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 0, 0 ) ), true, 'returns expected value' ); + + dot = zdotu( -4, x, 1, 0, y, 1, 0 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 0, 0 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 2.0, // 0 + -3.0, // 0 + -5.0, + 6.0, + 7.0, // 1 + 6.0 // 1 + ]); + y = new Complex128Array([ + 8.0, // 0 + 2.0, // 0 + -3.0, // 1 + 3.0, // 1 + -4.0, + 1.0 + ]); + + dot = zdotu( 2, x, 2, 0, y, 1, 0 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -17, -17 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 2.0, + -3.0, + -5.0, // 0 + 6.0, // 0 + 7.0, // 1 + 6.0 // 1 + ]); + y = new Complex128Array([ + 8.0, // 0 + 2.0, // 0 + -3.0, // 1 + 3.0, // 1 + -4.0, + 1.0 + ]); + + dot = zdotu( 2, x, 1, 1, y, 1, 0 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -91, 41 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 2.0, // 0 + -3.0, // 0 + -5.0, // 1 + 6.0, // 1 + 7.0, + 6.0 + ]); + y = new Complex128Array([ + 8.0, // 0 + 2.0, // 0 + -3.0, + 3.0, + -4.0, // 1 + 1.0 // 1 + ]); + + dot = zdotu( 2, x, 1, 0, y, 2, 0 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 36, -49 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 0 + 2.0, // 0 + 3.0, + 4.0, + 5.0, // 1 + 6.0 // 1 + ]); + y = new Complex128Array([ + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 0 + 11.0, // 1 + 12.0 // 1 + ]); + + dot = zdotu( 2, x, 2, 0, y, 1, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -28, 154 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 0 + 6.0 // 0 + ]); + y = new Complex128Array([ + 7.0, + 8.0, + 9.0, // 1 + 10.0, // 1 + 11.0, // 0 + 12.0 // 0 + ]); + + dot = zdotu( 2, x, -2, x.length-1, y, -1, 2 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -28, 154 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 0 + 2.0, // 0 + 3.0, + 4.0, + 5.0, // 1 + 6.0 // 1 + ]); + y = new Complex128Array([ + 7.0, // 0 + 8.0, // 0 + 9.0, // 1 + 10.0, // 1 + 11.0, + 12.0 + ]); + + dot = zdotu( 2, x, 2, 0, y, -1, y.length-2 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -24, 110 ) ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/zdotu/test/test.zdotu.js b/lib/node_modules/@stdlib/blas/base/zdotu/test/test.zdotu.js new file mode 100644 index 000000000000..7613bd1995d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotu/test/test.zdotu.js @@ -0,0 +1,217 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isSameComplex128 = require( '@stdlib/assert/is-same-complex128' ); +var zdotu = require( './../lib/zdotu.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zdotu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( zdotu.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the dot product of two double-precision complex floating-point vectors `x` and `y`', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + dot = zdotu( 4, x, 1, y, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 3, 70 ) ), true, 'returns expected value' ); + + x = new Complex128Array( [ 3.0, -4.0, 1.0, 2.0 ] ); + y = new Complex128Array( [ 1.0, -2.0, 3.0, 8.0 ] ); + + dot = zdotu( 2, x, 1, y, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -18, 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0 + 0i`', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array( [ 3.0, -4.0, 1.0, 7.0 ] ); + y = new Complex128Array( [ 1.0, -2.0, 3.0, -3.0 ] ); + + dot = zdotu( 0, x, 1, y, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 0, 0 ) ), true, 'returns expected value' ); + + dot = zdotu( -4, x, 1, y, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 0, 0 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 2.0, // 0 + -3.0, // 0 + -5.0, + 6.0, + 7.0, // 1 + 6.0 // 1 + ]); + y = new Complex128Array([ + 8.0, // 0 + 2.0, // 0 + -3.0, // 1 + 3.0, // 1 + -4.0, + 1.0 + ]); + + dot = zdotu( 2, x, 2, y, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -17, -17 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 2.0, // 0 + -3.0, // 0 + -5.0, // 1 + 7.0, // 1 + 6.0, + -2.0 + ]); + y = new Complex128Array([ + 8.0, // 0 + 2.0, // 0 + -3.0, + 3.0, + -4.0, // 1 + 1.0 // 1 + ]); + + dot = zdotu( 2, x, 1, y, 2 ); + t.strictEqual( isSameComplex128( dot, new Complex128( 35, -53 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 0 + 6.0 // 0 + ]); + y = new Complex128Array([ + 7.0, // 1 + 8.0, // 1 + 9.0, // 0 + 10.0, // 0 + 11.0, + 12.0 + ]); + + dot = zdotu( 2, x, -2, y, -1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -24, 126 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var dot; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 0 + 2.0, // 0 + 3.0, + 4.0, + 5.0, // 1 + 6.0 // 1 + ]); + y = new Complex128Array([ + 7.0, // 0 + 8.0, // 0 + 9.0, // 1 + 10.0, // 1 + 11.0, + 12.0 + ]); + + dot = zdotu( 2, x, 2, y, -1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -24, 110 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var dot; + var x0; + var y0; + var x1; + var y1; + + x0 = new Complex128Array([ + 1.0, // 0 + 2.0, // 0 + 3.0, + 4.0, + 5.0, // 1 + 6.0 // 1 + ]); + y0 = new Complex128Array([ + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 0 + 11.0, // 1 + 12.0 // 1 + ]); + + x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*0 ); + y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + + dot = zdotu( 2, x1, 2, y1, 1 ); + t.strictEqual( isSameComplex128( dot, new Complex128( -28, 154 ) ), true, 'returns expected value' ); + t.end(); +});