From b34ee1fefa321972cd3dcbb0b08c9f524f14a346 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 4 Apr 2024 23:29:55 +0530 Subject: [PATCH 01/16] feat: add BLAS Level 1 caxpy --- .../@stdlib/blas/base/caxpy/README.md | 253 +++++++ .../blas/base/caxpy/benchmark/benchmark.js | 117 +++ .../base/caxpy/benchmark/benchmark.ndarray.js | 117 +++ .../@stdlib/blas/base/caxpy/docs/repl.txt | 145 ++++ .../blas/base/caxpy/docs/types/index.d.ts | 159 ++++ .../blas/base/caxpy/docs/types/test.ts | 300 ++++++++ .../@stdlib/blas/base/caxpy/examples/index.js | 40 + .../@stdlib/blas/base/caxpy/lib/caxpy.js | 102 +++ .../@stdlib/blas/base/caxpy/lib/index.js | 94 +++ .../@stdlib/blas/base/caxpy/lib/main.js | 35 + .../@stdlib/blas/base/caxpy/lib/ndarray.js | 98 +++ .../@stdlib/blas/base/caxpy/package.json | 79 ++ .../blas/base/caxpy/test/test.caxpy.js | 583 +++++++++++++++ .../@stdlib/blas/base/caxpy/test/test.js | 82 +++ .../blas/base/caxpy/test/test.ndarray.js | 690 ++++++++++++++++++ 15 files changed, 2894 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..58ae7a08fd4a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/README.md @@ -0,0 +1,253 @@ + + +# caxpy + +> 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. + +
+ +## Usage + +```javascript +var caxpy = require( '@stdlib/blas/base/caxpy' ); +``` + +#### caxpy( N, ca, cx, strideX, cy, strideY ) + +Scales values from `x` by `ca` and adds the result to `y`. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require('@stdlib/complex/float32'); +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] constant. +- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. +- **strideX**: index increment for `x`. +- **cy**: input [`Complex64Array`][@stdlib/array/complex64]. +- **strideY**: index increment for `y`. + +The `N` and stride parameters determine how values from `cx` are scaled by `ca` and added to `y`. For example, to scale every other value in `cx` by `ca` and add th result to every other value of `cy`, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32' ); +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' ); +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 ] ); + +// Complex 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 add the result to `cy` using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32' ); +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 `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 scale every other value in the first input strided array starting from the second element and add the result to second input array starting from the second element, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32' ); +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' ); +var caxpy = require( '@stdlib/blas/base/caxpy' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.get( 0 ).toString() ); + +var cy = filledarrayBy( 10, 'complex64', rand ); +console.log( cy.get( 0 ).toString() ); + +var ca = new Complex64( 2.0, 2.0 ); + +// Scales values from `cx` by `ca` and add the result to `cy`: +caxpy( cx.length, ca, cx, 1, cy, 1 ); +console.log( cy.get( cy.length-1 ).toString() ); +``` + +
+ + + + + + + + + + + + + + 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..28804617d12e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js @@ -0,0 +1,117 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32' ); +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 = uniform( len*2, -100.0, 100.0, options ); + cx = new Complex64Array( cx.buffer ); + + cy = uniform( len*2, -100.0, 100.0, options ); + cy = new Complex64Array( cy.buffer ); + + 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 ); + viewY = reinterpret( cy, 0 ); + if ( isnan( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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..496890da69e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js @@ -0,0 +1,117 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32' ); +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 = uniform( len*2, -100.0, 100.0, options ); + cx = new Complex64Array( cx.buffer ); + + cy = uniform( len*2, -100.0, 100.0, options ); + cy = new Complex64Array( cy.buffer ); + + 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 ); + viewY = reinterpret( cy, 0 ); + if ( isnan( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt new file mode 100644 index 000000000000..ae8639f8a27a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt @@ -0,0 +1,145 @@ + +{{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 + Complex constant. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `x`. + + cy: Complex64Array + Output array. + + strideY: integer + Index increment for `y`. + + Returns + ------- + cy: Complex64Array + Output 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}}( 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 ] ); + > ca = new {{alias:@stdlib/complex/float32}}( 2.0, 2.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 ca = new {{alias:@stdlib/complex/float32}}( 2.0, 2.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 + Complex constant. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + cy: Complex64Array + Output array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + cy: Complex64Array + Output 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}}( 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 ] ); + > ca = new {{alias:@stdlib/complex/float32}}( 2.0, 2.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..6fda9431a3e8 --- /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 - complex constant + * @param cx - input array + * @param strideX - `x` stride length + * @param cy - output array + * @param strideY - `y` stride length + * @returns output array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32' ); + * 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 - complex constant + * @param cx - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param cy - output array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns output array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32' ); + * 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, x: Complex64Array, strideX: number, offsetX: number, y: 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 - complex constant +* @param cx - input array +* @param strideX - `x` stride length +* @param cy - output array +* @param strideY - `y` stride length +* @returns output array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32' ); +* 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' ); +* 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..c1ecb966a173 --- /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' ); +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 Complex64... +{ + 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 Complex64... +{ + 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 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, 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..815e057c3e18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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' ); +var caxpy = require( '@stdlib/blas/base/caxpy' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.get( 0 ).toString() ); + +var cy = filledarrayBy( 10, 'complex64', rand ); +console.log( cy.get( 0 ).toString() ); + +var ca = new Complex64( 2.0, 2.0 ); + +// Scales values from `cx` by `ca` and add the result to `cy`: +caxpy( cx.length, ca, cx, 1, cy, 1 ); +console.log( cy.get( cy.length-1 ).toString() ); 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..dc4fb422665a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js @@ -0,0 +1,102 @@ +/** +* @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 cmulf = require( '@stdlib/math/base/ops/cmulf' ); +var cabsf = require( '@stdlib/math/base/special/cabsf' ); +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 - constant +* @param {Complex64Array} cx - input array +* @param {integer} strideX - `x` stride length +* @param {Complex64Array} cy - input array +* @param {integer} strideY - `y` stride length +* @returns {Complex64Array} output array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32' ); +* 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; + var iy; + var i; + + if ( N <= 0 ) { + return cy; + } + if ( cabsf( ca ) === 0.0 ) { + return cy; + } + if ( strideX === 1 && strideY === 1 ) { + // Code for stride equal to `1`... + for ( i = 0; i < N; i++ ) { + cy.set( caddf( cmulf( ca, cx.get( i ) ), cy.get( i ) ), i ); + } + return cy; + } + // Code for stride not equal to `1`... + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = ( 1 - N ) * strideY; + } else { + iy = 0; + } + 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/lib/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js new file mode 100644 index 000000000000..e432dba0a79d --- /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 adds 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' ); +* 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 -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32' ); +* 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 -2.0 +* +* var im = imagf( z ); +* // returns 6.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..520d73cb22d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js @@ -0,0 +1,98 @@ +/** +* @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 cmulf = require( '@stdlib/math/base/ops/cmulf' ); +var cabsf = require( '@stdlib/math/base/special/cabsf' ); +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 - constant +* @param {Complex64Array} cx - input array +* @param {integer} strideX - `x` stride length +* @param {integer} offsetX - `x` offset +* @param {Complex64Array} cy - input array +* @param {integer} strideY - `y` stride length +* @param {integer} offsetY - `y` offset +* @returns {Complex64Array} output array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32' ); +* 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 ( cabsf( ca ) === 0.0 ) { + return cy; + } + ix = offsetX; + iy = offsetY; + if ( strideX === 1 && strideY === 1 ) { + // Code for stride equal to `1`... + for ( i = 0; i < N; i++ ) { + cy.set( caddf( cmulf( ca, cx.get( ix ) ), cy.get( iy ) ), iy ); + ix += strideX; + iy += strideY; + } + return cy; + } + // Code for stride not equal to `1`... + 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..c1b8570c67d1 --- /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": "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.", + "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..7c85b04c7ef8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -0,0 +1,583 @@ +/** +* @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' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var caxpy = require( './../lib/caxpy.js' ); + + +// 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 result to `cy`', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + 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 output 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 `x` strides', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports negative `y` strides', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + 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, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + cy0 = new Complex64Array([ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, // 1 + 1.0, // 1 + 1.0, // 2 + 1.0 // 2 + ]); + ca = new Complex64( 2.0, 2.0 ); + + // Create offset views... + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + cy1 = new Complex64Array( cy0.buffer, cy0.BYTES_PER_ELEMENT*2 ); // begin at the 3rd element + + caxpy( 2, 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, -1.0, 23.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..bd553971a044 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js @@ -0,0 +1,690 @@ +/** +* @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' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var caxpy = require( './../lib/ndarray.js' ); + + +// 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 result to `cy`', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports `y` offset', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + 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 output 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 negative `x` strides', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 10.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports negative `y` strides', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var delta; + var viewY; + var tol; + var ca; + var cx; + var cy; + var k; + + 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 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewY[ k ] === expected[ k ] ) { + t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); + } + else { + delta = abs( viewY[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); From c16f986ab54009d2769e4cf00495e3c4c4d68175 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 4 Apr 2024 23:34:05 +0530 Subject: [PATCH 02/16] feat: add BLAS Level 1 caxpy --- .../@stdlib/blas/base/caxpy/test/test.caxpy.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) 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 index 7c85b04c7ef8..a4bb5a5820d2 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -552,10 +552,8 @@ tape( 'the function supports view offsets', function test( t ) { 2.0, 3.0, // 1 4.0, // 1 - 5.0, // 2 - 6.0, // 2 - 7.0, - 8.0 + 5.0, + 6.0 ]); cy0 = new Complex64Array([ 1.0, @@ -563,9 +561,7 @@ tape( 'the function supports view offsets', function test( t ) { 1.0, 1.0, 1.0, // 1 - 1.0, // 1 - 1.0, // 2 - 1.0 // 2 + 1.0 // 1 ]); ca = new Complex64( 2.0, 2.0 ); @@ -573,10 +569,10 @@ tape( 'the function supports view offsets', function test( t ) { cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element cy1 = new Complex64Array( cy0.buffer, cy0.BYTES_PER_ELEMENT*2 ); // begin at the 3rd element - caxpy( 2, ca, cx1, 1, cy1, 1 ); + 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, -1.0, 23.0 ] ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, -1.0, 15.0 ] ); t.deepEqual( viewY, expected, 'returns expected value' ); t.end(); From 71a7470556edd1172de13657645b9aee6f90882f Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 4 Apr 2024 23:55:10 +0530 Subject: [PATCH 03/16] chore: apply review changes --- .../@stdlib/blas/base/caxpy/benchmark/benchmark.js | 3 ++- .../@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js index 28804617d12e..64c837b5950b 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js @@ -59,6 +59,8 @@ function createBenchmark( len ) { cy = uniform( len*2, -100.0, 100.0, options ); cy = new Complex64Array( cy.buffer ); + viewY = reinterpret( cy, 0 ); + ca = new Complex64( 1.0, 0.0 ); return benchmark; @@ -75,7 +77,6 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { caxpy( cx.length, ca, cx, 1, cy, 1 ); - viewY = reinterpret( cy, 0 ); if ( isnan( viewY[ i%(len*2) ] ) ) { b.fail( 'should not return NaN' ); } 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 index 496890da69e3..96448b2daafc 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js @@ -59,6 +59,8 @@ function createBenchmark( len ) { cy = uniform( len*2, -100.0, 100.0, options ); cy = new Complex64Array( cy.buffer ); + viewY = reinterpret( cy, 0 ); + ca = new Complex64( 1.0, 0.0 ); return benchmark; @@ -75,7 +77,6 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { caxpy( cx.length, ca, cx, 1, 0, cy, 1, 0 ); - viewY = reinterpret( cy, 0 ); if ( isnan( viewY[ i%(len*2) ] ) ) { b.fail( 'should not return NaN' ); } From 2a8cb9391148beb67469d0cb5058c072b4037449 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 5 Apr 2024 13:45:09 +0530 Subject: [PATCH 04/16] chore: apply review changes --- .../@stdlib/blas/base/caxpy/README.md | 18 ++++----- .../base/caxpy/benchmark/benchmark.ndarray.js | 2 +- .../@stdlib/blas/base/caxpy/docs/repl.txt | 40 +++++++++---------- .../blas/base/caxpy/docs/types/index.d.ts | 40 +++++++++---------- .../blas/base/caxpy/docs/types/test.ts | 2 +- .../@stdlib/blas/base/caxpy/lib/caxpy.js | 10 ++--- .../@stdlib/blas/base/caxpy/lib/index.js | 2 +- .../@stdlib/blas/base/caxpy/lib/ndarray.js | 16 ++++---- .../@stdlib/blas/base/caxpy/package.json | 2 +- .../blas/base/caxpy/test/test.caxpy.js | 30 ++++++-------- .../blas/base/caxpy/test/test.ndarray.js | 40 ++++++++----------- 11 files changed, 95 insertions(+), 107 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/README.md b/lib/node_modules/@stdlib/blas/base/caxpy/README.md index 58ae7a08fd4a..9e9bcf3233d2 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/README.md +++ b/lib/node_modules/@stdlib/blas/base/caxpy/README.md @@ -32,7 +32,7 @@ var caxpy = require( '@stdlib/blas/base/caxpy' ); #### caxpy( N, ca, cx, strideX, cy, strideY ) -Scales values from `x` by `ca` and adds the result to `y`. +Scales values from `cx` by `ca` and adds the result to `cy`. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); @@ -60,12 +60,12 @@ The function has the following parameters: - **N**: number of indexed elements. - **ca**: scalar [`Complex64`][@stdlib/complex/float32] constant. -- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. -- **strideX**: index increment for `x`. -- **cy**: input [`Complex64Array`][@stdlib/array/complex64]. -- **strideY**: index increment for `y`. +- **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 `y`. For example, to scale every other value in `cx` by `ca` and add th result to every other value of `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 th result to every other value of `cy`, ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); @@ -103,7 +103,7 @@ var imagf = require( '@stdlib/complex/imagf' ); 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 ] ); -// Complex constant +// Define a scalar constant: var ca = new Complex64( 2.0, 2.0 ); // Create offset views... @@ -151,8 +151,8 @@ var im = imagf( z ); The function has the following additional parameters: -- **offsetX**: starting index for `x`. -- **offsetY**: starting index for `y`. +- **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 every other value in the first input strided array starting from the second element and add the result to second input array starting from the second element, 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 index 96448b2daafc..b523dc5efcce 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js @@ -111,7 +111,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, f ); + bench( pkg+':ndarray:len='+len, f ); } } diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt index ae8639f8a27a..3e0a20e8865f 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt @@ -1,8 +1,8 @@ {{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. + 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`. @@ -18,24 +18,24 @@ Number of indexed elements. ca: Complex64 - Complex constant. + Scalar constant. cx: Complex64Array - Input array. + First input array. strideX: integer - Index increment for `x`. + Index increment for `cx`. cy: Complex64Array - Output array. + Second input array. strideY: integer - Index increment for `y`. + Index increment for `cy`. Returns ------- cy: Complex64Array - Output array. + Second input array. Examples -------- @@ -76,9 +76,9 @@ {{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 + 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 @@ -91,30 +91,30 @@ Number of indexed elements. ca: Complex64 - Complex constant. + Scalar constant. cx: Complex64Array - Input array. + First input array. strideX: integer - Index increment for `x`. + Index increment for `cx`. offsetX: integer - Starting index for `x`. + Starting index for `cx`. cy: Complex64Array - Output array. + Second input array. strideY: integer - Index increment for `y`. + Index increment for `cy`. offsetY: integer - Starting index for `y`. + Starting index for `cy`. Returns ------- cy: Complex64Array - Output array. + Second input array. Examples -------- 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 index 6fda9431a3e8..e070f939ccae 100644 --- 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 @@ -31,12 +31,12 @@ 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 - complex constant - * @param cx - input array - * @param strideX - `x` stride length - * @param cy - output array - * @param strideY - `y` stride length - * @returns output array + * @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' ); @@ -65,14 +65,14 @@ 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 - complex constant - * @param cx - input array - * @param strideX - `x` stride length - * @param offsetX - starting index for `x` - * @param cy - output array - * @param strideY - `y` stride length - * @param offsetY - starting index for `y` - * @returns output array + * @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' ); @@ -102,12 +102,12 @@ 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 - complex constant -* @param cx - input array -* @param strideX - `x` stride length -* @param cy - output array -* @param strideY - `y` stride length -* @returns output array +* @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' ); 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 index c1ecb966a173..4c5f9be28217 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts @@ -266,7 +266,7 @@ import caxpy = require( './index' ); 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 a seventh argument which is not a number... +// The compiler throws an error if the `ndarray` method is provided a eighth argument which is not a number... { const cx = new Complex64Array( 10 ); const cy = new Complex64Array( 10 ); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js index dc4fb422665a..6b2580e31261 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js @@ -31,12 +31,12 @@ var caddf = require( '@stdlib/math/base/ops/caddf' ); * 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 - constant -* @param {Complex64Array} cx - input array -* @param {integer} strideX - `x` stride length +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - first input array +* @param {integer} strideX - `cx` stride length * @param {Complex64Array} cy - input array -* @param {integer} strideY - `y` stride length -* @returns {Complex64Array} output array +* @param {integer} strideY - `cy` stride length +* @returns {Complex64Array} second input array * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js index e432dba0a79d..2290fa658699 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* BLAS level 1 routine to scale 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. +* 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 * diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js index 520d73cb22d0..5a59f345582c 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js @@ -31,14 +31,14 @@ var caddf = require( '@stdlib/math/base/ops/caddf' ); * 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 - constant -* @param {Complex64Array} cx - input array -* @param {integer} strideX - `x` stride length -* @param {integer} offsetX - `x` offset -* @param {Complex64Array} cy - input array -* @param {integer} strideY - `y` stride length -* @param {integer} offsetY - `y` offset -* @returns {Complex64Array} output array +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - first input array +* @param {integer} strideX - `cx` stride length +* @param {integer} offsetX - `cx` offset +* @param {Complex64Array} cy - second input array +* @param {integer} strideY - `cy` stride length +* @param {integer} offsetY - `cy` offset +* @returns {Complex64Array} second input array * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/package.json b/lib/node_modules/@stdlib/blas/base/caxpy/package.json index c1b8570c67d1..4bad808433a8 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/package.json +++ b/lib/node_modules/@stdlib/blas/base/caxpy/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/base/caxpy", "version": "0.0.0", - "description": "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.", + "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", 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 index a4bb5a5820d2..f905b1a7e395 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -108,8 +108,7 @@ tape( 'the function scales elements from `cx` by `ca` and result to `cy`', funct for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -118,7 +117,7 @@ tape( 'the function scales elements from `cx` by `ca` and result to `cy`', funct t.end(); }); -tape( 'the function supports an `x` stride', function test( t ) { +tape( 'the function supports a `cx` stride', function test( t ) { var expected; var delta; var viewY; @@ -184,8 +183,7 @@ tape( 'the function supports an `x` stride', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 5.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -194,7 +192,7 @@ tape( 'the function supports an `x` stride', function test( t ) { t.end(); }); -tape( 'the function supports a `y` stride', function test( t ) { +tape( 'the function supports a `cy` stride', function test( t ) { var expected; var delta; var viewY; @@ -260,8 +258,7 @@ tape( 'the function supports a `y` stride', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -286,7 +283,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +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; @@ -309,7 +306,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'the function supports negative `x` strides', function test( t ) { +tape( 'the function supports negative `cx` strides', function test( t ) { var expected; var delta; var viewY; @@ -375,8 +372,7 @@ tape( 'the function supports negative `x` strides', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -385,7 +381,7 @@ tape( 'the function supports negative `x` strides', function test( t ) { t.end(); }); -tape( 'the function supports negative `y` strides', function test( t ) { +tape( 'the function supports negative `cy` strides', function test( t ) { var expected; var delta; var viewY; @@ -451,8 +447,7 @@ tape( 'the function supports negative `y` strides', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 5.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -527,8 +522,7 @@ tape( 'the function supports complex access patterns', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 2.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -563,6 +557,8 @@ tape( 'the function supports view offsets', function test( t ) { 1.0, // 1 1.0 // 1 ]); + + // Define a scalar constant: ca = new Complex64( 2.0, 2.0 ); // Create offset views... 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 index bd553971a044..90f0a9b5340f 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js @@ -108,8 +108,7 @@ tape( 'the function scales elements from `cx` by `ca` and result to `cy`', funct for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -118,7 +117,7 @@ tape( 'the function scales elements from `cx` by `ca` and result to `cy`', funct t.end(); }); -tape( 'the function supports an `x` stride', function test( t ) { +tape( 'the function supports a `cx` stride', function test( t ) { var expected; var delta; var viewY; @@ -184,8 +183,7 @@ tape( 'the function supports an `x` stride', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 5.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -194,7 +192,7 @@ tape( 'the function supports an `x` stride', function test( t ) { t.end(); }); -tape( 'the function supports an `x` offset', function test( t ) { +tape( 'the function supports a `cx` offset', function test( t ) { var expected; var delta; var viewY; @@ -260,8 +258,7 @@ tape( 'the function supports an `x` offset', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -270,7 +267,7 @@ tape( 'the function supports an `x` offset', function test( t ) { t.end(); }); -tape( 'the function supports a `y` stride', function test( t ) { +tape( 'the function supports a `cy` stride', function test( t ) { var expected; var delta; var viewY; @@ -336,8 +333,7 @@ tape( 'the function supports a `y` stride', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -346,7 +342,7 @@ tape( 'the function supports a `y` stride', function test( t ) { t.end(); }); -tape( 'the function supports `y` offset', function test( t ) { +tape( 'the function supports a `cy` offset', function test( t ) { var expected; var delta; var viewY; @@ -405,15 +401,14 @@ tape( 'the function supports `y` offset', function test( t ) { -0.1, -0.2, -1.17, // 3 - -0.59, // 3 + -0.59, // 3 0.8, -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -438,7 +433,7 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { +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; @@ -461,7 +456,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'the function supports negative `x` strides', function test( t ) { +tape( 'the function supports a negative `cx` stride', function test( t ) { var expected; var delta; var viewY; @@ -527,8 +522,7 @@ tape( 'the function supports negative `x` strides', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 10.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -537,7 +531,7 @@ tape( 'the function supports negative `x` strides', function test( t ) { t.end(); }); -tape( 'the function supports negative `y` strides', function test( t ) { +tape( 'the function supports a negative `cy` stride', function test( t ) { var expected; var delta; var viewY; @@ -603,8 +597,7 @@ tape( 'the function supports negative `y` strides', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 5.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); @@ -679,8 +672,7 @@ tape( 'the function supports complex access patterns', function test( t ) { for ( k = 0; k < expected.length; k++ ) { if ( viewY[ k ] === expected[ k ] ) { t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } - else { + } else { delta = abs( viewY[ k ] - expected[ k ] ); tol = 2.0 * EPS * abs( expected[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); From 53c09b48a3dc2a68fadb0a32c5d1227121451aa2 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 23 Apr 2024 14:39:16 +0530 Subject: [PATCH 05/16] feat: add C / Fortran implementation for caxpy --- .../@stdlib/blas/base/caxpy/binding.gyp | 265 ++++++++++++++++++ .../@stdlib/blas/base/caxpy/include.gypi | 70 +++++ .../@stdlib/blas/base/caxpy/manifest.json | 0 .../@stdlib/blas/base/caxpy/package.json | 4 + .../@stdlib/blas/base/caxpy/src/Makefile | 70 +++++ .../@stdlib/blas/base/caxpy/src/addon.c | 47 ++++ .../@stdlib/blas/base/caxpy/src/caxpy.c | 68 +++++ .../@stdlib/blas/base/caxpy/src/caxpy.f | 0 .../@stdlib/blas/base/caxpy/src/caxpy_cblas.c | 33 +++ .../@stdlib/blas/base/caxpy/src/caxpy_f.c | 0 10 files changed, 557 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp b/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp new file mode 100644 index 000000000000..02a2799da097 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp @@ -0,0 +1,265 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi b/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi new file mode 100644 index 000000000000..497aeca15320 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi @@ -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. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, CA, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CY, N, strideX, argv, 4 ); + c_caxpy( N, CA, (void *)CX, strideX, (void *)CY, strideY ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c new file mode 100644 index 000000000000..49d618b7c3c6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c @@ -0,0 +1,68 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/caxpy.h" +#include "stdlib/complex/float32.h" +#include "stdlib/math/base/ops/caddf.h" +#include "stdlib/math/base/ops/cmulf.h" +#include "stdlib/math/base/special/cabsf.h" + +/** +* 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 +*/ +void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, void *CY, const int strideY ) { + stdlib_complex64_t ca = CA; + stdlib_complex64_t z1; + stdlib_complex64_t z2; + int i; + + uint8_t *ip1 = (uint8_t *)CX; + uint8_t *ip2 = (uint8_t *)CY; + int64_t is1 = 8 * strideX; + int64_t is2 = 8 * strideY; + + if ( N <= 0 ) { + return; + } + if ( stdlib_base_cabsf( ca ) == 0.0 ) { + return; + } + if ( strideX == 1 && strideY == 1 ) { + // Code for stride equal to `1`... + for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) { + z1 = *( (stdlib_complex64_t *)ip1 ); + z2 = *( (stdlib_complex64_t *)ip2 ); + *( (stdlib_complex64_t *)ip2 ) = stdlib_base_caddf( z2, stdlib_base_cmulf( ca, z1 ) ); + } + return; + } + // Code for stride not equal to `1`... + for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) { + z1 = *( (stdlib_complex64_t *)ip1 ); + z2 = *( (stdlib_complex64_t *)ip2 ); + *( (stdlib_complex64_t *)ip2 ) = stdlib_base_caddf( z2, stdlib_base_cmulf( ca, z1 ) ); + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c new file mode 100644 index 000000000000..42df0cf4ffa7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c @@ -0,0 +1,33 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/caxpy.h" +#include "stdlib/blas/base/caxpy_cblas.h" +#include "stdlib/complex/float32.h" + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param N number of indexed elements +* @param CA scalar constant +* @param CX input array +* @param strideX CX stride length +*/ +void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, void *CY, const int strideY ) { + cblas_caxpy( N, CA, CX, strideX ); +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c new file mode 100644 index 000000000000..e69de29bb2d1 From d17f53a2c35712be2eb64733f2f4e7cc0fa01d8d Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 23 Apr 2024 15:29:43 +0530 Subject: [PATCH 06/16] chore: apply implementation changes --- .../@stdlib/blas/base/caxpy/src/caxpy.c | 2 +- .../@stdlib/blas/base/caxpy/src/caxpy.f | 86 +++++++++++++++++++ .../@stdlib/blas/base/caxpy/src/caxpy_cblas.c | 4 +- .../@stdlib/blas/base/caxpy/src/caxpy_f.c | 35 ++++++++ 4 files changed, 124 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c index 49d618b7c3c6..3075fb958f3c 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c @@ -32,7 +32,7 @@ * @param CY second input array * @param strideY CY stride length */ -void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, void *CY, const int strideY ) { +void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, const void *CY, const int strideY ) { stdlib_complex64_t ca = CA; stdlib_complex64_t z1; stdlib_complex64_t z2; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f index e69de29bb2d1..4fa597513dd3 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f @@ -0,0 +1,86 @@ +!> +! @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. +!< + +!> 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. +! +! ## Notes +! +! * Modified version of reference BLAS level1 routine (version 3.9.0). Updated to "free form" Fortran 95. +! +! ## Authors +! +! * Univ. of Tennessee +! * Univ. of California Berkeley +! * Univ. of Colorado Denver +! * NAG Ltd. +! +! ## History +! +! * Jack Dongarra, linpack, 3/11/78. +! +! - modified 12/3/93, array(1) declarations changed to array(*) +! +! ## License +! +! From : +! +! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors. +! > +! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following: +! > +! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original. +! > +! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. +! +! @param {integer} N - number of indexed elements +! @param {complex} ca - scalar constant +! @param {Array} cx - first input array +! @param {integer} strideX - `cx` stride length +! @param {Array} cy - second input array +! @param {integer} strideY - `cy` stride length +!< +subroutine caxpy( N, ca, cx, strideX, cy, strideY ) + implicit none + ! .. + ! Scalar arguments: + complex :: ca + integer :: strideX, strideY N + ! .. + ! Array arguments: + complex :: cx(*), cy(*) + ! .. + ! Local scalars: + integer :: ix, iy, i + ! .. + if ( N <= 0 .OR. strideX <= 0 ) then + return + end if + ! .. + if ( strideX == 1 ) then + do i = 1, N + cx(i) = ca * cx(i) + end do + else + ix = 1 + do i = 1, N + cx(ix) = ca * cx(ix) + ix = ix + strideX + end do + end if + return +end subroutine caxpy \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c index 42df0cf4ffa7..90027bd92942 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c @@ -21,13 +21,13 @@ #include "stdlib/complex/float32.h" /** -* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* 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 input array * @param strideX CX stride length */ -void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, void *CY, const int strideY ) { +void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, const void *CY, const int strideY ) { cblas_caxpy( N, CA, CX, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c index e69de29bb2d1..7c4f3d139cc1 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c @@ -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. +*/ + +#include "stdlib/blas/base/caxpy.h" +#include "stdlib/blas/base/caxpy_fortran.h" +#include "stdlib/complex/float32.h" + +/** +* 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 +*/ +void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, const void *CY, const int strideY ) { + caxpy( &N, &CA, CX, &strideX, CY, &strideY ); +} From 42daad0bd7d41db1d5b3d55c29acd5ae32fa71eb Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 27 Jun 2024 11:33:25 +0530 Subject: [PATCH 07/16] refactor: update implementation, and descriptions --- .../@stdlib/blas/base/caxpy/README.md | 18 +- .../blas/base/caxpy/benchmark/benchmark.js | 15 +- .../base/caxpy/benchmark/benchmark.ndarray.js | 15 +- .../@stdlib/blas/base/caxpy/binding.gyp | 265 ------------------ .../@stdlib/blas/base/caxpy/docs/repl.txt | 10 +- .../blas/base/caxpy/docs/types/index.d.ts | 8 +- .../blas/base/caxpy/docs/types/test.ts | 2 +- .../@stdlib/blas/base/caxpy/examples/index.js | 2 +- .../@stdlib/blas/base/caxpy/include.gypi | 70 ----- .../@stdlib/blas/base/caxpy/lib/caxpy.js | 6 +- .../@stdlib/blas/base/caxpy/lib/index.js | 4 +- .../@stdlib/blas/base/caxpy/lib/ndarray.js | 6 +- .../@stdlib/blas/base/caxpy/manifest.json | 0 .../@stdlib/blas/base/caxpy/package.json | 4 - .../@stdlib/blas/base/caxpy/src/Makefile | 70 ----- .../@stdlib/blas/base/caxpy/src/addon.c | 47 ---- .../@stdlib/blas/base/caxpy/src/caxpy.c | 68 ----- .../@stdlib/blas/base/caxpy/src/caxpy.f | 86 ------ .../@stdlib/blas/base/caxpy/src/caxpy_cblas.c | 33 --- .../@stdlib/blas/base/caxpy/src/caxpy_f.c | 35 --- .../blas/base/caxpy/test/test.caxpy.js | 91 +++--- .../blas/base/caxpy/test/test.ndarray.js | 111 +++----- 22 files changed, 114 insertions(+), 852 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/include.gypi delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/manifest.json delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/Makefile delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c delete mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/README.md b/lib/node_modules/@stdlib/blas/base/caxpy/README.md index 9e9bcf3233d2..dfa9eadb8d7c 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/README.md +++ b/lib/node_modules/@stdlib/blas/base/caxpy/README.md @@ -36,7 +36,7 @@ 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'); +var Complex64 = require('@stdlib/complex/float32/ctor'); var realf = require( '@stdlib/complex/realf' ); var imagf = require( '@stdlib/complex/imagf' ); @@ -59,7 +59,7 @@ var im = imagf( z ); The function has the following parameters: - **N**: number of indexed elements. -- **ca**: scalar [`Complex64`][@stdlib/complex/float32] constant. +- **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]. @@ -69,7 +69,7 @@ The `N` and stride parameters determine how values from `cx` are scaled by `ca` ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex64 = require( '@stdlib/complex/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); var realf = require( '@stdlib/complex/realf' ); var imagf = require( '@stdlib/complex/imagf' ); @@ -95,7 +95,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex64 = require( '@stdlib/complex/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); var realf = require( '@stdlib/complex/realf' ); var imagf = require( '@stdlib/complex/imagf' ); @@ -129,7 +129,7 @@ Scales values from `cx` by `ca` and add the result to `cy` using alternative ind ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex64 = require( '@stdlib/complex/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); var realf = require( '@stdlib/complex/realf' ); var imagf = require( '@stdlib/complex/imagf' ); @@ -158,7 +158,7 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex64 = require( '@stdlib/complex/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); var realf = require( '@stdlib/complex/realf' ); var imagf = require( '@stdlib/complex/imagf' ); @@ -202,7 +202,7 @@ var im = imagf( z ); ```javascript var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); -var Complex64 = require( '@stdlib/complex/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); var caxpy = require( '@stdlib/blas/base/caxpy' ); function rand() { @@ -240,13 +240,13 @@ console.log( cy.get( cy.length-1 ).toString() ); [blas]: http://www.netlib.org/blas -[caxpy]: http://www.netlib.org/lapack/explore-html/da/df6/group__complex__blas__level1.html +[caxpy]: https://www.netlib.org/lapack/explore-html/d5/d4b/group__axpy_ga0b7bac1f4d42514074a48f14f5f9caa0.html#ga0b7bac1f4d42514074a48f14f5f9caa0 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray [@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 -[@stdlib/complex/float32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32 +[@stdlib/complex/float32/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32/ctor diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js index 64c837b5950b..b59bd3a45aa8 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.js @@ -22,10 +22,10 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +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' ); +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' ); @@ -53,11 +53,8 @@ function createBenchmark( len ) { var cx; var cy; - cx = uniform( len*2, -100.0, 100.0, options ); - cx = new Complex64Array( cx.buffer ); - - cy = uniform( len*2, -100.0, 100.0, options ); - cy = new Complex64Array( cy.buffer ); + 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 ); @@ -77,12 +74,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { caxpy( cx.length, ca, cx, 1, cy, 1 ); - if ( isnan( viewY[ i%(len*2) ] ) ) { + if ( isnanf( viewY[ i%(len*2) ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( viewY[ i%(len*2) ] ) ) { + if ( isnanf( viewY[ i%(len*2) ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); 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 index b523dc5efcce..127c8edbcafd 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.js @@ -22,10 +22,10 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +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' ); +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' ); @@ -53,11 +53,8 @@ function createBenchmark( len ) { var cx; var cy; - cx = uniform( len*2, -100.0, 100.0, options ); - cx = new Complex64Array( cx.buffer ); - - cy = uniform( len*2, -100.0, 100.0, options ); - cy = new Complex64Array( cy.buffer ); + 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 ); @@ -77,12 +74,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { caxpy( cx.length, ca, cx, 1, 0, cy, 1, 0 ); - if ( isnan( viewY[ i%(len*2) ] ) ) { + if ( isnanf( viewY[ i%(len*2) ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( viewY[ i%(len*2) ] ) ) { + if ( isnanf( viewY[ i%(len*2) ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp b/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp deleted file mode 100644 index 02a2799da097..000000000000 --- a/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp +++ /dev/null @@ -1,265 +0,0 @@ -# @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. - -# A `.gyp` file for building a Node.js native add-on. -# -# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md -# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md -{ - # List of files to include in this file: - 'includes': [ - './include.gypi', - ], - - # Define variables to be used throughout the configuration for all targets: - 'variables': { - # Target name should match the add-on export name: - 'addon_target_name%': 'addon', - - # Fortran compiler (to override -Dfortran_compiler=): - 'fortran_compiler%': 'gfortran', - - # Fortran compiler flags: - 'fflags': [ - # Specify the Fortran standard to which a program is expected to conform: - '-std=f95', - - # Indicate that the layout is free-form source code: - '-ffree-form', - - # Aggressive optimization: - '-O3', - - # Enable commonly used warning options: - '-Wall', - - # Warn if source code contains problematic language features: - '-Wextra', - - # Warn if a procedure is called without an explicit interface: - '-Wimplicit-interface', - - # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): - '-fno-underscoring', - - # Warn if source code contains Fortran 95 extensions and C-language constructs: - '-pedantic', - - # Compile but do not link (output is an object file): - '-c', - ], - - # Set variables based on the host OS: - 'conditions': [ - [ - 'OS=="win"', - { - # Define the object file suffix: - 'obj': 'obj', - }, - { - # Define the object file suffix: - 'obj': 'o', - } - ], # end condition (OS=="win") - ], # end conditions - }, # end variables - - # Define compile targets: - 'targets': [ - - # Target to generate an add-on: - { - # The target name should match the add-on export name: - 'target_name': '<(addon_target_name)', - - # Define dependencies: - 'dependencies': [], - - # Define directories which contain relevant include headers: - 'include_dirs': [ - # Local include directory: - '<@(include_dirs)', - ], - - # List of source files: - 'sources': [ - '<@(src_files)', - ], - - # Settings which should be applied when a target's object files are used as linker input: - 'link_settings': { - # Define libraries: - 'libraries': [ - '<@(libraries)', - ], - - # Define library directories: - 'library_dirs': [ - '<@(library_dirs)', - ], - }, - - # C/C++ compiler flags: - 'cflags': [ - # Enable commonly used warning options: - '-Wall', - - # Aggressive optimization: - '-O3', - ], - - # C specific compiler flags: - 'cflags_c': [ - # Specify the C standard to which a program is expected to conform: - '-std=c99', - ], - - # C++ specific compiler flags: - 'cflags_cpp': [ - # Specify the C++ standard to which a program is expected to conform: - '-std=c++11', - ], - - # Linker flags: - 'ldflags': [], - - # Apply conditions based on the host OS: - 'conditions': [ - [ - 'OS=="mac"', - { - # Linker flags: - 'ldflags': [ - '-undefined dynamic_lookup', - '-Wl,-no-pie', - '-Wl,-search_paths_first', - ], - }, - ], # end condition (OS=="mac") - [ - 'OS!="win"', - { - # C/C++ flags: - 'cflags': [ - # Generate platform-independent code: - '-fPIC', - ], - }, - ], # end condition (OS!="win") - ], # end conditions - - # Define custom build actions for particular inputs: - 'rules': [ - { - # Define a rule for processing Fortran files: - 'extension': 'f', - - # Define the pathnames to be used as inputs when performing processing: - 'inputs': [ - # Full path of the current input: - '<(RULE_INPUT_PATH)' - ], - - # Define the outputs produced during processing: - 'outputs': [ - # Store an output object file in a directory for placing intermediate results (only accessible within a single target): - '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' - ], - - # Define the rule for compiling Fortran based on the host OS: - 'conditions': [ - [ - 'OS=="win"', - - # Rule to compile Fortran on Windows: - { - 'rule_name': 'compile_fortran_windows', - 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', - - 'process_outputs_as_sources': 0, - - # Define the command-line invocation: - 'action': [ - '<(fortran_compiler)', - '<@(fflags)', - '<@(_inputs)', - '-o', - '<@(_outputs)', - ], - }, - - # Rule to compile Fortran on non-Windows: - { - 'rule_name': 'compile_fortran_linux', - 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', - - 'process_outputs_as_sources': 1, - - # Define the command-line invocation: - 'action': [ - '<(fortran_compiler)', - '<@(fflags)', - '-fPIC', # generate platform-independent code - '<@(_inputs)', - '-o', - '<@(_outputs)', - ], - } - ], # end condition (OS=="win") - ], # end conditions - }, # end rule (extension=="f") - ], # end rules - }, # end target <(addon_target_name) - - # Target to copy a generated add-on to a standard location: - { - 'target_name': 'copy_addon', - - # Declare that the output of this target is not linked: - 'type': 'none', - - # Define dependencies: - 'dependencies': [ - # Require that the add-on be generated before building this target: - '<(addon_target_name)', - ], - - # Define a list of actions: - 'actions': [ - { - 'action_name': 'copy_addon', - 'message': 'Copying addon...', - - # Explicitly list the inputs in the command-line invocation below: - 'inputs': [], - - # Declare the expected outputs: - 'outputs': [ - '<(addon_output_dir)/<(addon_target_name).node', - ], - - # Define the command-line invocation: - 'action': [ - 'cp', - '<(PRODUCT_DIR)/<(addon_target_name).node', - '<(addon_output_dir)/<(addon_target_name).node', - ], - }, - ], # end actions - }, # end target copy_addon - ], # end targets -} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt index 3e0a20e8865f..f2f7179739e6 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt @@ -42,7 +42,7 @@ // 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}}( 2.0, 2.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 ) @@ -53,7 +53,7 @@ // 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 ] ); - > ca = new {{alias:@stdlib/complex/float32}}( 2.0, 2.0 ); + > ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); > {{alias}}( 2, ca, cx, -2, cy, 1 ); > z = cy.get( 0 ); > re = {{alias:@stdlib/complex/realf}}( z ) @@ -64,7 +64,7 @@ // 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 ca = new {{alias:@stdlib/complex/float32}}( 2.0, 2.0 ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.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 ); @@ -121,7 +121,7 @@ // 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}}( 2.0, 2.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 ) @@ -132,7 +132,7 @@ // 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 ] ); - > ca = new {{alias:@stdlib/complex/float32}}( 2.0, 2.0 ); + > ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); > {{alias}}.ndarray( 2, ca, cx, 1, 1, cy, 1, 1 ); > z = cy.get( 2 ); > re = {{alias:@stdlib/complex/realf}}( z ) 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 index e070f939ccae..8aea763f588b 100644 --- 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 @@ -40,7 +40,7 @@ interface Routine { * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); - * var Complex64 = require( '@stdlib/complex/float32' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); * var realf = require( '@stdlib/complex/realf' ); * var imagf = require( '@stdlib/complex/imagf' ); * @@ -76,7 +76,7 @@ interface Routine { * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); - * var Complex64 = require( '@stdlib/complex/float32' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); * var realf = require( '@stdlib/complex/realf' ); * var imagf = require( '@stdlib/complex/imagf' ); * @@ -111,7 +111,7 @@ interface Routine { * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); -* var Complex64 = require( '@stdlib/complex/float32' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); * var realf = require( '@stdlib/complex/realf' ); * var imagf = require( '@stdlib/complex/imagf' ); * @@ -132,7 +132,7 @@ interface Routine { * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); -* var Complex64 = require( '@stdlib/complex/float32' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); * var realf = require( '@stdlib/complex/realf' ); * var imagf = require( '@stdlib/complex/imagf' ); * 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 index 4c5f9be28217..be61cc15a785 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts @@ -17,7 +17,7 @@ */ import Complex64Array = require( '@stdlib/array/complex64' ); -import Complex64 = require( '@stdlib/complex/float32' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); import caxpy = require( './index' ); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js index 815e057c3e18..348941fbcde4 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js @@ -20,7 +20,7 @@ var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); -var Complex64 = require( '@stdlib/complex/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); var caxpy = require( '@stdlib/blas/base/caxpy' ); function rand() { diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi b/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi deleted file mode 100644 index 497aeca15320..000000000000 --- a/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi +++ /dev/null @@ -1,70 +0,0 @@ -# @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. - -# A GYP include file for building a Node.js native add-on. -# -# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. -# -# Main documentation: -# -# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md -# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md -# -# Variable nesting hacks: -# -# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi -# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 -{ - # Define variables to be used throughout the configuration for all targets: - 'variables': { - 'variables': { - # Host BLAS library (to override -Dblas=): - 'blas%': '', - - # Path to BLAS library (to override -Dblas_dir=): - 'blas_dir%': '', - }, # end variables - - # Source directory: - 'src_dir': './src', - - # Include directories: - 'include_dirs': [ - '<@(blas_dir)', - ' - -/** -* Receives JavaScript callback invocation data. -* -* @private -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); - STDLIB_NAPI_ARGV_COMPLEX64( env, CA, argv, 1 ); - STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CY, N, strideX, argv, 4 ); - c_caxpy( N, CA, (void *)CX, strideX, (void *)CY, strideY ); - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c deleted file mode 100644 index 3075fb958f3c..000000000000 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @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. -*/ - -#include "stdlib/blas/base/caxpy.h" -#include "stdlib/complex/float32.h" -#include "stdlib/math/base/ops/caddf.h" -#include "stdlib/math/base/ops/cmulf.h" -#include "stdlib/math/base/special/cabsf.h" - -/** -* 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 -*/ -void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, const void *CY, const int strideY ) { - stdlib_complex64_t ca = CA; - stdlib_complex64_t z1; - stdlib_complex64_t z2; - int i; - - uint8_t *ip1 = (uint8_t *)CX; - uint8_t *ip2 = (uint8_t *)CY; - int64_t is1 = 8 * strideX; - int64_t is2 = 8 * strideY; - - if ( N <= 0 ) { - return; - } - if ( stdlib_base_cabsf( ca ) == 0.0 ) { - return; - } - if ( strideX == 1 && strideY == 1 ) { - // Code for stride equal to `1`... - for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) { - z1 = *( (stdlib_complex64_t *)ip1 ); - z2 = *( (stdlib_complex64_t *)ip2 ); - *( (stdlib_complex64_t *)ip2 ) = stdlib_base_caddf( z2, stdlib_base_cmulf( ca, z1 ) ); - } - return; - } - // Code for stride not equal to `1`... - for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) { - z1 = *( (stdlib_complex64_t *)ip1 ); - z2 = *( (stdlib_complex64_t *)ip2 ); - *( (stdlib_complex64_t *)ip2 ) = stdlib_base_caddf( z2, stdlib_base_cmulf( ca, z1 ) ); - } - return; -} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f deleted file mode 100644 index 4fa597513dd3..000000000000 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.f +++ /dev/null @@ -1,86 +0,0 @@ -!> -! @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. -!< - -!> 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. -! -! ## Notes -! -! * Modified version of reference BLAS level1 routine (version 3.9.0). Updated to "free form" Fortran 95. -! -! ## Authors -! -! * Univ. of Tennessee -! * Univ. of California Berkeley -! * Univ. of Colorado Denver -! * NAG Ltd. -! -! ## History -! -! * Jack Dongarra, linpack, 3/11/78. -! -! - modified 12/3/93, array(1) declarations changed to array(*) -! -! ## License -! -! From : -! -! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors. -! > -! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following: -! > -! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original. -! > -! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. -! -! @param {integer} N - number of indexed elements -! @param {complex} ca - scalar constant -! @param {Array} cx - first input array -! @param {integer} strideX - `cx` stride length -! @param {Array} cy - second input array -! @param {integer} strideY - `cy` stride length -!< -subroutine caxpy( N, ca, cx, strideX, cy, strideY ) - implicit none - ! .. - ! Scalar arguments: - complex :: ca - integer :: strideX, strideY N - ! .. - ! Array arguments: - complex :: cx(*), cy(*) - ! .. - ! Local scalars: - integer :: ix, iy, i - ! .. - if ( N <= 0 .OR. strideX <= 0 ) then - return - end if - ! .. - if ( strideX == 1 ) then - do i = 1, N - cx(i) = ca * cx(i) - end do - else - ix = 1 - do i = 1, N - cx(ix) = ca * cx(ix) - ix = ix + strideX - end do - end if - return -end subroutine caxpy \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c deleted file mode 100644 index 90027bd92942..000000000000 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @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. -*/ - -#include "stdlib/blas/base/caxpy.h" -#include "stdlib/blas/base/caxpy_cblas.h" -#include "stdlib/complex/float32.h" - -/** -* 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 input array -* @param strideX CX stride length -*/ -void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, const void *CY, const int strideY ) { - cblas_caxpy( N, CA, CX, strideX ); -} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c deleted file mode 100644 index 7c4f3d139cc1..000000000000 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_f.c +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @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. -*/ - -#include "stdlib/blas/base/caxpy.h" -#include "stdlib/blas/base/caxpy_fortran.h" -#include "stdlib/complex/float32.h" - -/** -* 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 -*/ -void c_caxpy( const int N, const stdlib_complex64_t CA, const void *CX, const int strideX, const void *CY, const int strideY ) { - caxpy( &N, &CA, CX, &strideX, CY, &strideY ); -} 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 index f905b1a7e395..f0c3ef470619 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -23,12 +23,41 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex64 = require( '@stdlib/complex/float32' ); +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 ) { @@ -44,9 +73,7 @@ tape( 'the function has an arity of 6', function test( t ) { tape( 'the function scales elements from `cx` by `ca` and result to `cy`', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -106,22 +133,14 @@ tape( 'the function scales elements from `cx` by `ca` and result to `cy`', funct -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a `cx` stride', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -181,22 +200,14 @@ tape( 'the function supports a `cx` stride', function test( t ) { -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a `cy` stride', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -256,13 +267,7 @@ tape( 'the function supports a `cy` stride', function test( t ) { -1.16 // 4 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); @@ -308,9 +313,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports negative `cx` strides', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -370,22 +373,14 @@ tape( 'the function supports negative `cx` strides', function test( t ) { -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports negative `cy` strides', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -445,22 +440,14 @@ tape( 'the function supports negative `cy` strides', function test( t ) { -1.51 // 1 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports complex access patterns', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -520,13 +507,7 @@ tape( 'the function supports complex access patterns', function test( t ) { -1.16 // 1 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 2.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); 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 index 90f0a9b5340f..334c0d39330f 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js @@ -23,12 +23,41 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex64 = require( '@stdlib/complex/float32' ); +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 ) { @@ -44,9 +73,7 @@ tape( 'the function has an arity of 8', function test( t ) { tape( 'the function scales elements from `cx` by `ca` and result to `cy`', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -106,22 +133,14 @@ tape( 'the function scales elements from `cx` by `ca` and result to `cy`', funct -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a `cx` stride', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -181,22 +200,14 @@ tape( 'the function supports a `cx` stride', function test( t ) { -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a `cx` offset', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -256,22 +267,14 @@ tape( 'the function supports a `cx` offset', function test( t ) { -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a `cy` stride', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -331,22 +334,14 @@ tape( 'the function supports a `cy` stride', function test( t ) { -1.16 // 4 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a `cy` offset', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -406,13 +401,7 @@ tape( 'the function supports a `cy` offset', function test( t ) { -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); @@ -458,9 +447,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports a negative `cx` stride', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -520,22 +507,14 @@ tape( 'the function supports a negative `cx` stride', function test( t ) { -0.7 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports a negative `cy` stride', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -595,22 +574,14 @@ tape( 'the function supports a negative `cy` stride', function test( t ) { -1.51 // 1 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); tape( 'the function supports complex access patterns', function test( t ) { var expected; - var delta; var viewY; - var tol; var ca; var cx; var cy; @@ -670,13 +641,7 @@ tape( 'the function supports complex access patterns', function test( t ) { -1.16 // 1 ] ); for ( k = 0; k < expected.length; k++ ) { - if ( viewY[ k ] === expected[ k ] ) { - t.strictEqual( viewY[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewY[ k ] - expected[ k ] ); - tol = 2.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewY[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + isApprox( t, viewY[ k ], expected[ k ], 2.0 ); } t.end(); }); From 85e081e38d8ed3bf16aed2f2023aff3dbc79dd42 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 27 Jun 2024 17:41:06 +0530 Subject: [PATCH 08/16] docs: update description --- lib/node_modules/@stdlib/blas/base/caxpy/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 8aea763f588b..f05c1c4783b0 100644 --- 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 @@ -95,7 +95,7 @@ interface Routine { * var im = imagf( z ); * // returns 7.0 */ - ndarray( N: number, x: Complex64Array, strideX: number, offsetX: number, y: Complex64Array, strideY: number, offsetY: number ): Complex64Array; + ndarray( N: number, ca: Complex64, cx: Complex64Array, strideX: number, offsetX: number, cy: Complex64Array, strideY: number, offsetY: number ): Complex64Array; } /** From 8a6e8d97f7eb64d3c6501d04e35c2ff5be75fc73 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Sat, 6 Jul 2024 11:46:20 +0530 Subject: [PATCH 09/16] refactor: update implementation for caxpy --- .../@stdlib/blas/base/caxpy/lib/caxpy.js | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js index 5e2a25acf1ff..dd2058244a12 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js @@ -20,9 +20,9 @@ // MODULES // +var stride2offset = require('@stdlib/strided/base/stride2offset'); var scabs1 = require('@stdlib/blas/base/scabs1'); -var cmulf = require( '@stdlib/math/base/ops/cmulf' ); -var caddf = require( '@stdlib/math/base/ops/caddf' ); +var ndarray = require('./ndarray.js'); // MAIN // @@ -62,38 +62,15 @@ var caddf = require( '@stdlib/math/base/ops/caddf' ); function caxpy( N, ca, cx, strideX, cy, strideY ) { var ix; var iy; - var i; - if ( N <= 0 ) { return cy; } if ( scabs1( ca ) === 0.0 ) { return cy; } - if ( strideX === 1 && strideY === 1 ) { - // Code for stride equal to `1`... - for ( i = 0; i < N; i++ ) { - cy.set( caddf( cmulf( ca, cx.get( i ) ), cy.get( i ) ), i ); - } - return cy; - } - // Code for stride not equal to `1`... - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - cy.set( caddf( cmulf( ca, cx.get( ix ) ), cy.get( iy ) ), iy ); - ix += strideX; - iy += strideY; - } - return cy; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, ca, cx, strideX, ix, cy, strideY, iy ); } From 473bc3068b6cae0d3dac231ed29bfe9e53acd251 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 11 Jul 2024 20:15:08 +0530 Subject: [PATCH 10/16] refactor: remove duplicate logic --- .../@stdlib/blas/base/caxpy/lib/caxpy.js | 15 +++------------ .../@stdlib/blas/base/caxpy/lib/index.js | 8 ++++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js index dd2058244a12..b56bf5657428 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.js @@ -21,7 +21,6 @@ // MODULES // var stride2offset = require('@stdlib/strided/base/stride2offset'); -var scabs1 = require('@stdlib/blas/base/scabs1'); var ndarray = require('./ndarray.js'); @@ -34,7 +33,7 @@ var ndarray = require('./ndarray.js'); * @param {Complex64} ca - scalar constant * @param {Complex64Array} cx - first input array * @param {integer} strideX - `cx` stride length -* @param {Complex64Array} cy - input array +* @param {Complex64Array} cy - second input array * @param {integer} strideY - `cy` stride length * @returns {Complex64Array} second input array * @@ -60,16 +59,8 @@ var ndarray = require('./ndarray.js'); * // returns 7.0 */ function caxpy( N, ca, cx, strideX, cy, strideY ) { - var ix; - var iy; - if ( N <= 0 ) { - return cy; - } - if ( scabs1( ca ) === 0.0 ) { - return cy; - } - ix = stride2offset( N, strideX ); - iy = stride2offset( N, strideY ); + var ix = stride2offset( N, strideX ); + var iy = stride2offset( N, strideY ); return ndarray( N, ca, cx, strideX, ix, cy, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js index 85651b2368b1..7e9d281df265 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/index.js @@ -40,10 +40,10 @@ * // returns * * var re = realf( z ); -* // returns -2.0 +* // returns -1.0 * * var im = imagf( z ); -* // returns 6.0 +* // returns 7.0 * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); @@ -62,10 +62,10 @@ * // returns * * var re = realf( z ); -* // returns -2.0 +* // returns -1.0 * * var im = imagf( z ); -* // returns 6.0 +* // returns 7.0 */ // MODULES // From 4a4cc088b8a23659a93a577cccc9c90123577f62 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 11 Jul 2024 20:16:53 +0530 Subject: [PATCH 11/16] refactor: reduce code duplication and update description --- .../@stdlib/blas/base/caxpy/lib/ndarray.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js index afe534052552..038310c0b326 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js @@ -74,16 +74,6 @@ function caxpy( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) { } ix = offsetX; iy = offsetY; - if ( strideX === 1 && strideY === 1 ) { - // Code for stride equal to `1`... - for ( i = 0; i < N; i++ ) { - cy.set( caddf( cmulf( ca, cx.get( ix ) ), cy.get( iy ) ), iy ); - ix += strideX; - iy += strideY; - } - return cy; - } - // Code for stride not equal to `1`... for ( i = 0; i < N; i++ ) { cy.set( caddf( cmulf( ca, cx.get( ix ) ), cy.get( iy ) ), iy ); ix += strideX; From 5658370e11938f5bc239c5b030da5a479eaa4edc Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 11 Jul 2024 20:22:59 +0530 Subject: [PATCH 12/16] docs: update examples and descriptions --- .../@stdlib/blas/base/caxpy/README.md | 21 +++++++++++-------- .../@stdlib/blas/base/caxpy/examples/index.js | 15 +++++++------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/README.md b/lib/node_modules/@stdlib/blas/base/caxpy/README.md index dfa9eadb8d7c..4d2888d103e7 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/README.md +++ b/lib/node_modules/@stdlib/blas/base/caxpy/README.md @@ -20,7 +20,7 @@ limitations under the License. # caxpy -> 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. +> 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.
@@ -65,7 +65,7 @@ The function has the following parameters: - **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 th result to every other value of `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' ); @@ -125,7 +125,7 @@ var im = imagf( z ); #### caxpy.ndarray( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) -Scales values from `cx` by `ca` and add the result to `cy` using alternative indexing semantics. +Scales values from `cx` by `ca` and adds the result to `cy` using alternative indexing semantics. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); @@ -154,7 +154,7 @@ 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 every other value in the first input strided array starting from the second element and add the result to second input array starting from the second element, +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' ); @@ -203,6 +203,9 @@ var im = imagf( z ); 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() { @@ -210,16 +213,16 @@ function rand() { } var cx = filledarrayBy( 10, 'complex64', rand ); -console.log( cx.get( 0 ).toString() ); - var cy = filledarrayBy( 10, 'complex64', rand ); -console.log( cy.get( 0 ).toString() ); +var cyc = ccopy( cy.length, cy, 1, zeros( cy.length, 'complex64' ), 1 ); var ca = new Complex64( 2.0, 2.0 ); -// Scales values from `cx` by `ca` and add the result to `cy`: +// Scale values from `cx` by `ca` and add the result to `cy`: caxpy( cx.length, ca, cx, 1, cy, 1 ); -console.log( cy.get( cy.length-1 ).toString() ); + +// Print the results: +logEach( '(%s)*(%s) + (%s) = %s', ca, cx, cyc, cy ); ```
diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js index 348941fbcde4..d88440e7f0e7 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/examples/index.js @@ -21,20 +21,23 @@ var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var caxpy = require( '@stdlib/blas/base/caxpy' ); +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 ); -console.log( cx.get( 0 ).toString() ); - var cy = filledarrayBy( 10, 'complex64', rand ); -console.log( cy.get( 0 ).toString() ); +var cyc = ccopy( cy.length, cy, 1, zeros( cy.length, 'complex64' ), 1 ); var ca = new Complex64( 2.0, 2.0 ); -// Scales values from `cx` by `ca` and add the result to `cy`: +// Scale values from `cx` by `ca` and add the result to `cy`: caxpy( cx.length, ca, cx, 1, cy, 1 ); -console.log( cy.get( cy.length-1 ).toString() ); + +// Print the results: +logEach( '(%s)*(%s) + (%s) = %s', ca, cx, cyc, cy ); From 37b19ea851e13f659850042b548b19ba5daf251a Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 11 Jul 2024 20:25:07 +0530 Subject: [PATCH 13/16] docs: fix descriptions --- lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index be61cc15a785..e7ffcb48981d 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/types/test.ts @@ -48,7 +48,7 @@ import caxpy = require( './index' ); 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 Complex64... +// 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 ); @@ -169,7 +169,7 @@ import caxpy = require( './index' ); 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 Complex64... +// 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 ); @@ -266,7 +266,7 @@ import caxpy = require( './index' ); 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 a eighth argument which is not a number... +// 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 ); From 511082d2116cc9b5702e2f5ee9191a716f5bb2c6 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 11 Jul 2024 20:28:43 +0530 Subject: [PATCH 14/16] docs: update examples --- lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt | 3 --- lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt index f2f7179739e6..8a823c8cfc14 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/caxpy/docs/repl.txt @@ -53,7 +53,6 @@ // 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 ] ); - > ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); > {{alias}}( 2, ca, cx, -2, cy, 1 ); > z = cy.get( 0 ); > re = {{alias:@stdlib/complex/realf}}( z ) @@ -64,7 +63,6 @@ // 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 ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.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 ); @@ -132,7 +130,6 @@ // 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 ] ); - > ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); > {{alias}}.ndarray( 2, ca, cx, 1, 1, cy, 1, 1 ); > z = cy.get( 2 ); > re = {{alias:@stdlib/complex/realf}}( z ) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js index 038310c0b326..d97fd05aaa51 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js @@ -34,10 +34,10 @@ var caddf = require( '@stdlib/math/base/ops/caddf' ); * @param {Complex64} ca - scalar constant * @param {Complex64Array} cx - first input array * @param {integer} strideX - `cx` stride length -* @param {integer} offsetX - `cx` offset +* @param {integer} offsetX - starting index for `cx` * @param {Complex64Array} cy - second input array * @param {integer} strideY - `cy` stride length -* @param {integer} offsetY - `cy` offset +* @param {integer} offsetY - starting index for `cy` * @returns {Complex64Array} second input array * * @example From cc0b3716d1b4aa3159456625213c7b2a74709946 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 11 Jul 2024 20:30:52 +0530 Subject: [PATCH 15/16] test: update descriptions and spacing --- lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js | 4 ++-- lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 index f0c3ef470619..3f410ec79f52 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -71,7 +71,7 @@ tape( 'the function has an arity of 6', function test( t ) { t.end(); }); -tape( 'the function scales elements from `cx` by `ca` and result to `cy`', function test( t ) { +tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy`', function test( t ) { var expected; var viewY; var ca; @@ -536,7 +536,7 @@ tape( 'the function supports view offsets', function test( t ) { 1.0, 1.0, 1.0, // 1 - 1.0 // 1 + 1.0 // 1 ]); // Define a scalar constant: 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 index 334c0d39330f..f6f8b7ac1e12 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js @@ -71,7 +71,7 @@ tape( 'the function has an arity of 8', function test( t ) { t.end(); }); -tape( 'the function scales elements from `cx` by `ca` and result to `cy`', function test( t ) { +tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy`', function test( t ) { var expected; var viewY; var ca; From 896ac44bee66c5053e1a2c6fd3941f8bcedb8c83 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 13 Jul 2024 18:29:52 -0700 Subject: [PATCH 16/16] test: fix test comparisons --- .../blas/base/caxpy/test/test.caxpy.js | 32 ++++----------- .../blas/base/caxpy/test/test.ndarray.js | 40 ++++--------------- 2 files changed, 15 insertions(+), 57 deletions(-) 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 index 3f410ec79f52..941e9004be22 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js @@ -77,7 +77,6 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -132,9 +131,7 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -144,7 +141,6 @@ tape( 'the function supports a `cx` stride', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -199,9 +195,7 @@ tape( 'the function supports a `cx` stride', function test( t ) { 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -211,7 +205,6 @@ tape( 'the function supports a `cy` stride', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -266,9 +259,7 @@ tape( 'the function supports a `cy` stride', function test( t ) { 0.32, // 4 -1.16 // 4 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -317,7 +308,6 @@ tape( 'the function supports negative `cx` strides', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 4 @@ -372,9 +362,7 @@ tape( 'the function supports negative `cx` strides', function test( t ) { 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -384,7 +372,6 @@ tape( 'the function supports negative `cy` strides', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -439,9 +426,7 @@ tape( 'the function supports negative `cy` strides', function test( t ) { 0.52, // 1 -1.51 // 1 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -451,7 +436,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 4 @@ -506,9 +490,7 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.32, // 1 -1.16 // 1 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -543,7 +525,7 @@ tape( 'the function supports view offsets', function test( t ) { ca = new Complex64( 2.0, 2.0 ); // Create offset views... - cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + 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 ); 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 index f6f8b7ac1e12..4a8e411efd9e 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.js @@ -77,7 +77,6 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -132,9 +131,7 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -144,7 +141,6 @@ tape( 'the function supports a `cx` stride', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -199,9 +195,7 @@ tape( 'the function supports a `cx` stride', function test( t ) { 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -211,7 +205,6 @@ tape( 'the function supports a `cx` offset', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, @@ -266,9 +259,7 @@ tape( 'the function supports a `cx` offset', function test( t ) { 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -278,7 +269,6 @@ tape( 'the function supports a `cy` stride', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -333,9 +323,7 @@ tape( 'the function supports a `cy` stride', function test( t ) { 0.32, // 4 -1.16 // 4 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -345,7 +333,6 @@ tape( 'the function supports a `cy` offset', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -400,9 +387,7 @@ tape( 'the function supports a `cy` offset', function test( t ) { 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -451,7 +436,6 @@ tape( 'the function supports a negative `cx` stride', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 4 @@ -506,9 +490,7 @@ tape( 'the function supports a negative `cx` stride', function test( t ) { 0.8, -0.7 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -518,7 +500,6 @@ tape( 'the function supports a negative `cy` stride', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 1 @@ -573,9 +554,7 @@ tape( 'the function supports a negative `cy` stride', function test( t ) { 0.52, // 1 -1.51 // 1 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); }); @@ -585,7 +564,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var ca; var cx; var cy; - var k; cx = new Complex64Array( [ 0.7, // 4 @@ -640,8 +618,6 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.32, // 1 -1.16 // 1 ] ); - for ( k = 0; k < expected.length; k++ ) { - isApprox( t, viewY[ k ], expected[ k ], 2.0 ); - } + isApprox( t, viewY, expected, 10.0 ); t.end(); });