diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/README.md b/lib/node_modules/@stdlib/blas/base/dzasum/README.md new file mode 100644 index 000000000000..135590fee4f0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/README.md @@ -0,0 +1,205 @@ + + +# dzasum + +> Compute the sum of the [absolute values][@stdlib/blas/base/dcab1] of each element in a double-precision [complex][@stdlib/complex/float64/ctor] floating-point vector. + +
+ +dzasum is defined as + + + +```math +\|\mathbf{x}\|_1 = \sum_{i=0}^{n-1} \left( |a_i| + |b_i| \right) +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var dzasum = require( '@stdlib/blas/base/dzasum' ); +``` + +#### dzasum( N, x, stride ) + +Compute the sum of the [absolute values][@stdlib/blas/base/dcab1] of each element in a double-precision [complex][@stdlib/complex/float64/ctor] floating-point vector. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var sum = dzasum( x.length, x, 1 ); +// returns 19.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Complex128Array`][complex128array]. +- **stride**: index increment. + +The `N` and `stride` parameters determine which elements in `x` are used to compute the sum. For example, to sum every other value, + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var sum = dzasum( 2, x, 2 ); +// 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 Complex128Array = require( '@stdlib/array/complex128' ); + +// Initial array... +var x0 = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ); + +// Create an offset view... +var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Sum every other value... +var sum = dzasum( 2, x1, 2 ); +// returns 22.0 +``` + +If `N` is less than or equal to `0`, the function returns `0`. + +#### dzasum.ndarray( N, x, stride, offset ) + +Compute the sum of the [absolute values][@stdlib/blas/base/dcab1] of each element in a double-precision [complex][@stdlib/complex/float64/ctor] floating-point vector using alternative indexing semantics. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var sum = dzasum.ndarray( x.length, x, 1, 0 ); +// returns 19.0 +``` + +The function has the following additional parameters: + +- **offset**: 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 sum the last three elements, + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ); + +var sum = dzasum.ndarray( 3, x, 1, x.length-3 ); +// returns 33.0 + +// Using a negative stride to sum from the last element: +sum = dzasum.ndarray( 3, x, -1, x.length-1 ); +// returns 33.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, the sum is `0`. +- `dzasum()` corresponds to the [BLAS][blas] level 1 function dzasum. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var dzasum = require( '@stdlib/blas/base/dzasum' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +// Generate random input arrays: +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var out = dzasum( x.length, x, 1 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.js new file mode 100644 index 000000000000..8cee6bfd8a5c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var dzasum = require( './../lib/dzasum.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + + x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dzasum( x.length, x, 1 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + 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/dzasum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..5fd95fe79ec7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var dzasum = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + + x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dzasum( x.length, x, 1, 0 ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dzasum/docs/repl.txt new file mode 100644 index 000000000000..d7a062f681a6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/docs/repl.txt @@ -0,0 +1,90 @@ + +{{alias}}( N, x, stride ) + Compute the sum of the absolute values of each element in a + double-precision complex floating-point vector + + The `N` and `stride` parameters determine which elements in `x` are used + to compute the sum. + + 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 `0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex128Array + Input array. + + stride: integer + Index increment. + + Returns + ------- + sum: number + Sum of absolute values. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0 ] ); + > var s = {{alias}}( x.length, x, 1 ) + 15.0 + + // Sum every other value: + > s = {{alias}}( 2, x, 2 ) + 7.0 + + // Use view offset; e.g., starting at 2nd element: + > var x0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ); + > var x1 = new {{alias:@stdlib/array/complex128}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > s = {{alias}}( 2, x1, 2 ) + 22.0 + + +{{alias}}.ndarray( N, x, stride, offset ) + Compute the sum of the absolute values of each element in a + double-precision complex floating-point vector using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex128Array + Input array. + + stride: integer + Index increment. + + offset: integer + Starting index. + + Returns + ------- + sum: number + Sum of absolute values. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + > var s = {{alias}}.ndarray( x.length, x, 1, 0 ) + 19.0 + + // Sum the last three elements: + > x = new {{alias:@stdlib/array/complex128}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ); + > s = {{alias}}.ndarray( 3, x, -1, x.length-1 ) + 33.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dzasum/docs/types/index.d.ts new file mode 100644 index 000000000000..af30dd68a8ca --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex128Array } from '@stdlib/types/array'; + +/** +* Interface describing `dzasum`. +*/ +interface Routine { + /** + * Compute the sum of the absolute values of each element in a double-precision complex floating-point vector. + * + * @param N - number of indexed elements + * @param x - input array + * @param stride - stride length + * @returns sum of absolute values + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + * + * var sum = dzasum( x.length, x, 1 ); + * // returns 19.0 + */ + ( N: number, x: Complex128Array, stride: number ): number; + + /** + * Computes the sum of the absolute values using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param stride - stride length + * @param offset - starting index + * @returns sum of absolute values + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + * + * var z = dzasum.ndarray( x.length, x, 1, 0 ); + * // returns 19.0 + */ + ndarray( N: number, x: Complex128Array, stride: number, offset: number ): number; +} + +/** +* Compute the sum of the absolute values of each element in a double-precision complex floating-point vector. +* +* @param N - number of indexed elements +* @param x - input array +* @param stride - stride length +* @returns sum of absolute values +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var sum = dzasum( x.length, x, 1 ); +* // returns 19.0 +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var z = dzasum.ndarray( x.length, x, 1, 0 ); +* // returns 19.0 +*/ +declare var dzasum: Routine; + + +// EXPORTS // + +export = dzasum; diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/dzasum/docs/types/test.ts new file mode 100644 index 000000000000..16f905048756 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/docs/types/test.ts @@ -0,0 +1,158 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import Complex128Array = require( '@stdlib/array/complex128' ); +import dzasum = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Complex128Array( 10 ); + + dzasum( x.length, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + dzasum( '10', x, 1 ); // $ExpectError + dzasum( true, x, 1 ); // $ExpectError + dzasum( false, x, 1 ); // $ExpectError + dzasum( null, x, 1 ); // $ExpectError + dzasum( undefined, x, 1 ); // $ExpectError + dzasum( [], x, 1 ); // $ExpectError + dzasum( {}, x, 1 ); // $ExpectError + dzasum( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + dzasum( x.length, 10, 1 ); // $ExpectError + dzasum( x.length, '10', 1 ); // $ExpectError + dzasum( x.length, true, 1 ); // $ExpectError + dzasum( x.length, false, 1 ); // $ExpectError + dzasum( x.length, null, 1 ); // $ExpectError + dzasum( x.length, undefined, 1 ); // $ExpectError + dzasum( x.length, [], 1 ); // $ExpectError + dzasum( x.length, {}, 1 ); // $ExpectError + dzasum( x.length, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + dzasum( x.length, x, '10' ); // $ExpectError + dzasum( x.length, x, true ); // $ExpectError + dzasum( x.length, x, false ); // $ExpectError + dzasum( x.length, x, null ); // $ExpectError + dzasum( x.length, x, undefined ); // $ExpectError + dzasum( x.length, x, [] ); // $ExpectError + dzasum( x.length, x, {} ); // $ExpectError + dzasum( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + + dzasum(); // $ExpectError + dzasum( x.length ); // $ExpectError + dzasum( x.length, x ); // $ExpectError + dzasum( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Complex128Array( 10 ); + + dzasum.ndarray( x.length, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + dzasum.ndarray( '10', x, 1, 0 ); // $ExpectError + dzasum.ndarray( true, x, 1, 0 ); // $ExpectError + dzasum.ndarray( false, x, 1, 0 ); // $ExpectError + dzasum.ndarray( null, x, 1, 0 ); // $ExpectError + dzasum.ndarray( undefined, x, 1, 0 ); // $ExpectError + dzasum.ndarray( [], x, 1, 0 ); // $ExpectError + dzasum.ndarray( {}, x, 1, 0 ); // $ExpectError + dzasum.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + dzasum.ndarray( x.length, 10, 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, '10', 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, true, 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, false, 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, null, 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, [], 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, {}, 1, 0 ); // $ExpectError + dzasum.ndarray( x.length, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + dzasum.ndarray( x.length, x, '10', 0 ); // $ExpectError + dzasum.ndarray( x.length, x, true, 0 ); // $ExpectError + dzasum.ndarray( x.length, x, false, 0 ); // $ExpectError + dzasum.ndarray( x.length, x, null, 0 ); // $ExpectError + dzasum.ndarray( x.length, x, undefined, 0 ); // $ExpectError + dzasum.ndarray( x.length, x, [], 0 ); // $ExpectError + dzasum.ndarray( x.length, x, {}, 0 ); // $ExpectError + dzasum.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + dzasum.ndarray( x.length, x, 1, '10' ); // $ExpectError + dzasum.ndarray( x.length, x, 1, true ); // $ExpectError + dzasum.ndarray( x.length, x, 1, false ); // $ExpectError + dzasum.ndarray( x.length, x, 1, null ); // $ExpectError + dzasum.ndarray( x.length, x, 1, undefined ); // $ExpectError + dzasum.ndarray( x.length, x, 1, [] ); // $ExpectError + dzasum.ndarray( x.length, x, 1, {} ); // $ExpectError + dzasum.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + + dzasum.ndarray(); // $ExpectError + dzasum.ndarray( x.length ); // $ExpectError + dzasum.ndarray( x.length, x ); // $ExpectError + dzasum.ndarray( x.length, x, 1 ); // $ExpectError + dzasum.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/examples/index.js b/lib/node_modules/@stdlib/blas/base/dzasum/examples/index.js new file mode 100644 index 000000000000..55e808dac0f2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var dzasum = require( '@stdlib/blas/base/dzasum' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +// Generate random input arrays: +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var out = dzasum( x.length, x, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/lib/dzasum.js b/lib/node_modules/@stdlib/blas/base/dzasum/lib/dzasum.js new file mode 100644 index 000000000000..f7be49fde4ce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/lib/dzasum.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the sum of the absolute values of each element in a double-precision complex floating-point vector. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64Array} x - input array +* @param {integer} stride - `x` stride length +* @returns {number} sum +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var sum = dzasum( x.length, x, 1 ); +* // returns 19.0 +*/ +function dzasum( N, x, stride ) { + var ox = stride2offset( N, stride ); + return ndarray( N, x, stride, ox ); +} + + +// EXPORTS // + +module.exports = dzasum; diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/lib/index.js b/lib/node_modules/@stdlib/blas/base/dzasum/lib/index.js new file mode 100644 index 000000000000..44a78a24abea --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/lib/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* BLAS level 1 routine to compute the sum of absolute values of each element in a double-precision complex floating-point vector. +* +* @module @stdlib/blas/base/dzasum +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var dzasum = require( '@stdlib/blas/base/dzasum' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var sum = dzasum( x.length, x, 1 ); +* // returns 19.0 +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var dzasum = require( '@stdlib/blas/base/dzasum' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var sum = dzasum.ndarray( x.length, x, 1, 0 ); +* // returns 19.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 dzasum; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dzasum = main; +} else { + dzasum = tmp; +} + + +// EXPORTS // + +module.exports = dzasum; + +// exports: { "ndarray": "dzasum.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/lib/main.js b/lib/node_modules/@stdlib/blas/base/dzasum/lib/main.js new file mode 100644 index 000000000000..02691681c914 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dzasum = require( './dzasum.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dzasum, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dzasum; diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/dzasum/lib/ndarray.js new file mode 100644 index 000000000000..e59053675ede --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/lib/ndarray.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dcabs1 = require( '@stdlib/blas/base/dcabs1' ); + + +// MAIN // + +/** +* Computes the sum of the absolute values of each element in a double-precision complex floating-point vector. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64Array} x - input array +* @param {integer} stride - `x` stride length +* @param {NonNegativeInteger} offset - starting index for `x` +* @returns {number} sum +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var sum = dzasum( x.length, x, 1, 0 ); +* // returns 19.0 +*/ +function dzasum( N, x, stride, offset ) { + var sum; + var ix; + var i; + + sum = 0.0; + if ( N <= 0 ) { + return sum; + } + ix = offset; + for ( i = 0; i < N; i++ ) { + sum += dcabs1( x.get( ix ) ); + ix += stride; + } + return sum; +} + + +// EXPORTS // + +module.exports = dzasum; diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/package.json b/lib/node_modules/@stdlib/blas/base/dzasum/package.json new file mode 100644 index 000000000000..693df0d5e522 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/package.json @@ -0,0 +1,83 @@ +{ + "name": "@stdlib/blas/base/dzasum", + "version": "0.0.0", + "description": "Compute the sum of the absolute values of each element in a double-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", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "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", + "dcabs1", + "absolute", + "value", + "sum", + "l1norm", + "norm", + "taxicab", + "manhattan", + "vector", + "array", + "ndarray", + "double", + "complex128", + "complex128array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/test/test.dzasum.js b/lib/node_modules/@stdlib/blas/base/dzasum/test/test.dzasum.js new file mode 100644 index 000000000000..181c7a728d82 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/test/test.dzasum.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var dzasum = require( './../lib/dzasum.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dzasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( dzasum.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the sum of absolute values', function test( t ) { + var x; + var y; + + x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + y = dzasum( x.length, x, 1 ); + + t.strictEqual( y, 21.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var x; + var y; + var N; + + x = new Complex128Array([ + 1.0, // 1 + -2.0, // 1 + 3.0, + -4.0, + 5.0, // 2 + -6.0 // 2 + ]); + N = 2; + + y = dzasum( N, x, 2 ); + + t.strictEqual( y, 14.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) { + var x; + var y; + + x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + y = dzasum( 0, x, 1 ); + + t.strictEqual( y, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var x; + var y; + var N; + + x = new Complex128Array([ + 1.0, // 2 + -2.0, // 2 + 3.0, + -4.0, + 5.0, // 1 + -6.0 // 1 + ]); + N = 2; + + y = dzasum( N, x, -2 ); + + t.strictEqual( y, 14.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var y; + var N; + + // Initial array... + x0 = new Complex128Array([ + 1.0, + -2.0, + 3.0, // 1 + -4.0, // 1 + 5.0, // 2 + -6.0 // 2 + ]); + + // Create an offset view... + x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + N = 2; + y = dzasum( N, x1, 1 ); + + t.strictEqual( y, 18.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/test/test.js b/lib/node_modules/@stdlib/blas/base/dzasum/test/test.js new file mode 100644 index 000000000000..c7c4ac04005a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dzasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dzasum, '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 dzasum.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 dzasum = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dzasum, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dzasum; + var main; + + main = require( './../lib/dzasum.js' ); + + dzasum = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dzasum, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/dzasum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dzasum/test/test.ndarray.js new file mode 100644 index 000000000000..ac1ca0fa4b91 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dzasum/test/test.ndarray.js @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var dzasum = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dzasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( dzasum.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the sum of absolute values', function test( t ) { + var x; + var y; + + x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + y = dzasum( x.length, x, 1, 0 ); + + t.strictEqual( y, 21.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var x; + var y; + var N; + + x = new Complex128Array([ + 1.0, // 1 + -2.0, // 1 + 3.0, + -4.0, + 5.0, // 2 + -6.0 // 2 + ]); + N = 2; + + y = dzasum( N, x, 2, 0 ); + + t.strictEqual( y, 14.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var x; + var y; + var N; + + x = new Complex128Array([ + 1.0, + -2.0, + 3.0, // 1 + -4.0, // 1 + 5.0, // 2 + -6.0 // 2 + ]); + N = 2; + + y = dzasum( N, x, 1, 1 ); + + t.strictEqual( y, 18.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) { + var x; + var y; + + x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + + y = dzasum( -1, x, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = dzasum( 0, x, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var x; + var y; + var N; + + x = new Complex128Array([ + 1.0, // 2 + -2.0, // 2 + 3.0, + -4.0, + 5.0, // 1 + -6.0 // 1 + ]); + N = 2; + + y = dzasum( N, x, -2, x.length-1 ); + + t.strictEqual( y, 14.0, 'returns expected value' ); + t.end(); +});