From 5de6a6cde02486e15f5e69cbfaf57622a6b03a74 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Mon, 28 Apr 2025 16:32:03 +0530 Subject: [PATCH 1/7] feat: add blas/base/zdotc --- 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 status: passed - 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/base/zdotc/README.md | 201 ++++++++++++++ .../blas/base/zdotc/benchmark/benchmark.js | 110 ++++++++ .../base/zdotc/benchmark/benchmark.ndarray.js | 110 ++++++++ .../@stdlib/blas/base/zdotc/docs/repl.txt | 106 ++++++++ .../blas/base/zdotc/docs/types/index.d.ts | 107 ++++++++ .../blas/base/zdotc/docs/types/test.ts | 249 ++++++++++++++++++ .../@stdlib/blas/base/zdotc/examples/index.js | 38 +++ .../@stdlib/blas/base/zdotc/lib/index.js | 71 +++++ .../@stdlib/blas/base/zdotc/lib/main.js | 35 +++ .../@stdlib/blas/base/zdotc/lib/ndarray.js | 78 ++++++ .../@stdlib/blas/base/zdotc/lib/zdotc.js | 63 +++++ .../@stdlib/blas/base/zdotc/package.json | 83 ++++++ .../@stdlib/blas/base/zdotc/test/test.js | 82 ++++++ .../blas/base/zdotc/test/test.ndarray.js | 215 +++++++++++++++ .../blas/base/zdotc/test/test.zdotc.js | 215 +++++++++++++++ 15 files changed, 1763 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/lib/zdotc.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/README.md b/lib/node_modules/@stdlib/blas/base/zdotc/README.md new file mode 100644 index 000000000000..8ac3a4b00d92 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/README.md @@ -0,0 +1,201 @@ + + +# zdotc + +> Calculate the dot product of two double-precision complex vectors. + +
+ +The [dot product][dot-product] (or scalar product) is defined as + +
+ + + +
+ +## Usage + +```javascript +var zdotc = require( '@stdlib/blas/base/zdotc' ); +``` + +#### zdotc( N, x, strideX, y, strideY ) + +Calculates the dot product `x^H * y` of complex vectors `x` and `y`. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex128 = require( '@stdlib/complex/float32/ctor' ); + +var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); + +var z = zdotc( x.length, x, 1, y, 1 ); +// returns [ 54.0, -80.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Complex128Array`][@stdlib/array/complex128]. +- **strideX**: index increment for `x`. +- **y**: input [`Complex128Array`][@stdlib/array/complex128]. +- **strideY**: index increment for `y`. + +The `N` and stride 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 Complex128 = require( '@stdlib/complex/float32/ctor' ); + +var x = new Complex128Array( [ -1.0, -9.0, 2.0, -8.0 ] ); +var y = new Complex128Array( [ -5.0, 1.0, -6.0, 7.0 ] ); + +var z = zdotc( x.length, x, 1, y, -1 ); +// returns [ -75.0, -99.0 ] +``` + +#### zdotc.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Calculates the dot product `x^H * y` of `x` and `y` using alternative indexing semantics. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex128 = require( '@stdlib/complex/float32/ctor' ); + +var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); + +var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); +// returns [ 54.0, -80.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 Complex128 = require( '@stdlib/complex/float32/ctor' ); + +var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); + +var z = zdotc.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +// returns [ -55.0, 23.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return complex128 with real and imagnary as `0.0`. +- `zdotc()` corresponds to the [BLAS][blas] level 1 function [`zdotc`][zdotc]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex128 = require( '@stdlib/complex/float32/ctor' ); +var zdotc = require( '@stdlib/blas/base/zdotc' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( 1, 5 ) ); +} + +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var y = filledarrayBy( 10, 'complex128', rand ); +console.log( y.toString() ); + +// Perform dot product of x and y +var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); +console.log( z ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js new file mode 100644 index 000000000000..0571e2ca6144 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js @@ -0,0 +1,110 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var pkg = require( './../package.json' ).name; +var zdotc = require( './../lib/zdotc.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var y; + + x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + y = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = zdotc( x.length, x, 1, y, 1 ); + if ( isnan( real( z ) ) || isnan( imag( z ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( real( z ) ) || isnan( imag( z ) ) ) { + 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( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..bfafc4dc9f60 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js @@ -0,0 +1,110 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var pkg = require( './../package.json' ).name; +var zdotc = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var y; + + x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + y = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = zdotc( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( real( z ) ) || isnan( imag( z ) )) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( real( z ) ) || isnan( imag( z ) )) { + 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( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/zdotc/docs/repl.txt new file mode 100644 index 000000000000..590d8c8113dc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/docs/repl.txt @@ -0,0 +1,106 @@ + +{{alias}}( N, x, strideX, y, strideY ) + Computes the dot product of two double-precision complex 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`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex128Array + First input array. + + strideX: integer + Index increment for `x`. + + y: Complex128Array + Second input array. + + strideY: integer + Index increment for `y`. + + Returns + ------- + z: Complex128 + The dot product. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ 7.0, -8.0, -1.0, -9.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, -6.0, -9.0, 5.0 ] ); + > var z = {{alias}}( x.length, x, 1, y, 1 ) + [ 54.0, -80.0 ] + + // Strides: + > x = new {{alias:@stdlib/array/complex128}}( [ 7.0, -8.0, -4.0, -7.0, -1.0, -9.0 ] ); + > y = new {{alias:@stdlib/array/complex128}}( [ 6.0, -6.0, -9.0, 5.0, 7.0, -6.0 ] ); + > z = {{alias}}( 2, x, 2, y, 1 ) + [ 54.0, -80.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Computes the dot product of two double-precision complex 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 + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Complex128Array + Second input array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + z: Complex128 + The dot product. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ 7.0, -8.0, -1.0, -9.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, -6.0, -9.0, 5.0 ] ); + > var z = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + [ 54.0, -80.0 ] + + // Strides: + > x = new {{alias:@stdlib/array/complex128}}( [ 7.0, -8.0, -4.0, -7.0, -1.0, -9.0 ] ); + > y = new {{alias:@stdlib/array/complex128}}( [ 6.0, -6.0, -9.0, 5.0, 7.0, -6.0 ] ); + > z = {{alias}}.ndarray( 2, x, 2, 0, y, 1, 0 ) + [ 54.0, -80.0 ] + + // Using offset indices: + > x = new {{alias:@stdlib/array/complex128}}( [ 7.0, -8.0, -4.0, -7.0, -1.0, -9.0 ] ); + > y = new {{alias:@stdlib/array/complex128}}( [ 6.0, -6.0, -9.0, 5.0, 7.0, -6.0 ] ); + > z = {{alias}}.ndarray( 2, x, -2, x.length-1, y, 1, 1 ) + [ 61.0, -72.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/zdotc/docs/types/index.d.ts new file mode 100644 index 000000000000..74754f7b5366 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/docs/types/index.d.ts @@ -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. +*/ + +import { Complex128 } from '@stdlib/types/complex'; +import { Complex128Array } from '@stdlib/types/array'; + + +// TypeScript Version: 4.1 + +/** +* Interface describing `zdotc`. +*/ +interface Routine { + /** + * Computes the dot product `x^H * y` of `x` and `y`. + * + * @param N - number of indexed elements + * @param x - first input complex array + * @param strideX - `x` stride length + * @param y - second input complex array + * @param strideY - `y` stride length + * @returns dot product + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ 7, -8, -1, -9 ] ); + * var y = new Complex128Array( [ 6, -6, -9, 5 ] ); + * + * var z = zdotc( x.length, x, 1, y, 1 ); + * // returns [ 54.0, -80.0 ] + */ + ( N: number, x: Complex128Array, strideX: number, y: Complex128Array, strideY: number ): Complex128; + + /** + * Computes the dot product `x^H * y` of `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( [ 7, -8, -1, -9 ] ); + * var y = new Complex128Array( [ 6, -6, -9, 5 ] ); + * + * var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * // returns [ 54.0, -80.0 ] + */ + ndarray( N: number, x: Complex128Array, strideX: number, offsetX: number, y: Complex128Array, strideY: number, offsetY: number ): Complex128; +} + +/** +* Computes the dot product `x^H * y` of `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( [ 7, -8, -1, -9 ] ); +* var y = new Complex128Array( [ 6, -6, -9, 5 ] ); +* +* var z = zdotc( x.length, x, 1, y, 1 ); +* // returns [ 54.0, -80.0 ] +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 7, -8, -1, -9 ] ); +* var y = new Complex128Array( [ 6, -6, -9, 5 ] ); +* +* var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns [ 54.0, -80.0 ] +*/ +declare var zdotc: Routine; + + +// EXPORTS // + +export = zdotc; diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/zdotc/docs/types/test.ts new file mode 100644 index 000000000000..7168d63bca3d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/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 zdotc = require( './index' ); + + +// TESTS // + +// The function returns a Complex128... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zdotc( 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 ); + + zdotc( '10', x, 1, y, 1 ); // $ExpectError + zdotc( true, x, 1, y, 1 ); // $ExpectError + zdotc( false, x, 1, y, 1 ); // $ExpectError + zdotc( null, x, 1, y, 1 ); // $ExpectError + zdotc( undefined, x, 1, y, 1 ); // $ExpectError + zdotc( [], x, 1, y, 1 ); // $ExpectError + zdotc( {}, x, 1, y, 1 ); // $ExpectError + zdotc( ( 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 ); + + zdotc( x.length, 10, 1, y, 1 ); // $ExpectError + zdotc( x.length, '10', 1, y, 1 ); // $ExpectError + zdotc( x.length, true, 1, y, 1 ); // $ExpectError + zdotc( x.length, false, 1, y, 1 ); // $ExpectError + zdotc( x.length, null, 1, y, 1 ); // $ExpectError + zdotc( x.length, undefined, 1, y, 1 ); // $ExpectError + zdotc( x.length, [], 1, y, 1 ); // $ExpectError + zdotc( x.length, {}, 1, y, 1 ); // $ExpectError + zdotc( 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 ); + + zdotc( x.length, x, '10', y, 1 ); // $ExpectError + zdotc( x.length, x, true, y, 1 ); // $ExpectError + zdotc( x.length, x, false, y, 1 ); // $ExpectError + zdotc( x.length, x, null, y, 1 ); // $ExpectError + zdotc( x.length, x, undefined, y, 1 ); // $ExpectError + zdotc( x.length, x, [], y, 1 ); // $ExpectError + zdotc( x.length, x, {}, y, 1 ); // $ExpectError + zdotc( 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 ); + + zdotc( x.length, x, 1, 10, 1 ); // $ExpectError + zdotc( x.length, x, 1, '10', 1 ); // $ExpectError + zdotc( x.length, x, 1, true, 1 ); // $ExpectError + zdotc( x.length, x, 1, false, 1 ); // $ExpectError + zdotc( x.length, x, 1, null, 1 ); // $ExpectError + zdotc( x.length, x, 1, undefined, 1 ); // $ExpectError + zdotc( x.length, x, 1, [], 1 ); // $ExpectError + zdotc( x.length, x, 1, {}, 1 ); // $ExpectError + zdotc( 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 ); + + zdotc( x.length, x, 1, y, '10' ); // $ExpectError + zdotc( x.length, x, 1, y, true ); // $ExpectError + zdotc( x.length, x, 1, y, false ); // $ExpectError + zdotc( x.length, x, 1, y, null ); // $ExpectError + zdotc( x.length, x, 1, y, undefined ); // $ExpectError + zdotc( x.length, x, 1, y, [] ); // $ExpectError + zdotc( x.length, x, 1, y, {} ); // $ExpectError + zdotc( 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 ); + + zdotc(); // $ExpectError + zdotc( x.length ); // $ExpectError + zdotc( x.length, x ); // $ExpectError + zdotc( x.length, x, 1 ); // $ExpectError + zdotc( x.length, x, 1, y ); // $ExpectError + zdotc( 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 ); + + zdotc.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 ); + + zdotc.ndarray( '10', x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( [], x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray( x.length, 10, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, '10', 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, [], 1, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray( x.length, x, '10', 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, undefined, 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, [], 0, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray( x.length, x, 1, '10', y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, undefined, y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, [], y, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, [], 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray( x.length, x, 1, 0, y, '10', 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, undefined, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, [], 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray( x.length, x, 1, 0, y, 1, '10' ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, undefined ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, [] ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError + zdotc.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 ); + + zdotc.ndarray(); // $ExpectError + zdotc.ndarray( x.length ); // $ExpectError + zdotc.ndarray( x.length, x ); // $ExpectError + zdotc.ndarray( x.length, x, 1 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + zdotc.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/examples/index.js b/lib/node_modules/@stdlib/blas/base/zdotc/examples/index.js new file mode 100644 index 000000000000..e34180ac0f67 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var zdotc = require( './../lib' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( 1, 5 ) ); +} + +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var y = filledarrayBy( 10, 'complex128', rand ); +console.log( y.toString() ); + +// Perform dot product of x and y +var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); +console.log( z ); diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/lib/index.js b/lib/node_modules/@stdlib/blas/base/zdotc/lib/index.js new file mode 100644 index 000000000000..f82b3b68576f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/lib/index.js @@ -0,0 +1,71 @@ +/** +* @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 `x^H * y` of two double-precision complex vectors. +* +* @module @stdlib/blas/base/zdotc +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var zdotc = require( '@stdlib/blas/base/zdotc' ); +* +* var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +* var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); +* var z = zdotc( x.length, x, 1, y, 1 ); +* // returns [ 54.0, -80.0 ] +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var zdotc = require( '@stdlib/blas/base/zdotc' ); +* +* var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +* var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); +* +* var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns [ 54.0, -80.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 zdotc; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + zdotc = main; +} else { + zdotc = tmp; +} + + +// EXPORTS // + +module.exports = zdotc; + +// exports: { "ndarray": "zdotc.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/lib/main.js b/lib/node_modules/@stdlib/blas/base/zdotc/lib/main.js new file mode 100644 index 000000000000..0a7cf6dfc7b0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/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 zdotc = require( './zdotc.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( zdotc, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = zdotc; diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotc/lib/ndarray.js new file mode 100644 index 000000000000..796f394e4d2d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/lib/ndarray.js @@ -0,0 +1,78 @@ +/** +* @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 zmul = require( '@stdlib/complex/float64/base/mul' ); +var zadd = require( '@stdlib/complex/float64/base/add' ); +var conj = require( '@stdlib/complex/float64/conj' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); + + +// MAIN // + +/** +* Computes the dot product `x^H * y` of `x` and `y`. +* +* @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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +* var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); +* +* var z = zdotc( x.length, x, 1, 0, y, 1, 0 ); +* // z => [ 54.0, -80.0 ] +*/ +function zdotc( N, x, strideX, offsetX, y, strideY, offsetY ) { + var conjX; + var dot; + var ix; + var iy; + var i; + + dot = new Complex128( 0, 0 ); + if ( N <= 0 ) { + return dot; + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + conjX = conj( x.get( ix ) ); + dot = zadd( dot, zmul( conjX, y.get( iy ) ) ); + ix += strideX; + iy += strideY; + } + return dot; +} + + +// EXPORTS // + +module.exports = zdotc; diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/lib/zdotc.js b/lib/node_modules/@stdlib/blas/base/zdotc/lib/zdotc.js new file mode 100644 index 000000000000..3785d20b5259 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/lib/zdotc.js @@ -0,0 +1,63 @@ +/** +* @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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the dot product `x^H * y` of `x` and `y`. +* +* @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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var zdotc = require( '@stdlib/blas/base/zdotc' ); +* +* var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); +* var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); +* var z = zdotc( x.length, x, 1, y, 1 ); +*/ +function zdotc( N, x, strideX, y, strideY ) { + var ix; + var iy; + if ( N <= 0 ) { + return new Complex128( 0, 0 ); + } + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); +} + + +// EXPORTS // + +module.exports = zdotc; diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/package.json b/lib/node_modules/@stdlib/blas/base/zdotc/package.json new file mode 100644 index 000000000000..bdf50e63a6e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/package.json @@ -0,0 +1,83 @@ +{ + "name": "@stdlib/blas/base/zdotc", + "version": "0.0.0", + "description": "Calculate the dot product of two double-precision complex 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", + "browser": "./lib/main.js", + "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", + "zdotc", + "dot", + "product", + "dot product", + "scalar", + "scalar product", + "inner", + "inner product", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "complex", + "complex128", + "float64", + "float", + "double", + "float64array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.js b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.js new file mode 100644 index 000000000000..76c7f9f3906b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/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 zdotc = 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 zdotc, '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 zdotc.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 zdotc = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( zdotc, 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 zdotc; + var main; + + main = require( './../lib/zdotc.js' ); + + zdotc = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( zdotc, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js new file mode 100644 index 000000000000..14a0cb2f2c51 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js @@ -0,0 +1,215 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex128 = require( '@stdlib/complex/float32/ctor' ); +var zdotc = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.deepEqual( typeof zdotc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.deepEqual( zdotc.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the dot product of complex vectors `x` and `y`', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 0.7, // 0 + -0.8, // 0 + -0.4, // 1 + -0.7 // 1 + ]); + y = new Complex128Array([ + 0.6, // 0 + -0.6, // 0 + -0.9, // 1 + 0.5 // 1 + ]); + expected = new Complex128( 0.91, -0.77 ); + + dot = zdotc( x.length, x, 1, 0, y, 1, 0 ); + t.deepEqual( dot, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns Complex( 0.0, 0.0 )', function test( t ) { + var expected; + var dot; + var x; + var y; + + expected = new Complex128( 0.0, 0.0 ); + x = new Complex128Array( [ -0.1, -0.9, 0.2, -0.8 ] ); + y = new Complex128Array( [ 0.7, -0.6, 0.1, -0.5 ] ); + + dot = zdotc( 0, x, 1, 0, y, 1, 0 ); + t.deepEqual( dot, expected, 'returns expected value' ); + + dot = zdotc( -4, x, 1, y, 1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 0 + -8, // 0 + -4, + -7, + -1, // 1 + -9, // 1 + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 0 + -6, // 0 + -9, // 1 + 5, // 1 + 7, + -6, + 1, + -5 + ]); + expected = new Complex128( 54, -80 ); + dot = zdotc( 2, x, 2, 0, y, 1, 0 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 0 + -8, // 0 + -4, + -7, + -1, // 1 + -9, // 1 + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 1 + -6, // 1 + -9, // 0 + 5, // 0 + 7, + -6, + 1, + -5 + ]); + expected = new Complex128( -55, 23 ); + + dot = zdotc( 2, x, 2, 0, y, -1, 1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `y` stride', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 0 + -8, // 0 + -4, // 1 + -7, // 1 + -1, + -9, + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 0 + -6, // 0 + -9, + 5, + 7, // 1 + -6, // 1 + 1, + -5 + ]); + expected = new Complex128( 104, 79 ); + + dot = zdotc( 2, x, 1, 0, y, 2, 0 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 1 + -8, // 1 + -4, // 0 + -7, // 0 + -1, + -9, + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 1 + -6, // 1 + -9, + 5, + 7, // 0 + -6, // 0 + 1, + -5 + ]); + expected = new Complex128( 104, 79 ); + + dot = zdotc( 2, x, -1, 1, y, -2, 2 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js new file mode 100644 index 000000000000..f4e51569579c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js @@ -0,0 +1,215 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var zdotc = require( './../lib/zdotc.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.deepEqual( typeof zdotc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.deepEqual( zdotc.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the dot product of vectors `x` and `y`', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 0.7, // 0 + -0.8, // 0 + -0.4, // 1 + -0.7 // 1 + ]); + y = new Complex128Array([ + 0.6, // 0 + -0.6, // 0 + -0.9, // 1 + 0.5 // 1 + ]); + expected = new Complex128( 0.91, -0.77 ); + + dot = zdotc( x.length, x, 1, y, 1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns Complex( 0.0, 0.0 )', function test( t ) { + var expected; + var dot; + var x; + var y; + + expected = new Complex128( 0.0, 0.0 ); + x = new Complex128Array( [-0.1, -0.9, 0.2, -0.8 ] ); + y = new Complex128Array( [ 0.7, -0.6, 0.1, -0.5 ] ); + + dot = zdotc( 0, x, 1, y, 1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + + dot = zdotc( -4, x, 1, y, 1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 0 + -8, // 0 + -4, + -7, + -1, // 1 + -9, // 1 + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 0 + -6, // 0 + -9, // 1 + 5, // 1 + 7, + -6, + 1, + -5 + ]); + expected = new Complex128( 54, -80 ); + dot = zdotc( 2, x, 2, y, 1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 0 + -8, // 0 + -4, + -7, + -1, // 1 + -9, // 1 + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 1 + -6, // 1 + -9, // 0 + 5, // 0 + 7, + -6, + 1, + -5 + ]); + expected = new Complex128( -55, 23 ); + + dot = zdotc( 2, x, 2, y, -1 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `y` stride', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 0 + -8, // 0 + -4, // 1 + -7, // 1 + -1, + -9, + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 0 + -6, // 0 + -9, + 5, + 7, // 1 + -6, // 1 + 1, + -5 + ]); + expected = new Complex128( 104, 79 ); + + dot = zdotc( 2, x, 1, y, 2 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var dot; + var x; + var y; + + x = new Complex128Array([ + 7, // 1 + -8, // 1 + -4, // 0 + -7, // 0 + -1, + -9, + 2, + -8 + ]); + y = new Complex128Array([ + 6, // 1 + -6, // 1 + -9, + 5, + 7, // 0 + -6, // 0 + 1, + -5 + ]); + expected = new Complex128( 104, 79 ); + + dot = zdotc( 2, x, -1, y, -2 ); + t.deepEqual( dot, expected, 'returns expected value' ); + t.end(); +}); From ad235afad44c72a8d4f0e1ec73593b2059474a65 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Mon, 28 Apr 2025 16:52:14 +0530 Subject: [PATCH 2/7] chore: update test cases --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/base/zdotc/test/test.ndarray.js | 18 +++++++++--------- .../@stdlib/blas/base/zdotc/test/test.zdotc.js | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js index 14a0cb2f2c51..c9f7a1b5a07c 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.ndarray.js @@ -46,18 +46,18 @@ tape( 'the function calculates the dot product of complex vectors `x` and `y`', var y; x = new Complex128Array([ - 0.7, // 0 - -0.8, // 0 - -0.4, // 1 - -0.7 // 1 + 1.0, // 0 + 2.0, // 0 + 3.0, // 1 + 4.0 // 1 ]); y = new Complex128Array([ - 0.6, // 0 - -0.6, // 0 - -0.9, // 1 - 0.5 // 1 + -5.0, // 0 + 1.0, // 0 + -6.0, // 1 + 7.0 // 1 ]); - expected = new Complex128( 0.91, -0.77 ); + expected = new Complex128( 7.0, 56.0 ); dot = zdotc( x.length, x, 1, 0, y, 1, 0 ); t.deepEqual( dot, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js index f4e51569579c..2d2de04bc77b 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/test/test.zdotc.js @@ -46,18 +46,18 @@ tape( 'the function calculates the dot product of vectors `x` and `y`', function var y; x = new Complex128Array([ - 0.7, // 0 - -0.8, // 0 - -0.4, // 1 - -0.7 // 1 + 1.0, // 0 + 2.0, // 0 + 3.0, // 1 + 4.0 // 1 ]); y = new Complex128Array([ - 0.6, // 0 - -0.6, // 0 - -0.9, // 1 - 0.5 // 1 + -5.0, // 0 + 1.0, // 0 + -6.0, // 1 + 7.0 // 1 ]); - expected = new Complex128( 0.91, -0.77 ); + expected = new Complex128( 7.0, 56.0 ); dot = zdotc( x.length, x, 1, y, 1 ); t.deepEqual( dot, expected, 'returns expected value' ); From ed6aa6786ea6550064dabcc54ec86e142fcddc31 Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Tue, 29 Apr 2025 08:41:26 +0530 Subject: [PATCH 3/7] chore: update benchmark Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js index 0571e2ca6144..145246103339 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js @@ -74,7 +74,7 @@ function createBenchmark( len ) { } } b.toc(); - if ( isnan( real( z ) ) || isnan( imag( z ) ) ) { + if ( isnan( real( z ) ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); From 7e96ed3d62fe84f814ca76d96c64e40e1b34634d Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Tue, 29 Apr 2025 08:42:18 +0530 Subject: [PATCH 4/7] remove: unused package Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js index 145246103339..4b96deb4f90c 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js @@ -26,7 +26,6 @@ var pow = require( '@stdlib/math/base/special/pow' ); var Complex128Array = require( '@stdlib/array/complex128' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var real = require( '@stdlib/complex/float64/real' ); -var imag = require( '@stdlib/complex/float64/imag' ); var pkg = require( './../package.json' ).name; var zdotc = require( './../lib/zdotc.js' ); From c476dcdc2322886b0d14462847aa17cdff15edb0 Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Tue, 29 Apr 2025 08:44:32 +0530 Subject: [PATCH 5/7] chore: update benchmark Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- .../@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js index bfafc4dc9f60..74d10574a52e 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js @@ -26,7 +26,6 @@ var pow = require( '@stdlib/math/base/special/pow' ); var Complex128Array = require( '@stdlib/array/complex128' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var real = require( '@stdlib/complex/float64/real' ); -var imag = require( '@stdlib/complex/float64/imag' ); var pkg = require( './../package.json' ).name; var zdotc = require( './../lib/ndarray.js' ); @@ -69,7 +68,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { z = zdotc( x.length, x, 1, 0, y, 1, 0 ); - if ( isnan( real( z ) ) || isnan( imag( z ) )) { + if ( isnan( real( z ) ) ) { b.fail( 'should not return NaN' ); } } From 75faea68f86aef6548699eaf27d6d3c8efbc4aa7 Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Tue, 29 Apr 2025 08:47:33 +0530 Subject: [PATCH 6/7] chore: update benchmark Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- .../@stdlib/blas/base/zdotc/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js index 4b96deb4f90c..0fc7c4f3e470 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.js @@ -68,12 +68,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { z = zdotc( x.length, x, 1, y, 1 ); - if ( isnan( real( z ) ) || isnan( imag( z ) ) ) { + if ( isnan( real( z ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( real( z ) ) ) ) { + if ( isnan( real( z ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); From d311880a7cad58b646604d58e078aa3a72b68bae Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Tue, 29 Apr 2025 08:48:23 +0530 Subject: [PATCH 7/7] chore: update benchmark Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- .../@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js index 74d10574a52e..84272dec6f15 100644 --- a/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/zdotc/benchmark/benchmark.ndarray.js @@ -73,7 +73,7 @@ function createBenchmark( len ) { } } b.toc(); - if ( isnan( real( z ) ) || isnan( imag( z ) )) { + if ( isnan( real( z ) ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' );