From 7d65943604945f9a9e3ad63267c9d91a8c26da2c Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Sun, 14 Jul 2024 07:23:00 +0530 Subject: [PATCH] feat: add `blas/base/caxpy` PR-URL: https://github.com/stdlib-js/stdlib/pull/2121 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/caxpy/README.md | 256 +++++++ .../blas/base/caxpy/benchmark/benchmark.js | 115 ++++ .../base/caxpy/benchmark/benchmark.ndarray.js | 115 ++++ .../@stdlib/blas/base/caxpy/docs/repl.txt | 142 ++++ .../blas/base/caxpy/docs/types/index.d.ts | 159 +++++ .../blas/base/caxpy/docs/types/test.ts | 300 +++++++++ .../@stdlib/blas/base/caxpy/examples/index.js | 43 ++ .../@stdlib/blas/base/caxpy/lib/caxpy.js | 70 ++ .../@stdlib/blas/base/caxpy/lib/index.js | 94 +++ .../@stdlib/blas/base/caxpy/lib/main.js | 35 + .../@stdlib/blas/base/caxpy/lib/ndarray.js | 88 +++ .../@stdlib/blas/base/caxpy/package.json | 79 +++ .../blas/base/caxpy/test/test.caxpy.js | 538 +++++++++++++++ .../@stdlib/blas/base/caxpy/test/test.js | 82 +++ .../blas/base/caxpy/test/test.ndarray.js | 623 ++++++++++++++++++ 15 files changed, 2739 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/README.md b/lib/node_modules/@stdlib/blas/base/caxpy/README.md new file mode 100644 index 000000000000..4d2888d103e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/README.md @@ -0,0 +1,256 @@ + + +# caxpy + +> Scale a single-precision complex floating-point vector by a single-precision complex floating-point constant and add the result to a single-precision complex floating-point vector. + +
+ +## Usage + +```javascript +var caxpy = require( '@stdlib/blas/base/caxpy' ); +``` + +#### caxpy( N, ca, cx, strideX, cy, strideY ) + +Scales values from `cx` by `ca` and adds the result to `cy`. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require('@stdlib/complex/float32/ctor'); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var ca = new Complex64( 2.0, 2.0 ); + +caxpy( 3, ca, cx, 1, cy, 1 ); + +var z = cy.get( 0 ); +// returns + +var re = realf( z ); +// returns -1.0 + +var im = imagf( z ); +// returns 7.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **ca**: scalar [`Complex64`][@stdlib/complex/float32/ctor] constant. +- **cx**: first input [`Complex64Array`][@stdlib/array/complex64]. +- **strideX**: index increment for `cx`. +- **cy**: second input [`Complex64Array`][@stdlib/array/complex64]. +- **strideY**: index increment for `cy`. + +The `N` and stride parameters determine how values from `cx` are scaled by `ca` and added to `cy`. For example, to scale every other value in `cx` by `ca` and add the result to every other value of `cy`, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var ca = new Complex64( 2.0, 2.0 ); + +caxpy( 2, ca, cx, 2, cy, 2 ); + +var z = cy.get( 0 ); +// returns + +var re = realf( z ); +// returns -1.0 + +var im = imagf( z ); +// returns 7.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +// Initial arrays... +var cx0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var cy0 = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// Define a scalar constant: +var ca = new Complex64( 2.0, 2.0 ); + +// Create offset views... +var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var cy1 = new Complex64Array( cy0.buffer, cy0.BYTES_PER_ELEMENT*2 ); // start at 3rd element + +// Scales values of `cx0` by `ca` starting from second index and add the result to `cy0` starting from third index... +caxpy( 2, ca, cx1, 1, cy1, 1 ); + +var z = cy0.get( 2 ); +// returns + +var re = realf( z ); +// returns -1.0 + +var im = imagf( z ); +// returns 15.0 +``` + +#### caxpy.ndarray( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) + +Scales values from `cx` by `ca` and adds the result to `cy` using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var ca = new Complex64( 2.0, 2.0 ); + +caxpy.ndarray( 3, ca, cx, 1, 0, cy, 1, 0 ); + +var z = cy.get( 0 ); +// returns + +var re = realf( z ); +// returns -1.0 + +var im = imagf( z ); +// returns 7.0 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `cx`. +- **offsetY**: starting index for `cy`. + +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 scale values in the first input strided array starting from the second element and add the result to the second input array starting from the second element, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var ca = new Complex64( 2.0, 2.0 ); + +caxpy.ndarray( 3, ca, cx, 1, 1, cy, 1, 1 ); + +var z = cy.get( 3 ); +// returns + +var re = realf( z ); +// returns -1.0 + +var im = imagf( z ); +// returns 31.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `cy` unchanged. +- `caxpy()` corresponds to the [BLAS][blas] level 1 function [`caxpy`][caxpy]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ccopy = require( '@stdlib/blas/base/ccopy' ); +var zeros = require( '@stdlib/array/zeros' ); +var logEach = require( '@stdlib/console/log-each' ); +var caxpy = require( '@stdlib/blas/base/caxpy' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +var cy = filledarrayBy( 10, 'complex64', rand ); +var cyc = ccopy( cy.length, cy, 1, zeros( cy.length, 'complex64' ), 1 ); + +var ca = new Complex64( 2.0, 2.0 ); + +// Scale values from `cx` by `ca` and add the result to `cy`: +caxpy( cx.length, ca, cx, 1, cy, 1 ); + +// Print the results: +logEach( '(%s)*(%s) + (%s) = %s', ca, cx, cyc, cy ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js new file mode 100644 index 000000000000..b59bd3a45aa8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var pkg = require( './../package.json' ).name; +var caxpy = require( './../lib/caxpy.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + cy = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + + viewY = reinterpret( cy, 0 ); + + ca = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + caxpy( cx.length, ca, cx, 1, cy, 1 ); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + 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/caxpy/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..127c8edbcafd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var pkg = require( './../package.json' ).name; +var caxpy = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + cy = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + + viewY = reinterpret( cy, 0 ); + + ca = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + caxpy( cx.length, ca, cx, 1, 0, cy, 1, 0 ); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + 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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt new file mode 100644 index 000000000000..8a823c8cfc14 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt @@ -0,0 +1,142 @@ + +{{alias}}( N, ca, cx, strideX, cy, strideY ) + Scales a single-precision complex floating-point vector by a single- + precision complex floating point constant and adds the result to a single- + precision complex floating-point vector. + + The `N` and stride parameters determine how values from `cx` are scaled by + `ca` and added to `cy`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N` is less than or equal to `0`, the function returns `cy` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + ca: Complex64 + Scalar constant. + + cx: Complex64Array + First input array. + + strideX: integer + Index increment for `cx`. + + cy: Complex64Array + Second input array. + + strideY: integer + Index increment for `cy`. + + Returns + ------- + cy: Complex64Array + Second input array. + + Examples + -------- + // Standard usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var cy = new {{alias:@stdlib/array/complex64}}( [ 1.0, 1.0, 1.0, 1.0 ] ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); + > {{alias}}( 2, ca, cx, 1, cy, 1 ); + > var z = cy.get( 0 ); + > var re = {{alias:@stdlib/complex/realf}}( z ) + -1.0 + > var im = {{alias:@stdlib/complex/imagf}}( z ) + 7.0 + + // Advanced indexing: + > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > cy = new {{alias:@stdlib/array/complex64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > {{alias}}( 2, ca, cx, -2, cy, 1 ); + > z = cy.get( 0 ); + > re = {{alias:@stdlib/complex/realf}}( z ) + -1.0 + > im = {{alias:@stdlib/complex/imagf}}( z ) + 23.0 + + // Using typed array views: + > var cx0 = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var cy0 = new {{alias:@stdlib/array/complex64}}( [ 1.0, 1.0, 1.0, 1.0 ] ); + > var cx1 = new {{alias:@stdlib/array/complex64}}( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + > var cy1 = new {{alias:@stdlib/array/complex64}}( cy0.buffer, cy0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 1, ca, cx1, 1, cy1, 1 ); + > z = cy0.get( 1 ); + > re = {{alias:@stdlib/complex/realf}}( z ) + -1.0 + > im = {{alias:@stdlib/complex/imagf}}( z ) + 15.0 + + +{{alias}}.ndarray( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) + Scales a single-precision complex floating-point vector by a single- + precision complex floating-point constant and adds the result to a single- + precision complex floating-point vector using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + ca: Complex64 + Scalar constant. + + cx: Complex64Array + First input array. + + strideX: integer + Index increment for `cx`. + + offsetX: integer + Starting index for `cx`. + + cy: Complex64Array + Second input array. + + strideY: integer + Index increment for `cy`. + + offsetY: integer + Starting index for `cy`. + + Returns + ------- + cy: Complex64Array + Second input array. + + Examples + -------- + // Standard usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var cy = new {{alias:@stdlib/array/complex64}}( [ 1.0, 1.0, 1.0, 1.0 ] ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); + > {{alias}}.ndarray( cx.length, ca, cx, 1, 0, cy, 1, 0 ); + > var z = cy.get( 0 ); + > var re = {{alias:@stdlib/complex/realf}}( z ) + -1.0 + > var im = {{alias:@stdlib/complex/imagf}}( z ) + 7.0 + + // Advanced indexing: + > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > cy = new {{alias:@stdlib/array/complex64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > {{alias}}.ndarray( 2, ca, cx, 1, 1, cy, 1, 1 ); + > z = cy.get( 2 ); + > re = {{alias:@stdlib/complex/realf}}( z ) + -1.0 + > im = {{alias:@stdlib/complex/imagf}}( z ) + 23.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/index.d.ts new file mode 100644 index 000000000000..f05c1c4783b0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/index.d.ts @@ -0,0 +1,159 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 { Complex64Array } from '@stdlib/types/array'; +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Interface describing `caxpy`. +*/ +interface Routine { + /** + * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. + * + * @param N - number of indexed elements + * @param ca - scalar constant + * @param cx - first input array + * @param strideX - `cx` stride length + * @param cy - second input array + * @param strideY - `cy` stride length + * @returns second input array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var realf = require( '@stdlib/complex/realf' ); + * var imagf = require( '@stdlib/complex/imagf' ); + * + * var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * var ca = new Complex64( 2.0, 2.0 ); + * + * caxpy( cx.length, ca, cx, 1, cy, 1 ); + * + * var z = cy.get( 0 ); + * // returns + * + * var re = realf( z ); + * // returns -1.0 + * + * var im = imagf( z ); + * // returns 7.0 + */ + ( N: number, ca: Complex64, cx: Complex64Array, strideX: number, cy: Complex64Array, strideY: number ): Complex64Array; + + /** + * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. + * + * @param N - number of indexed elements + * @param ca - scalar constant + * @param cx - first input array + * @param strideX - `cx` stride length + * @param offsetX - starting index for `cx` + * @param cy - second input array + * @param strideY - `cy` stride length + * @param offsetY - starting index for `cy` + * @returns second input array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var realf = require( '@stdlib/complex/realf' ); + * var imagf = require( '@stdlib/complex/imagf' ); + * + * var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * var ca = new Complex64( 2.0, 2.0 ); + * + * caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, 0 ); + * + * var z = cy.get( 0 ); + * // returns + * + * var re = realf( z ); + * // returns -1.0 + * + * var im = imagf( z ); + * // returns 7.0 + */ + ndarray( N: number, ca: Complex64, cx: Complex64Array, strideX: number, offsetX: number, cy: Complex64Array, strideY: number, offsetY: number ): Complex64Array; +} + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. +* +* @param N - number of indexed elements +* @param ca - scalar constant +* @param cx - first input array +* @param strideX - `cx` stride length +* @param cy - second input array +* @param strideY - `cy` stride length +* @returns second input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy( 2, ca, cx, 2, cy, 2 ); +* +* var z = cy.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.0 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy.ndarray( 3, ca, cx, 1, 1, cy, 1, 1 ); +* +* var z = cy.get( 3 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 31.0 +*/ +declare var caxpy: Routine; + + +// EXPORTS // + +export = caxpy; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts new file mode 100644 index 000000000000..e7ffcb48981d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts @@ -0,0 +1,300 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Complex64Array = require( '@stdlib/array/complex64' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import caxpy = require( './index' ); + + +// TESTS // + +// The function returns a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy( cx.length, ca, cx, 1, cy, 1 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy( '10', ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( true, ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( false, ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( null, ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( undefined, ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( [], ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( {}, ca, cx, 1, cy, 1 ); // $ExpectError + caxpy( ( cx: number ): number => cx, ca, cx, 1, cy, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a complex number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + + caxpy( cx.length, 10, cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, '10', cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, true, cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, false, cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, null, cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, undefined, cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, [ '1' ], cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, {}, cx, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ( cx: number ): number => cx, cx, 1, cy, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy( cx.length, ca, 10, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, '10', 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, true, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, false, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, null, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, undefined, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, [ '1' ], 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, {}, 1, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, ( cx: number ): number => cx, 1, cy, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy( cx.length, ca, cx, '10', cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, true, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, false, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, null, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, undefined, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, [], cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, {}, cy, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, ( cx: number ): number => cx, cy, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy( cx.length, ca, cx, 1, 10, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, '10', 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, true, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, false, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, null, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, undefined, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, [ '1' ], 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, {}, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, ( cx: number ): number => cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy( cx.length, ca, cx, 1, cy, '10' ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, true ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, false ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, null ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, undefined ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, [] ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, {} ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, ( cx: number ): number => cx ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy(); // $ExpectError + caxpy( cx.length ); // $ExpectError + caxpy( cx.length, ca ); // $ExpectError + caxpy( cx.length, ca, cx ); // $ExpectError + caxpy( cx.length, ca, cx, 1 ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy ); // $ExpectError + caxpy( cx.length, ca, cx, 1, cy, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( '10', ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( true, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( false, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( null, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( undefined, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( [], ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( {}, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( ( cx: number ): number => cx, ca, cx, 1, 0, cy, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a complex number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + + caxpy.ndarray( cx.length, 10, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, '10', cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, true, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, false, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, null, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, undefined, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, [ '1' ], cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, {}, cx, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ( cx: number ): number => cx, cx, 1, 0, cy, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, 10, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, '10', 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, true, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, false, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, null, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, undefined, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, [ '1' ], 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, {}, 1, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, ( cx: number ): number => cx, 1, 0, cy, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, cx, '10', 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, true, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, false, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, null, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, undefined, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, [], 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, {}, 0, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, ( cx: number ): number => cx, 0, cy, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, cx, 1, '10', cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, true, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, false, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, null, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, undefined, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, [], cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, {}, cy, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, ( cx: number ): number => cx, cy, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, cx, 1, 0, 10, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, '10', 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, true, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, false, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, null, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, undefined, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, {}, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, ( cx: number ): number => cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, '10', 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, true, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, false, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, null, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, undefined, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, [], 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, {}, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, ( cx: number ): number => cx, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, '10' ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, true ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, false ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, null ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, undefined ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, [] ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, {} ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, ( cx: number ): number => cx ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const cx = new Complex64Array( 10 ); + const cy = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + caxpy.ndarray(); // $ExpectError + caxpy.ndarray( cx.length ); // $ExpectError + caxpy.ndarray( cx.length, ca ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1 ); // $ExpectError + caxpy.ndarray( cx.length, ca, cx, 1, 0, cy, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js new file mode 100644 index 000000000000..d88440e7f0e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ccopy = require( '@stdlib/blas/base/ccopy' ); +var zeros = require( '@stdlib/array/zeros' ); +var logEach = require( '@stdlib/console/log-each' ); +var caxpy = require( './../lib' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +var cy = filledarrayBy( 10, 'complex64', rand ); +var cyc = ccopy( cy.length, cy, 1, zeros( cy.length, 'complex64' ), 1 ); + +var ca = new Complex64( 2.0, 2.0 ); + +// Scale values from `cx` by `ca` and add the result to `cy`: +caxpy( cx.length, ca, cx, 1, cy, 1 ); + +// Print the results: +logEach( '(%s)*(%s) + (%s) = %s', ca, cx, cyc, cy ); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js new file mode 100644 index 000000000000..b56bf5657428 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 // + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - first input array +* @param {integer} strideX - `cx` stride length +* @param {Complex64Array} cy - second input array +* @param {integer} strideY - `cy` stride length +* @returns {Complex64Array} second input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy( 3, ca, cx, 1, cy, 1 ); +* +* var z = cy.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.0 +*/ +function caxpy( N, ca, cx, strideX, cy, strideY ) { + var ix = stride2offset( N, strideX ); + var iy = stride2offset( N, strideY ); + return ndarray( N, ca, cx, strideX, ix, cy, strideY, iy ); +} + + +// EXPORTS // + +module.exports = caxpy; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js new file mode 100644 index 000000000000..7e9d281df265 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 scale a single-precision complex floating-point vector by a single-precision complex floating-point constant and add the result to a single-precision complex floating-point vector. +* +* @module @stdlib/blas/base/caxpy +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* var caxpy = require( '@stdlib/blas/base/caxpy' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy( 3, ca, cx, 1, cy, 1 ); +* +* var z = cy.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.0 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* var caxpy = require( '@stdlib/blas/base/caxpy' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy.ndarray( 3, ca cx, 1, 0, cy, 1, 0); +* +* var z = cy.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.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 caxpy; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + caxpy = main; +} else { + caxpy = tmp; +} + + +// EXPORTS // + +module.exports = caxpy; + +// exports: { "ndarray": "caxpy.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/main.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/main.js new file mode 100644 index 000000000000..4f149abb7331 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 caxpy = require( './caxpy.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( caxpy, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = caxpy; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js new file mode 100644 index 000000000000..d97fd05aaa51 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 scabs1 = require( '@stdlib/blas/base/scabs1' ); +var cmulf = require( '@stdlib/math/base/ops/cmulf' ); +var caddf = require( '@stdlib/math/base/ops/caddf' ); + + +// MAIN // + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - first input array +* @param {integer} strideX - `cx` stride length +* @param {integer} offsetX - starting index for `cx` +* @param {Complex64Array} cy - second input array +* @param {integer} strideY - `cy` stride length +* @param {integer} offsetY - starting index for `cy` +* @returns {Complex64Array} second input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy( 3, ca, cx, 1, 0, cy, 1, 0 ); +* +* var z = cy.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.0 +*/ +function caxpy( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) { + var ix; + var iy; + var i; + + if ( N <= 0 ) { + return cy; + } + if ( scabs1( ca ) === 0.0 ) { + return cy; + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + cy.set( caddf( cmulf( ca, cx.get( ix ) ), cy.get( iy ) ), iy ); + ix += strideX; + iy += strideY; + } + return cy; +} + + +// EXPORTS // + +module.exports = caxpy; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/package.json b/lib/node_modules/@stdlib/blas/base/caxpy/package.json new file mode 100644 index 000000000000..4bad808433a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/package.json @@ -0,0 +1,79 @@ +{ + "name": "@stdlib/blas/base/caxpy", + "version": "0.0.0", + "description": "Scale a single-precision complex floating-point vector by a single-precision complex floating-point constant and add the result to a single-precision complex floating-point vector.", + "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", + "caxpy", + "scale", + "add", + "cp", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex64", + "float", + "float32", + "single", + "float32array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js new file mode 100644 index 000000000000..941e9004be22 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -0,0 +1,538 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var caxpy = require( './../lib/caxpy.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof caxpy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( caxpy.length, 6, 'arity of 6' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy`', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, cy, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.55, // 2 + 0.5, // 2 + 0.03, // 3 + -0.89, // 3 + -0.38, // 4 + -0.96, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cx` stride', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, cy, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.57, // 2 + 0.21, // 2 + 0.06, // 3 + -0.13, // 3 + 0.28, // 4 + 0.16, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cy` stride', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, + 0.5, + 0.7, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.1, // 3 + -0.2, // 3 + -0.5, + -0.3, + 0.8, // 4 + -0.7 // 4 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, cy, 2 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -0.9, + 0.5, + 0.05, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.77, // 3 + -0.49, // 3 + -0.5, + -0.3, + 0.32, // 4 + -1.16 // 4 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = caxpy( cx.length, ca, cx, 1, cy, 1 ); + + t.strictEqual( out, cy, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the second input array unchanged', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + caxpy( -1, ca, cx, 1, cy, 1 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + caxpy( 0, ca, cx, 1, cy, 1 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative `cx` strides', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, + -0.7, + -0.1, // 3 + -0.9, // 3 + 0.2, + -0.8, + -0.9, // 2 + -0.4, // 2 + 0.1, + 0.4, + -0.6, // 1 + 0.6 // 1 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -2, cy, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 1 + 0.06, // 1 + -1.54, // 2 + 0.97, // 2 + 0.03, // 3 + -0.89, // 3 + -0.18, // 4 + -1.31, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports negative `cy` strides', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, cy, -2 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 4 + 0.06, // 4 + -0.9, + 0.5, + 0.06, // 3 + -0.13, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.52, // 1 + -1.51 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, // 3 + -0.7, // 3 + -0.1, // 2 + -0.9, // 2 + 0.2, // 1 + -0.8, // 1 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -1, cy, -2 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 4 + -1.41, // 4 + -0.9, + 0.5, + 0.05, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.32, // 1 + -1.16 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var viewY; + var cx0; + var cy0; + var cx1; + var cy1; + var ca; + + // Initial arrays... + cx0 = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, + 6.0 + ]); + cy0 = new Complex64Array([ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, // 1 + 1.0 // 1 + ]); + + // Define a scalar constant: + ca = new Complex64( 2.0, 2.0 ); + + // Create offset views... + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at the 2nd element + cy1 = new Complex64Array( cy0.buffer, cy0.BYTES_PER_ELEMENT*2 ); // begin at the 3rd element + + caxpy( 1, ca, cx1, 1, cy1, 1 ); + + viewY = new Float32Array( cy0.buffer ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, -1.0, 15.0 ] ); + + t.deepEqual( viewY, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.js b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.js new file mode 100644 index 000000000000..dc9b77d849f1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isBrowser = require( '@stdlib/assert/is-browser' ); +var caxpy = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof caxpy, '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 caxpy.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 caxpy = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( caxpy, mock, 'returns native implementation' ); + 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 caxpy; + var main; + + main = require( './../lib/caxpy.js' ); + + caxpy = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( caxpy, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js new file mode 100644 index 000000000000..4a8e411efd9e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js @@ -0,0 +1,623 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var caxpy = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof caxpy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( caxpy.length, 8, 'arity of 8' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy`', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, 0, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.55, // 2 + 0.5, // 2 + 0.03, // 3 + -0.89, // 3 + -0.38, // 4 + -0.96, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cx` stride', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, 0, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.57, // 2 + 0.21, // 2 + 0.06, // 3 + -0.13, // 3 + 0.28, // 4 + 0.16, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cx` offset', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, + -0.8, + -0.4, // 1 + -0.7, // 1 + -0.1, + -0.9, + 0.2, // 2 + -0.8, // 2 + -0.9, + -0.4, + 0.1, // 3 + 0.4, // 3 + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 3, ca, cx, 2, 1, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + -0.05, // 1 + -0.6, // 1 + -1.38, // 2 + 0.04, // 2 + 1.02, // 3 + -0.51, // 3 + 0.1, + -0.5, + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cy` stride', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, + 0.5, + 0.7, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.1, // 3 + -0.2, // 3 + -0.5, + -0.3, + 0.8, // 4 + -0.7 // 4 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, 0, cy, 2, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -0.9, + 0.5, + 0.05, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.77, // 3 + -0.49, // 3 + -0.5, + -0.3, + 0.32, // 4 + -1.16 // 4 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cy` offset', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, + -0.8, + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, + -0.6, + -0.9, // 1 + 0.5, // 1 + 0.7, + -0.6, + 0.1, // 2 + -0.5, // 2 + -0.1, + -0.2, + -0.5, // 3 + -0.3, // 3 + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 3, ca, cx, 1, 0, cy, 2, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.6, + -0.6, + -1.18, // 1 + -0.31, // 1 + 0.7, + -0.6, + -0.55, // 2 + -0.5, // 2 + -0.1, + -0.2, + -1.17, // 3 + -0.59, // 3 + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = caxpy( cx.length, ca, cx, 1, 0, cy, 1, 0 ); + + t.strictEqual( out, cy, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the second input array unchanged', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + caxpy( -1, ca, cx, 1, 0, cy, 1, 0 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + caxpy( 0, ca, cx, 1, 0, cy, 1, 0 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `cx` stride', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, + -0.7, + -0.1, // 3 + -0.9, // 3 + 0.2, + -0.8, + -0.9, // 2 + -0.4, // 2 + 0.1, + 0.4, + -0.6, // 1 + 0.6 // 1 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -2, 6, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 1 + 0.06, // 1 + -1.54, // 2 + 0.97, // 2 + 0.03, // 3 + -0.89, // 3 + -0.18, // 4 + -1.31, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a negative `cy` stride', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, 0, cy, -2, 6 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 4 + 0.06, // 4 + -0.9, + 0.5, + 0.06, // 3 + -0.13, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.52, // 1 + -1.51 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, // 3 + -0.7, // 3 + -0.1, // 2 + -0.9, // 2 + 0.2, // 1 + -0.8, // 1 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -1, 3, cy, -2, 6 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 4 + -1.41, // 4 + -0.9, + 0.5, + 0.05, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.32, // 1 + -1.16 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +});