From c3aab4bd0c3b432e36c7b011b42e67baad2074bf Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 27 May 2024 14:17:20 +0530 Subject: [PATCH 01/27] feat: add BLAS Level 1 routine for scnrm2 --- .../@stdlib/blas/base/scnrm2/README.md | 172 +++++++++++++++ .../blas/base/scnrm2/benchmark/benchmark.js | 93 ++++++++ .../scnrm2/benchmark/benchmark.ndarray.js | 93 ++++++++ .../@stdlib/blas/base/scnrm2/docs/repl.txt | 89 ++++++++ .../blas/base/scnrm2/docs/types/index.d.ts | 96 +++++++++ .../blas/base/scnrm2/docs/types/test.ts | 158 ++++++++++++++ .../blas/base/scnrm2/examples/index.js | 35 +++ .../@stdlib/blas/base/scnrm2/lib/index.js | 68 ++++++ .../@stdlib/blas/base/scnrm2/lib/main.js | 35 +++ .../@stdlib/blas/base/scnrm2/lib/ndarray.js | 87 ++++++++ .../@stdlib/blas/base/scnrm2/lib/scnrm2.js | 86 ++++++++ .../@stdlib/blas/base/scnrm2/package.json | 73 +++++++ .../@stdlib/blas/base/scnrm2/test/test.js | 82 ++++++++ .../blas/base/scnrm2/test/test.ndarray.js | 196 +++++++++++++++++ .../blas/base/scnrm2/test/test.scnrm2.js | 199 ++++++++++++++++++ 15 files changed, 1562 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md new file mode 100644 index 000000000000..217b2a80465f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md @@ -0,0 +1,172 @@ + + +# scnrm2 + +> Find the euclidean norm of a single-precision floating-point vector. + +
+ +## Usage + +```javascript +var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); +``` + +#### scnrm2( N, cx, strideX ) + +Finds the euclidean norm of a single-precision floating-point vector. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); + +var norm = scnrm2( 4, cx, 1 ); +// returns ~0.8 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. +- **strideX**: index increment for `cx`. + +The `N` and `strideX` parameters determine which elements in `cx` are accessed at runtime. For example, to traverse every other value, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var norm = scnrm2( 2, cx, 2 ); +// returns ~4.6 +``` + +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' ); + +// Initial array: +var cx0 = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create an offset view: +var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find euclidean norm: +var norm = scnrm2( 2, cx1, 1 ); +// returns ~9.3 +``` + +#### scnrm2.ndarray( N, cx, strideX, offset ) + +Finds the euclidean norm of a single-precision floating-point vector using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); + +var norm = scnrm2.ndarray( 4, cx, 1, 0 ); +// returns ~0.8 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a starting index. For example, to start from the second index, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +var norm = scnrm2.ndarray( 3, cx, 1, 1 ); +// returns ~9.3 +``` + +
+ + + +
+ +## Notes + +- If `N < 1` or `strideX < 0`, both functions return `0.0`. +- `scnrm2()` corresponds to the [BLAS][blas] level 1 function [`scnrm2`][scnrm2]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32' ); +var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.toString() ); + +// Finds the euclidean norm: +var norm = scnrm2( cx.length, cx, 1 ); +console.log( norm ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js new file mode 100644 index 000000000000..8de8e8ac763d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js @@ -0,0 +1,93 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib/scnrm2.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var cx = uniform( len, -10.0, 10.0, options ); + cx = new Complex64Array( cx.buffer ); + return benchmark; + + function benchmark( b ) { + var norm; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + norm = scnrm2( cx.length, cx, 1 ); + if ( isnan( norm ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( norm ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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/scnrm2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..083f7c404af0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js @@ -0,0 +1,93 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var cx = uniform( len, -10.0, 10.0, options ); + cx = new Complex64Array( cx.buffer ); + return benchmark; + + function benchmark( b ) { + var norm; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + norm = scnrm2( cx.length, cx, 1, 0 ); + if ( isnan( norm ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( norm ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt new file mode 100644 index 000000000000..57c2a7658d09 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt @@ -0,0 +1,89 @@ + +{{alias}}( N, cx, strideX ) + Finds the the euclidean norm of a single-precision floating-point vector. + + The `N` and `strideX` parameters determine which elements in `cx` are + accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N < 1` or `strideX < 0`, the function returns `0.0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `cx`. + + Returns + ------- + norm: number + Euclidean norm. + + Examples + -------- + // Standard Usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); + > var norm = {{alias}}( 4, cx, 1 ) + ~0.8 + + // Using `N` and stride parameters: + > cx = new {{alias:@stdlib/array/complex64}}( [ -2.0, 1.0, 3.0, -5.0 ] ); + > norm = {{alias}}( 1, cx, 2 ) + ~2.2 + + // Using view offsets: + > var cx0 = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var cx1 = new {{alias:@stdlib/array/complex64}}( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + > norm = {{alias}}( 2, cx1, 1 ) + ~9.3 + + +{{alias}}.ndarray( N, cx, strideX, offsetX ) + Finds the euclidean norm of a single-precision floating-point vector using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offsetX` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `cx`. + + offsetX: integer + Starting index of `cx`. + + Returns + ------- + norm: number + Euclidean norm. + + Examples + -------- + // Standard Usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ -2.0, 1.0, 3.0, -5.0 ] ); + > var norm = {{alias}}.ndarray( 1, cx, 2, 0 ) + ~2.2 + + // Using an index offset: + > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > norm = {{alias}}.ndarray( 3, cx, 1, 1 ) + ~9.3 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts new file mode 100644 index 000000000000..4086ddaab9ff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @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'; + +/** +* Interface describing `scnrm2`. +*/ +interface Routine { + /** + * Finds the euclidean norm of a single-precision floating-point vector. + * + * @param N - number of indexed elements + * @param cx - input array + * @param strideX - stride length for `cx` + * @returns euclidean norm + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); + * + * var norm = scnrm2( 4, cx, 1 ); + * // returns ~0.8 + */ + ( N: number, x: Complex64Array, strideX: number ): number; + + /** + * Finds the euclidean norm of a single-precision floating-point vector using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param cx - input array + * @param strideX - stride length for `cx` + * @param offsetX - starting index for `cx` + * @returns index value + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); + * + * var norm = scnrm2.ndarray( 4, cx, 1, 0 ); + * // returns ~0.8 + */ + ndarray( N: number, x: Complex64Array, strideX: number, offsetX: number ): number; +} + +/** +* Finds the euclidean norm of a single-precision floating-point vector. +* +* @param N - number of indexed elements +* @param cx - input array +* @param strideX - stride length for `cx` +* @returns index value +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var x = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0 ] ); +* +* var norm = scnrm2( 1, cx, 2 ); +* // returns ~2.2 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var x = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); +* +* var norm = scnrm2.ndarray( 2, cx, 1, 1 ); +* // returns ~9.3 +*/ +declare var scnrm2: Routine; + + +// EXPORTS // + +export = scnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/test.ts new file mode 100644 index 000000000000..dffd6ac98860 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/test.ts @@ -0,0 +1,158 @@ +/* +* @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 scnrm2 = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const cx = new Complex64Array( 10 ); + + scnrm2( cx.length, cx, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scnrm2( '10', cx, 1 ); // $ExpectError + scnrm2( true, cx, 1 ); // $ExpectError + scnrm2( false, cx, 1 ); // $ExpectError + scnrm2( null, cx, 1 ); // $ExpectError + scnrm2( undefined, cx, 1 ); // $ExpectError + scnrm2( [], cx, 1 ); // $ExpectError + scnrm2( {}, cx, 1 ); // $ExpectError + scnrm2( ( cx: number ): number => cx, cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + + scnrm2( cx.length, 10, 1 ); // $ExpectError + scnrm2( cx.length, '10', 1 ); // $ExpectError + scnrm2( cx.length, true, 1 ); // $ExpectError + scnrm2( cx.length, false, 1 ); // $ExpectError + scnrm2( cx.length, null, 1 ); // $ExpectError + scnrm2( cx.length, undefined, 1 ); // $ExpectError + scnrm2( cx.length, [], 1 ); // $ExpectError + scnrm2( cx.length, {}, 1 ); // $ExpectError + scnrm2( cx.length, ( cx: number ): number => cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scnrm2( cx.length, cx, '10' ); // $ExpectError + scnrm2( cx.length, cx, true ); // $ExpectError + scnrm2( cx.length, cx, false ); // $ExpectError + scnrm2( cx.length, cx, null ); // $ExpectError + scnrm2( cx.length, cx, undefined ); // $ExpectError + scnrm2( cx.length, cx, [] ); // $ExpectError + scnrm2( cx.length, cx, {} ); // $ExpectError + scnrm2( cx.length, cx, ( 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 ); + + scnrm2(); // $ExpectError + scnrm2( cx.length ); // $ExpectError + scnrm2( cx.length, cx ); // $ExpectError + scnrm2( cx.length, cx, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const cx = new Complex64Array( 10 ); + + scnrm2.ndarray( cx.length, cx, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scnrm2.ndarray( '10', cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( true, cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( false, cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( null, cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( undefined, cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( [], cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( {}, cx, 1, 0 ); // $ExpectError + scnrm2.ndarray( ( cx: number ): number => cx, cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + + scnrm2.ndarray( cx.length, 10, 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, '10', 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, true, 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, false, 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, null, 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, undefined, 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, [], 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, {}, 1, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, ( cx: number ): number => cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scnrm2.ndarray( cx.length, cx, '10', 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, true, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, false, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, null, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, undefined, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, [], 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, {}, 0 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, ( cx: number ): number => cx, 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 ); + + scnrm2.ndarray( cx.length, cx, 1, '10' ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, true ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, false ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, null ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, undefined ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, [] ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, {} ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 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 ); + + scnrm2.ndarray(); // $ExpectError + scnrm2.ndarray( cx.length ); // $ExpectError + scnrm2.ndarray( cx.length, cx ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1 ); // $ExpectError + scnrm2.ndarray( cx.length, cx, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/examples/index.js b/lib/node_modules/@stdlib/blas/base/scnrm2/examples/index.js new file mode 100644 index 000000000000..3b3f16459f06 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/examples/index.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'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32' ); +var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.toString() ); + +// Finds the euclidean norm: +var norm = scnrm2( cx.length, cx, 1 ); +console.log( norm ); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js new file mode 100644 index 000000000000..0e92b8411bd5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* BLAS level 1 routine to find the euclidean norm of a single-precision floating-point vector. +* +* @module @stdlib/blas/base/scnrm2 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); +* +* var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); +* +* var norm = scnrm2( 4, cx, 1 ); +* // returns ~0.8 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); +* +* var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); +* +* var norm = scnrm2.ndarray( 4, cx, 1, 0 ); +* // returns ~0.8 +*/ + +// 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 scnrm2; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + scnrm2 = main; +} else { + scnrm2 = tmp; +} + + +// EXPORTS // + +module.exports = scnrm2; + +// exports: { "ndarray": "scnrm2.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/main.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/main.js new file mode 100644 index 000000000000..fc2bcd9c6674 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/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 scnrm2 = require( './scnrm2.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( scnrm2, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = scnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js new file mode 100644 index 000000000000..f45ea936ebdc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js @@ -0,0 +1,87 @@ +/** +* @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 absf = require( '@stdlib/math/base/special/absf' ); +var imagf = require( '@stdlib/complex/imagf' ); +var realf = require( '@stdlib/complex/realf' ); +var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); + + +// MAIN // + +/** +* Finds the euclidean norm of a single-precision floating-point vector. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64Array} cx - input array +* @param {NonNegativeInteger} strideX - `cx` stride length +* @param {NonNegativeInteger} offsetX - starting index for `cx` +* @returns {number} index value +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); +* +* var norm = scnrm2( 4, cx, 1, 0 ); +* // returns ~0.8 +*/ +function scnrm2( N, cx, strideX, offsetX ) { + var scale; + var norm; + var temp; + var ssq; + var ix; + + if ( N < 1 || strideX < 0 ) { + return 0.0; + } + scale = 0.0; + ssq = 1.0; + for ( ix = offsetX; ix <= ( N - 1 ) * strideX; ix += strideX ) { + if ( realf( cx.get( ix ) ) !== 0.0 ) { + temp = absf( realf( cx.get( ix ) ) ); + if ( scale < temp ) { + ssq = 1.0 + ( ssq * ( scale / temp ) * ( scale / temp ) ); + scale = temp; + } else { + ssq += ( ( temp / scale ) * ( temp / scale ) ); + } + } + if ( imagf( cx.get( ix ) ) !== 0.0 ) { + temp = absf( imagf( cx.get( ix ) ) ); + if ( scale < temp ) { + ssq = 1.0 + ( ssq * ( scale / temp ) * ( scale / temp ) ); + scale = temp; + } else { + ssq += ( ( temp / scale ) * ( temp / scale ) ); + } + } + norm = scale * sqrtf( ssq ); + } + return norm; +} + + +// EXPORTS // + +module.exports = scnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js new file mode 100644 index 000000000000..478e1c512749 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var absf = require( '@stdlib/math/base/special/absf' ); +var imagf = require( '@stdlib/complex/imagf' ); +var realf = require( '@stdlib/complex/realf' ); +var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); + + +// MAIN // + +/** +* Finds the euclidean norm of a single-precision floating-point vector. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64Array} cx - input array +* @param {NonNegativeInteger} strideX - `cx` stride length +* @returns {number} index value +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); +* +* var norm = scnrm2( 4, cx, 1 ); +* // returns ~0.8 +*/ +function scnrm2( N, cx, strideX ) { + var scale; + var norm; + var temp; + var ssq; + var ix; + + if ( N < 1 || strideX < 0 ) { + return 0.0; + } + scale = 0.0; + ssq = 1.0; + for ( ix = 0; ix <= ( N - 1 ) * strideX; ix += strideX ) { + if ( realf( cx.get( ix ) ) !== 0.0 ) { + temp = absf( realf( cx.get( ix ) ) ); + if ( scale < temp ) { + ssq = 1.0 + ( ssq * ( ( scale / temp ) * ( scale / temp ) ) ); + scale = temp; + } else { + ssq += ( ( temp / scale ) * ( temp / scale ) ); + } + } + if ( imagf( cx.get( ix ) ) !== 0.0 ) { + temp = absf( imagf( cx.get( ix ) ) ); + if ( scale < temp ) { + ssq = 1.0 + ( ssq * ( ( scale / temp ) * ( scale / temp ) ) ); + scale = temp; + } else { + ssq += ( ( temp / scale ) * ( temp / scale ) ); + } + } + norm = scale * sqrtf( ssq ); + } + return norm; +} + + +// EXPORTS // + +module.exports = scnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/package.json b/lib/node_modules/@stdlib/blas/base/scnrm2/package.json new file mode 100644 index 000000000000..63e347b66d24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/blas/base/scnrm2", + "version": "0.0.0", + "description": "Find the euclidean norm of a single-precision 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", + "scnrm2", + "euclidean", + "norm", + "euclidean-norm", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "float32", + "float", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.js b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.js new file mode 100644 index 000000000000..1b86c01e265e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/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 scnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scnrm2, '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 scnrm2.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 scnrm2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( scnrm2, 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 scnrm2; + var main; + + main = require( './../lib/scnrm2.js' ); + + scnrm2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( scnrm2, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js new file mode 100644 index 000000000000..54036a8fb65c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js @@ -0,0 +1,196 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var scnrm2 = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scnrm2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( scnrm2.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function finds the euclidean norm', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0 + ]); + expected = 0.8; + + norm = scnrm2( 4, cx, 1, 0 ); + isApprox( t, norm, expected, 2 ); + + cx = new Complex64Array( [ + 0.1, // 1 + 0.1, // 1 + -0.6, // 2 + 0.1, // 2 + 0.1, // 3 + -0.3, // 3 + 7.0, + 8.0 + ] ); + expected = 0.7; + + norm = scnrm2( 3, cx, 1, 0 ); + isApprox( t, norm, expected, 2 ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the function returns `0.0`', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array( [ + 1.0, + 2.0, + 3.0, + 4.0 + ] ); + expected = 0.0; + + norm = scnrm2( 0, cx, 1, 0 ); + t.strictEqual( norm, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `strideX` parameter less than `0`, the function returns `0.0`', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + expected = 0.0; + + norm = scnrm2( cx.length, cx, -1, 0 ); + t.strictEqual( norm, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 0.8; + + norm = scnrm2( 4, cx, 2, 0 ); + isApprox( t, norm, expected, 2 ); + t.end(); +}); + +tape( 'the function supports specifying an offset', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, // 2 + 6.0, // 2 + 7.0, // 3 + 8.0, // 3 + 9.0, + 10.0 + ]); + expected = 14.1; + + norm = scnrm2( 3, cx, 1, 1 ); + isApprox( t, norm, expected, 2 ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js new file mode 100644 index 000000000000..0da4708f0b89 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js @@ -0,0 +1,199 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var scnrm2 = require( './../lib/scnrm2.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scnrm2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( scnrm2.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function finds the euclidean norm', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0 + ]); + expected = 0.8; + + norm = scnrm2( 4, cx, 1 ); + isApprox( t, norm, expected, 2 ); + + cx = new Complex64Array( [ + 0.1, // 1 + 0.1, // 1 + -0.6, // 2 + 0.1, // 2 + 0.1, // 3 + -0.3, // 3 + 7.0, + 8.0 + ] ); + expected = 0.7; + + norm = scnrm2( 3, cx, 1 ); + isApprox( t, norm, expected, 2 ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the function returns `0.0`', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array( [ + 1.0, + 2.0, + 3.0, + 4.0 + ] ); + expected = 0.0; + + norm = scnrm2( 0, cx, 1 ); + t.strictEqual( norm, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `strideX` parameter less than `0`, the function returns `0.0`', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + expected = 0.0; + + norm = scnrm2( cx.length, cx, -1 ); + t.strictEqual( norm, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var norm; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 0.8; + + norm = scnrm2( 4, cx, 2 ); + isApprox( t, norm, expected, 2 ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var norm; + var cx0; + var cx1; + + cx0 = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, // 2 + 6.0, // 2 + 7.0, // 3 + 8.0, // 3 + 9.0, + 10.0 + ]); + expected = 14.1; + + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + + norm = scnrm2( 3, cx1, 1 ); + isApprox( t, norm, expected, 2 ); + t.end(); +}); From 5453d22f84bf6f9241657b803085ed4e4b471dd3 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 27 May 2024 16:12:10 +0530 Subject: [PATCH 02/27] chore: apply review changes --- lib/node_modules/@stdlib/blas/base/scnrm2/README.md | 6 +++--- lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt | 7 ++++--- .../@stdlib/blas/base/scnrm2/docs/types/index.d.ts | 6 +++--- lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js | 2 +- lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md index 217b2a80465f..5a58c65f53de 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md @@ -20,7 +20,7 @@ limitations under the License. # scnrm2 -> Find the euclidean norm of a single-precision floating-point vector. +> Find the euclidean norm of a complex single-precision floating-point vector.
@@ -32,7 +32,7 @@ var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); #### scnrm2( N, cx, strideX ) -Finds the euclidean norm of a single-precision floating-point vector. +Finds the euclidean norm of a complex single-precision floating-point vector. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); @@ -78,7 +78,7 @@ var norm = scnrm2( 2, cx1, 1 ); #### scnrm2.ndarray( N, cx, strideX, offset ) -Finds the euclidean norm of a single-precision floating-point vector using alternative indexing semantics. +Finds the euclidean norm of a complex single-precision floating-point vector using alternative indexing semantics. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt index 57c2a7658d09..b8f64ec2058a 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt @@ -1,6 +1,7 @@ {{alias}}( N, cx, strideX ) - Finds the the euclidean norm of a single-precision floating-point vector. + Finds the the euclidean norm of a complex single-precision floating-point + vector. The `N` and `strideX` parameters determine which elements in `cx` are accessed at runtime. @@ -46,8 +47,8 @@ {{alias}}.ndarray( N, cx, strideX, offsetX ) - Finds the euclidean norm of a single-precision floating-point vector using - alternative indexing semantics. + Finds the euclidean norm of a complex single-precision floating-point + vector using alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the `offsetX` parameter supports indexing semantics based on a diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts index 4086ddaab9ff..62bd816f7b01 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts @@ -27,7 +27,7 @@ import { Complex64Array } from '@stdlib/types/array'; */ interface Routine { /** - * Finds the euclidean norm of a single-precision floating-point vector. + * Finds the euclidean norm of a complex single-precision floating-point vector. * * @param N - number of indexed elements * @param cx - input array @@ -45,7 +45,7 @@ interface Routine { ( N: number, x: Complex64Array, strideX: number ): number; /** - * Finds the euclidean norm of a single-precision floating-point vector using alternative indexing semantics. + * Finds the euclidean norm of a complex single-precision floating-point vector using alternative indexing semantics. * * @param N - number of indexed elements * @param cx - input array @@ -65,7 +65,7 @@ interface Routine { } /** -* Finds the euclidean norm of a single-precision floating-point vector. +* Finds the euclidean norm of a complex single-precision floating-point vector. * * @param N - number of indexed elements * @param cx - input array diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js index 0e92b8411bd5..c48056ba752a 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* BLAS level 1 routine to find the euclidean norm of a single-precision floating-point vector. +* BLAS level 1 routine to find the euclidean norm of a complex single-precision floating-point vector. * * @module @stdlib/blas/base/scnrm2 * diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js index f45ea936ebdc..8a4f1365614f 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js @@ -29,7 +29,7 @@ var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); // MAIN // /** -* Finds the euclidean norm of a single-precision floating-point vector. +* Finds the euclidean norm of a complex single-precision floating-point vector. * * @param {PositiveInteger} N - number of indexed elements * @param {Complex64Array} cx - input array diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js index 478e1c512749..cac99ee4ad1f 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js @@ -29,7 +29,7 @@ var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); // MAIN // /** -* Finds the euclidean norm of a single-precision floating-point vector. +* Finds the euclidean norm of a complex single-precision floating-point vector. * * @param {PositiveInteger} N - number of indexed elements * @param {Complex64Array} cx - input array From 9bb083aba89b72f4102b1511f83fd859e5244d9c Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 10 Jun 2024 23:48:10 -0400 Subject: [PATCH 03/27] bench: ensure arrays are of intended length --- .../@stdlib/blas/base/scnrm2/benchmark/benchmark.js | 8 ++++---- .../blas/base/scnrm2/benchmark/benchmark.ndarray.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js index 8de8e8ac763d..f0e1496863e1 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js @@ -22,7 +22,7 @@ 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 pkg = require( './../package.json' ).name; @@ -46,7 +46,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var cx = uniform( len, -10.0, 10.0, options ); + var cx = uniform( len*2, -10.0, 10.0, options ); cx = new Complex64Array( cx.buffer ); return benchmark; @@ -57,12 +57,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { norm = scnrm2( cx.length, cx, 1 ); - if ( isnan( norm ) ) { + if ( isnanf( norm ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( norm ) ) { + if ( isnanf( norm ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js index 083f7c404af0..d4f336f670c2 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js @@ -22,7 +22,7 @@ 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 pkg = require( './../package.json' ).name; @@ -46,7 +46,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var cx = uniform( len, -10.0, 10.0, options ); + var cx = uniform( len*2, -10.0, 10.0, options ); cx = new Complex64Array( cx.buffer ); return benchmark; @@ -57,12 +57,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { norm = scnrm2( cx.length, cx, 1, 0 ); - if ( isnan( norm ) ) { + if ( isnanf( norm ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( norm ) ) { + if ( isnanf( norm ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); From e50fcda91dd169694d24442315d61b8b56b49610 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 10 Jun 2024 23:52:52 -0400 Subject: [PATCH 04/27] docs: update descriptions --- .../@stdlib/blas/base/scnrm2/docs/types/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts index 62bd816f7b01..e9fda6c2d119 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/types/index.d.ts @@ -27,12 +27,12 @@ import { Complex64Array } from '@stdlib/types/array'; */ interface Routine { /** - * Finds the euclidean norm of a complex single-precision floating-point vector. + * Computes the L2-norm of a complex single-precision floating-point vector. * * @param N - number of indexed elements * @param cx - input array * @param strideX - stride length for `cx` - * @returns euclidean norm + * @returns L2-norm * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); @@ -45,13 +45,13 @@ interface Routine { ( N: number, x: Complex64Array, strideX: number ): number; /** - * Finds the euclidean norm of a complex single-precision floating-point vector using alternative indexing semantics. + * Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. * * @param N - number of indexed elements * @param cx - input array * @param strideX - stride length for `cx` * @param offsetX - starting index for `cx` - * @returns index value + * @returns L2-norm * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); @@ -65,12 +65,12 @@ interface Routine { } /** -* Finds the euclidean norm of a complex single-precision floating-point vector. +* Computes the L2-norm of a complex single-precision floating-point vector. * * @param N - number of indexed elements * @param cx - input array * @param strideX - stride length for `cx` -* @returns index value +* @returns L2-norm * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); From 4b7d1d80621882aec74c2326da2c738d1591d8b0 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 10 Jun 2024 23:53:40 -0400 Subject: [PATCH 05/27] bench: inline expression to avoid unnecessary reassignment --- .../@stdlib/blas/base/scnrm2/benchmark/benchmark.js | 3 +-- .../@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js index f0e1496863e1..88b0f0d3102e 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.js @@ -46,8 +46,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var cx = uniform( len*2, -10.0, 10.0, options ); - cx = new Complex64Array( cx.buffer ); + var cx = new Complex64Array( uniform( len*2, -10.0, 10.0, options ) ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js index d4f336f670c2..69868a754941 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.js @@ -46,8 +46,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var cx = uniform( len*2, -10.0, 10.0, options ); - cx = new Complex64Array( cx.buffer ); + var cx = new Complex64Array( uniform( len*2, -10.0, 10.0, options ) ); return benchmark; function benchmark( b ) { From ef90a7c174e4c1a9bfa175a147382fd97da4aebb Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 19 Jun 2024 14:01:10 +0530 Subject: [PATCH 06/27] refactor: update implementation --- .../@stdlib/blas/base/scnrm2/README.md | 12 +- .../@stdlib/blas/base/scnrm2/docs/repl.txt | 15 ++- .../@stdlib/blas/base/scnrm2/lib/index.js | 2 +- .../@stdlib/blas/base/scnrm2/lib/ndarray.js | 111 +++++++++++++---- .../@stdlib/blas/base/scnrm2/lib/scnrm2.js | 116 ++++++++++++++---- .../@stdlib/blas/base/scnrm2/package.json | 2 +- .../blas/base/scnrm2/test/test.ndarray.js | 32 +++-- .../blas/base/scnrm2/test/test.scnrm2.js | 32 +++-- 8 files changed, 240 insertions(+), 82 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md index 5a58c65f53de..5c0614f4dcb2 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md @@ -20,7 +20,7 @@ limitations under the License. # scnrm2 -> Find the euclidean norm of a complex single-precision floating-point vector. +> Compute the L2-norm of a complex single-precision floating-point vector.
@@ -32,7 +32,7 @@ var scnrm2 = require( '@stdlib/blas/base/scnrm2' ); #### scnrm2( N, cx, strideX ) -Finds the euclidean norm of a complex single-precision floating-point vector. +Computes the L2-norm of a complex single-precision floating-point vector. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); @@ -78,7 +78,7 @@ var norm = scnrm2( 2, cx1, 1 ); #### scnrm2.ndarray( N, cx, strideX, offset ) -Finds the euclidean norm of a complex single-precision floating-point vector using alternative indexing semantics. +Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. ```javascript var Complex64Array = require( '@stdlib/array/complex64' ); @@ -100,7 +100,7 @@ var Complex64Array = require( '@stdlib/array/complex64' ); var cx = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); -var norm = scnrm2.ndarray( 3, cx, 1, 1 ); +var norm = scnrm2.ndarray( 2, cx, 1, 1 ); // returns ~9.3 ``` @@ -112,7 +112,7 @@ var norm = scnrm2.ndarray( 3, cx, 1, 1 ); ## Notes -- If `N < 1` or `strideX < 0`, both functions return `0.0`. +- If `N <= 0`, both functions return `0.0`. - `scnrm2()` corresponds to the [BLAS][blas] level 1 function [`scnrm2`][scnrm2].
@@ -161,7 +161,7 @@ console.log( norm ); [blas]: http://www.netlib.org/blas -[scnrm2]: http://www.netlib.org/lapack/explore-html/de/da4/group__double__blas__level1.html +[scnrm2]: https://www.netlib.org/lapack/explore-html/d1/d2a/group__nrm2_gaee5779d5d216a7cd8cf83488fb6bb175.html#gaee5779d5d216a7cd8cf83488fb6bb175 [@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt index b8f64ec2058a..19daa9005da4 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/docs/repl.txt @@ -1,7 +1,6 @@ {{alias}}( N, cx, strideX ) - Finds the the euclidean norm of a complex single-precision floating-point - vector. + Computes the L2-norm of a complex single-precision floating-point vector. The `N` and `strideX` parameters determine which elements in `cx` are accessed at runtime. @@ -9,7 +8,7 @@ Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N < 1` or `strideX < 0`, the function returns `0.0`. + If `N <= 0`, the function returns `0.0`. Parameters ---------- @@ -25,7 +24,7 @@ Returns ------- norm: number - Euclidean norm. + L2-norm. Examples -------- @@ -47,8 +46,8 @@ {{alias}}.ndarray( N, cx, strideX, offsetX ) - Finds the euclidean norm of a complex single-precision floating-point - vector using alternative indexing semantics. + Computes the L2-norm of a complex single-precision floating-point vector + using alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the `offsetX` parameter supports indexing semantics based on a @@ -71,7 +70,7 @@ Returns ------- norm: number - Euclidean norm. + L2-norm. Examples -------- @@ -82,7 +81,7 @@ // Using an index offset: > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > norm = {{alias}}.ndarray( 3, cx, 1, 1 ) + > norm = {{alias}}.ndarray( 2, cx, 1, 1 ) ~9.3 See Also diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js index c48056ba752a..64d20bf95a7c 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* BLAS level 1 routine to find the euclidean norm of a complex single-precision floating-point vector. +* BLAS level 1 routine to compute the L2-norm of a complex single-precision floating-point vector. * * @module @stdlib/blas/base/scnrm2 * diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js index 8a4f1365614f..881271495919 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js @@ -20,22 +20,37 @@ // MODULES // +var f32 = require( '@stdlib/number/float64/base/to-float32' ); var absf = require( '@stdlib/math/base/special/absf' ); -var imagf = require( '@stdlib/complex/imagf' ); -var realf = require( '@stdlib/complex/realf' ); var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + + +// VARIABLES // + +// Largest positive single-precision floating-point number +var maxN = 3.4028234663852886e38; + +// Blue's scaling constants... +var tsml = 1.08420217E-19; + +var tbig = 4.50359963E+15; + +var ssml = 3.77789319E+22; + +var sbig = 1.32348898E-23; // MAIN // /** -* Finds the euclidean norm of a complex single-precision floating-point vector. +* Computes the L2-norm of a complex single-precision floating-point vector. * * @param {PositiveInteger} N - number of indexed elements * @param {Complex64Array} cx - input array * @param {NonNegativeInteger} strideX - `cx` stride length * @param {NonNegativeInteger} offsetX - starting index for `cx` -* @returns {number} index value +* @returns {number} L2-norm * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); @@ -46,38 +61,84 @@ var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); * // returns ~0.8 */ function scnrm2( N, cx, strideX, offsetX ) { - var scale; + var notbig; + var sumsq; + var viewX; + var abig; + var amed; + var asml; var norm; - var temp; - var ssq; + var ymax; + var ymin; + var scl; + var ax; var ix; + var i; - if ( N < 1 || strideX < 0 ) { + if ( N <= 0 ) { return 0.0; } - scale = 0.0; - ssq = 1.0; - for ( ix = offsetX; ix <= ( N - 1 ) * strideX; ix += strideX ) { - if ( realf( cx.get( ix ) ) !== 0.0 ) { - temp = absf( realf( cx.get( ix ) ) ); - if ( scale < temp ) { - ssq = 1.0 + ( ssq * ( scale / temp ) * ( scale / temp ) ); - scale = temp; - } else { - ssq += ( ( temp / scale ) * ( temp / scale ) ); + scl = 1.0; + sumsq = 0.0; + notbig = true; + abig = 0.0; + amed = 0.0; + asml = 0.0; + ix = offsetX * 2; + viewX = reinterpret( cx, 0 ); + for ( i = 0; i < N; i++ ) { + ax = absf( viewX[ ix ] ); + if ( ax > tbig ) { + abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + notbig = false; + } else if ( ax < tsml ) { + if ( notbig ) { + asml += f32( ( ax * ssml ) * ( ax * ssml ) ); + } + } else { + amed += f32( ax * ax ); + } + ax = absf( viewX[ ix + 1 ] ); + if ( ax > tbig ) { + abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + notbig = false; + } else if ( ax < tsml ) { + if ( notbig ) { + asml += f32( ( ax * ssml ) * ( ax * ssml ) ); } + } else { + amed += f32( ax * ax ); + } + ix += ( strideX * 2 ); + } + if ( abig > 0.0 ) { + if ( amed > 0.0 || ( amed > maxN ) || ( amed !== amed ) ) { + abig += f32( ( amed * sbig ) * sbig ); } - if ( imagf( cx.get( ix ) ) !== 0.0 ) { - temp = absf( imagf( cx.get( ix ) ) ); - if ( scale < temp ) { - ssq = 1.0 + ( ssq * ( scale / temp ) * ( scale / temp ) ); - scale = temp; + scl = 1.0 / sbig; + sumsq = abig; + } else if ( asml > 0.0 ) { + if ( amed > 0.0 || amed > maxN || ( amed !== amed ) ) { + amed = sqrtf( amed ); + asml = sqrtf( asml ) / ssml; + if ( asml > amed ) { + ymin = amed; + ymax = asml; } else { - ssq += ( ( temp / scale ) * ( temp / scale ) ); + ymin = asml; + ymax = amed; } + scl = 1.0; + sumsq = f32( ( ymax * ymax ) * ( 1.0 + ( ( ymin / ymax ) * ( ymin / ymax ) ) ) ); // eslint-disable-line max-len + } else { + scl = ( 1.0 / ssml ); + sumsq = asml; } - norm = scale * sqrtf( ssq ); + } else { + scl = 1.0; + sumsq = amed; } + norm = f32( sqrtf( sumsq ) * scl ); return norm; } diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js index cac99ee4ad1f..85ed0a2259ba 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js @@ -20,21 +20,36 @@ // MODULES // +var f32 = require( '@stdlib/number/float64/base/to-float32' ); var absf = require( '@stdlib/math/base/special/absf' ); -var imagf = require( '@stdlib/complex/imagf' ); -var realf = require( '@stdlib/complex/realf' ); var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + + +// VARIABLES // + +// Largest positive single-precision floating-point number +var maxN = 3.4028234663852886e38; + +// Blue's scaling constants... +var tsml = 1.08420217E-19; + +var tbig = 4.50359963E+15; + +var ssml = 3.77789319E+22; + +var sbig = 1.32348898E-23; // MAIN // /** -* Finds the euclidean norm of a complex single-precision floating-point vector. +* Computes the L2-norm of a complex single-precision floating-point vector. * * @param {PositiveInteger} N - number of indexed elements * @param {Complex64Array} cx - input array * @param {NonNegativeInteger} strideX - `cx` stride length -* @returns {number} index value +* @returns {number} L2-norm * * @example * var Complex64Array = require( '@stdlib/array/complex64' ); @@ -45,38 +60,89 @@ var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); * // returns ~0.8 */ function scnrm2( N, cx, strideX ) { - var scale; + var notbig; + var sumsq; + var viewX; + var abig; + var amed; + var asml; var norm; - var temp; - var ssq; + var ymax; + var ymin; + var scl; + var ax; var ix; + var i; - if ( N < 1 || strideX < 0 ) { + if ( N <= 0 ) { return 0.0; } - scale = 0.0; - ssq = 1.0; - for ( ix = 0; ix <= ( N - 1 ) * strideX; ix += strideX ) { - if ( realf( cx.get( ix ) ) !== 0.0 ) { - temp = absf( realf( cx.get( ix ) ) ); - if ( scale < temp ) { - ssq = 1.0 + ( ssq * ( ( scale / temp ) * ( scale / temp ) ) ); - scale = temp; - } else { - ssq += ( ( temp / scale ) * ( temp / scale ) ); + scl = 1.0; + sumsq = 0.0; + notbig = true; + abig = 0.0; + amed = 0.0; + asml = 0.0; + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX * 2; + } + else { + ix = 0; + } + viewX = reinterpret( cx, 0 ); + for ( i = 0; i < N; i++ ) { + ax = absf( viewX[ ix ] ); + if ( ax > tbig ) { + abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + notbig = false; + } else if ( ax < tsml ) { + if ( notbig ) { + asml += f32( ( ax * ssml ) * ( ax * ssml ) ); } + } else { + amed += f32( ax * ax ); + } + ax = absf( viewX[ ix + 1 ] ); + if ( ax > tbig ) { + abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + notbig = false; + } else if ( ax < tsml ) { + if ( notbig ) { + asml += f32( ( ax * ssml ) * ( ax * ssml ) ); + } + } else { + amed += f32( ax * ax ); + } + ix += ( strideX * 2 ); + } + if ( abig > 0.0 ) { + if ( amed > 0.0 || ( amed > maxN ) || ( amed !== amed ) ) { + abig += f32( ( amed * sbig ) * sbig ); } - if ( imagf( cx.get( ix ) ) !== 0.0 ) { - temp = absf( imagf( cx.get( ix ) ) ); - if ( scale < temp ) { - ssq = 1.0 + ( ssq * ( ( scale / temp ) * ( scale / temp ) ) ); - scale = temp; + scl = 1.0 / sbig; + sumsq = abig; + } else if ( asml > 0.0 ) { + if ( amed > 0.0 || amed > maxN || ( amed !== amed ) ) { + amed = sqrtf( amed ); + asml = sqrtf( asml ) / ssml; + if ( asml > amed ) { + ymin = amed; + ymax = asml; } else { - ssq += ( ( temp / scale ) * ( temp / scale ) ); + ymin = asml; + ymax = amed; } + scl = 1.0; + sumsq = f32( ( ymax * ymax ) * ( 1.0 + ( ( ymin / ymax ) * ( ymin / ymax ) ) ) ); // eslint-disable-line max-len + } else { + scl = ( 1.0 / ssml ); + sumsq = asml; } - norm = scale * sqrtf( ssq ); + } else { + scl = 1.0; + sumsq = amed; } + norm = f32( sqrtf( sumsq ) * scl ); return norm; } diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/package.json b/lib/node_modules/@stdlib/blas/base/scnrm2/package.json index 63e347b66d24..83f02d060878 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/package.json +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/base/scnrm2", "version": "0.0.0", - "description": "Find the euclidean norm of a single-precision floating-point vector.", + "description": "Compute the L2-norm of a complex single-precision floating-point vector.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js index 54036a8fb65c..9b7c2e5923bb 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js @@ -127,21 +127,37 @@ tape( 'if provided an `N` parameter less than `1`, the function returns `0.0`', t.end(); }); -tape( 'if provided a `strideX` parameter less than `0`, the function returns `0.0`', function test( t ) { +tape( 'the function supports specifying a stride', function test( t ) { var expected; var norm; var cx; - cx = new Complex64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); - expected = 0.0; - - norm = scnrm2( cx.length, cx, -1, 0 ); - t.strictEqual( norm, expected, 'returns expected value' ); + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 0.8; + norm = scnrm2( 4, cx, 2, 0 ); + isApprox( t, norm, expected, 2 ); t.end(); }); -tape( 'the function supports specifying a stride', function test( t ) { +tape( 'the function supports specifying a negative stride', function test( t ) { var expected; var norm; var cx; @@ -166,7 +182,7 @@ tape( 'the function supports specifying a stride', function test( t ) { ]); expected = 0.8; - norm = scnrm2( 4, cx, 2, 0 ); + norm = scnrm2( 4, cx, -2, 6 ); isApprox( t, norm, expected, 2 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js index 0da4708f0b89..63b87bb5adf9 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js @@ -127,21 +127,37 @@ tape( 'if provided an `N` parameter less than `1`, the function returns `0.0`', t.end(); }); -tape( 'if provided a `strideX` parameter less than `0`, the function returns `0.0`', function test( t ) { +tape( 'the function supports specifying a stride', function test( t ) { var expected; var norm; var cx; - cx = new Complex64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); - expected = 0.0; - - norm = scnrm2( cx.length, cx, -1 ); - t.strictEqual( norm, expected, 'returns expected value' ); + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 0.8; + norm = scnrm2( 4, cx, 2 ); + isApprox( t, norm, expected, 2 ); t.end(); }); -tape( 'the function supports specifying a stride', function test( t ) { +tape( 'the function supports specifying a negative stride', function test( t ) { var expected; var norm; var cx; @@ -166,7 +182,7 @@ tape( 'the function supports specifying a stride', function test( t ) { ]); expected = 0.8; - norm = scnrm2( 4, cx, 2 ); + norm = scnrm2( 4, cx, -2 ); isApprox( t, norm, expected, 2 ); t.end(); }); From ee256696bc63181c076f783b1d0015475cfe2a26 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 19 Jun 2024 14:06:21 +0530 Subject: [PATCH 07/27] docs: update variable type description --- lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js index 881271495919..b4d0d893a9db 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js @@ -48,7 +48,7 @@ var sbig = 1.32348898E-23; * * @param {PositiveInteger} N - number of indexed elements * @param {Complex64Array} cx - input array -* @param {NonNegativeInteger} strideX - `cx` stride length +* @param {integer} strideX - `cx` stride length * @param {NonNegativeInteger} offsetX - starting index for `cx` * @returns {number} L2-norm * diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js index 85ed0a2259ba..26f2a9d87f9d 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js @@ -48,7 +48,7 @@ var sbig = 1.32348898E-23; * * @param {PositiveInteger} N - number of indexed elements * @param {Complex64Array} cx - input array -* @param {NonNegativeInteger} strideX - `cx` stride length +* @param {integer} strideX - `cx` stride length * @returns {number} L2-norm * * @example From 90bafad2302b0e60ea55b634a832d8ed5bceff88 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 19 Jun 2024 14:17:25 +0530 Subject: [PATCH 08/27] chore: apply emulation of float32 arithmetic --- .../@stdlib/blas/base/scnrm2/lib/ndarray.js | 18 +++++++++--------- .../@stdlib/blas/base/scnrm2/lib/scnrm2.js | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js index b4d0d893a9db..db3975cdb92f 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.js @@ -89,22 +89,22 @@ function scnrm2( N, cx, strideX, offsetX ) { for ( i = 0; i < N; i++ ) { ax = absf( viewX[ ix ] ); if ( ax > tbig ) { - abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + abig += f32( f32( ax * sbig ) * f32( ax * sbig ) ); notbig = false; } else if ( ax < tsml ) { if ( notbig ) { - asml += f32( ( ax * ssml ) * ( ax * ssml ) ); + asml += f32( f32( ax * ssml ) * f32( ax * ssml ) ); } } else { amed += f32( ax * ax ); } ax = absf( viewX[ ix + 1 ] ); if ( ax > tbig ) { - abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + abig += f32( f32( ax * sbig ) * f32( ax * sbig ) ); notbig = false; } else if ( ax < tsml ) { if ( notbig ) { - asml += f32( ( ax * ssml ) * ( ax * ssml ) ); + asml += f32( f32( ax * ssml ) * f32( ax * ssml ) ); } } else { amed += f32( ax * ax ); @@ -113,14 +113,14 @@ function scnrm2( N, cx, strideX, offsetX ) { } if ( abig > 0.0 ) { if ( amed > 0.0 || ( amed > maxN ) || ( amed !== amed ) ) { - abig += f32( ( amed * sbig ) * sbig ); + abig += f32( f32( amed * sbig ) * sbig ); } - scl = 1.0 / sbig; + scl = f32( 1.0 / sbig ); sumsq = abig; } else if ( asml > 0.0 ) { if ( amed > 0.0 || amed > maxN || ( amed !== amed ) ) { amed = sqrtf( amed ); - asml = sqrtf( asml ) / ssml; + asml = f32( sqrtf( asml ) / ssml ); if ( asml > amed ) { ymin = amed; ymax = asml; @@ -129,9 +129,9 @@ function scnrm2( N, cx, strideX, offsetX ) { ymax = amed; } scl = 1.0; - sumsq = f32( ( ymax * ymax ) * ( 1.0 + ( ( ymin / ymax ) * ( ymin / ymax ) ) ) ); // eslint-disable-line max-len + sumsq = f32( f32( ymax * ymax ) * ( 1.0 + ( f32( ymin / ymax ) * f32( ymin / ymax ) ) ) ); // eslint-disable-line max-len } else { - scl = ( 1.0 / ssml ); + scl = f32( 1.0 / ssml ); sumsq = asml; } } else { diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js index 26f2a9d87f9d..3f1ca45fb71c 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.js @@ -93,22 +93,22 @@ function scnrm2( N, cx, strideX ) { for ( i = 0; i < N; i++ ) { ax = absf( viewX[ ix ] ); if ( ax > tbig ) { - abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + abig += f32( f32( ax * sbig ) * f32( ax * sbig ) ); notbig = false; } else if ( ax < tsml ) { if ( notbig ) { - asml += f32( ( ax * ssml ) * ( ax * ssml ) ); + asml += f32( f32( ax * ssml ) * f32( ax * ssml ) ); } } else { amed += f32( ax * ax ); } ax = absf( viewX[ ix + 1 ] ); if ( ax > tbig ) { - abig += f32( ( ax * sbig ) * ( ax * sbig ) ); + abig += f32( f32( ax * sbig ) * f32( ax * sbig ) ); notbig = false; } else if ( ax < tsml ) { if ( notbig ) { - asml += f32( ( ax * ssml ) * ( ax * ssml ) ); + asml += f32( f32( ax * ssml ) * f32( ax * ssml ) ); } } else { amed += f32( ax * ax ); @@ -117,14 +117,14 @@ function scnrm2( N, cx, strideX ) { } if ( abig > 0.0 ) { if ( amed > 0.0 || ( amed > maxN ) || ( amed !== amed ) ) { - abig += f32( ( amed * sbig ) * sbig ); + abig += f32( f32( amed * sbig ) * sbig ); } - scl = 1.0 / sbig; + scl = f32( 1.0 / sbig ); sumsq = abig; } else if ( asml > 0.0 ) { if ( amed > 0.0 || amed > maxN || ( amed !== amed ) ) { amed = sqrtf( amed ); - asml = sqrtf( asml ) / ssml; + asml = f32( sqrtf( asml ) / ssml ); if ( asml > amed ) { ymin = amed; ymax = asml; @@ -133,9 +133,9 @@ function scnrm2( N, cx, strideX ) { ymax = amed; } scl = 1.0; - sumsq = f32( ( ymax * ymax ) * ( 1.0 + ( ( ymin / ymax ) * ( ymin / ymax ) ) ) ); // eslint-disable-line max-len + sumsq = f32( f32( ymax * ymax ) * f32( 1.0 + f32( f32( ymin / ymax ) * f32( ymin / ymax ) ) ) ); // eslint-disable-line max-len } else { - scl = ( 1.0 / ssml ); + scl = f32( 1.0 / ssml ); sumsq = asml; } } else { From 0d073d458ac30a222b6a51328b0e91c25940e993 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 20 Jun 2024 12:04:17 +0530 Subject: [PATCH 09/27] feat: add C / Fortran implementation for scnrm2 --- .../@stdlib/blas/base/scnrm2/README.md | 95 ++++ .../base/scnrm2/benchmark/benchmark.native.js | 97 ++++ .../benchmark/benchmark.ndarray.native.js | 97 ++++ .../blas/base/scnrm2/benchmark/c/Makefile | 146 ++++++ .../scnrm2/benchmark/c/benchmark.length.c | 155 ++++++ .../base/scnrm2/benchmark/fortran/Makefile | 141 ++++++ .../benchmark/fortran/benchmark.length.f | 220 +++++++++ .../@stdlib/blas/base/scnrm2/binding.gyp | 265 ++++++++++ .../blas/base/scnrm2/examples/c/Makefile | 146 ++++++ .../blas/base/scnrm2/examples/c/example.c | 37 ++ .../blas/base/scnrm2/examples/index.js | 2 +- .../@stdlib/blas/base/scnrm2/include.gypi | 70 +++ .../scnrm2/include/stdlib/blas/base/scnrm2.h | 43 ++ .../include/stdlib/blas/base/scnrm2_cblas.h | 43 ++ .../include/stdlib/blas/base/scnrm2_fortran.h | 41 ++ .../@stdlib/blas/base/scnrm2/lib/native.js | 35 ++ .../@stdlib/blas/base/scnrm2/lib/ndarray.js | 4 +- .../blas/base/scnrm2/lib/ndarray.native.js | 58 +++ .../@stdlib/blas/base/scnrm2/lib/scnrm2.js | 4 +- .../blas/base/scnrm2/lib/scnrm2.native.js | 54 ++ .../@stdlib/blas/base/scnrm2/manifest.json | 463 ++++++++++++++++++ .../@stdlib/blas/base/scnrm2/package.json | 3 + .../@stdlib/blas/base/scnrm2/src/Makefile | 70 +++ .../@stdlib/blas/base/scnrm2/src/addon.c | 45 ++ .../@stdlib/blas/base/scnrm2/src/scnrm2.c | 130 +++++ .../@stdlib/blas/base/scnrm2/src/scnrm2.f | 156 ++++++ .../blas/base/scnrm2/src/scnrm2_cblas.c | 32 ++ .../@stdlib/blas/base/scnrm2/src/scnrm2_f.c | 35 ++ .../@stdlib/blas/base/scnrm2/src/scnrm2sub.f | 47 ++ .../blas/base/scnrm2/test/test.native.js | 82 ++++ .../base/scnrm2/test/test.ndarray.native.js | 221 +++++++++ .../base/scnrm2/test/test.scnrm2.native.js | 224 +++++++++ 32 files changed, 3258 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/include/stdlib/blas/base/scnrm2.h create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/include/stdlib/blas/base/scnrm2_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/include/stdlib/blas/base/scnrm2_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/lib/scnrm2.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/scnrm2.c create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/scnrm2.f create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/scnrm2_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/scnrm2_f.c create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/src/scnrm2sub.f create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/test/test.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.native.js diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md index 5c0614f4dcb2..e460e528629f 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/README.md @@ -147,6 +147,101 @@ console.log( norm ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/scnrm2.h" +``` + +#### c_scnrm2( N, \*CX, strideX ) + +Computes the L2-norm of a complex single-precision floating-point vector. + +```c +const float cx[] = { 0.3f, 0.1f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.2f }; + +float norm = c_scnrm2( 4, (void *)cx, 1 ); +// returns 0.8 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **CX**: `[inout] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. + +```c +float c_scnrm2( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/scnrm2.h" +#include + +int main( void ) { + // Create a strided array of interleaved real and imaginary components: + float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify stride length: + const int strideX = 1; + + // Compute the L2-norm: + c_scnrm2( N, (void *)cx, strideX ); + + // Print the result: + printf( "L2-norm: %lf\n", norm ); +} +``` + +
+ + + +
+ + +