Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cbead2a
feat: add blas/base/dzasum
gururaj1512 Jan 11, 2025
9ef0e0e
add repl.txt
gururaj1512 Jan 11, 2025
cb2094f
fix: copyright years
gururaj1512 Jan 11, 2025
6cafe5a
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot Apr 27, 2025
998b584
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot Jul 7, 2025
114b390
bench: update variable naming
ShabiShett07 Jul 7, 2025
9860165
docs: update variable naming and jsdoc
ShabiShett07 Jul 7, 2025
10ba7b3
chore: add ndarray example
ShabiShett07 Jul 7, 2025
2a604f9
docs: update jsdoc and variable naming
ShabiShett07 Jul 7, 2025
5a3cb83
chore: update markdown
ShabiShett07 Jul 7, 2025
88559fb
fix: linting in package.json
ShabiShett07 Jul 7, 2025
1a3dc71
chore: update markdown example
ShabiShett07 Jul 7, 2025
f4c25fe
chore: convert tabs to spaces
ShabiShett07 Jul 8, 2025
3f9142b
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot Nov 19, 2025
12df660
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot Dec 27, 2025
db49dbd
Merge remote-tracking branch 'origin/develop' into blas-dzasum
MeKaustubh07 May 26, 2026
c3291eb
fix: add C API placeholder and refactor readme according to standard …
MeKaustubh07 May 26, 2026
1305408
chore: fix description in package.json
MeKaustubh07 May 26, 2026
64cb6e5
chore: update the JS test implementation
MeKaustubh07 May 26, 2026
840afdc
chore: update and cleanup for lib files
MeKaustubh07 May 26, 2026
0ff8764
chore: update examples
MeKaustubh07 May 26, 2026
874d1e6
chore: update bench
MeKaustubh07 May 26, 2026
dc49006
chore: update documentation
MeKaustubh07 May 26, 2026
c19837b
chore: final docs changes
MeKaustubh07 May 26, 2026
d53c798
Apply suggestions from code review
kgryte May 27, 2026
469533d
Apply suggestions from code review
kgryte May 27, 2026
c361802
Apply suggestions from code review
kgryte May 27, 2026
46ee2fd
Apply suggestions from code review
kgryte May 27, 2026
877619b
Apply suggestions from code review
kgryte May 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions lib/node_modules/@stdlib/blas/base/dzasum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# dzasum

> Compute the sum of the absolute values of the real and imaginary components of a double-precision complex floating-point strided array.

<section class="usage">

## Usage

```javascript
var dzasum = require( '@stdlib/blas/base/dzasum' );
```

#### dzasum( N, x, strideX )

Computes the sum of the absolute values of the real and imaginary components of a double-precision complex floating-point strided array.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] );

var out = dzasum( 4, x, 1 );
// returns ~1.6
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
- **strideX**: stride length.

The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to traverse 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 out = 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 ] );

// Create an offset view:
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Compute the sum of absolute values:
var out = dzasum( 2, x1, 1 );
// returns 18.0
```

#### dzasum.ndarray( N, x, strideX, offsetX )

Computes the sum of the absolute values of the real and imaginary components of a double-precision complex floating-point strided array using alternative indexing semantics.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] );

var out = dzasum.ndarray( 4, x, 1, 0 );
// returns ~1.6
```

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 element

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );

var out = dzasum.ndarray( 2, x, 1, 1 );
// returns 18.0
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return `0.0`.
- `dzasum()` corresponds to the [BLAS][blas] level 1 function [`dzasum`][dzasum].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var dzasum = require( '@stdlib/blas/base/dzasum' );

function rand() {
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}

var x = filledarrayBy( 10, 'complex128', rand );
console.log( x.toString() );

// Compute the sum of the absolute values of real and imaginary components:
var out = dzasum( x.length, x, 1 );
console.log( out );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
```

#### TODO

TODO.

```c
TODO
```

TODO

```c
TODO
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[blas]: http://www.netlib.org/blas

[dzasum]: https://www.netlib.org/lapack/explore-html/d5/d72/group__asum_ga89c76eef329f84ba9ed106b34fedab16.html#ga89c76eef329f84ba9ed106b34fedab16

[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
104 changes: 104 additions & 0 deletions lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dzasum = require( './../lib/dzasum.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Create a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = new Complex128Array( uniform( len*2, -10.0, 10.0, options ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = dzasum( x.length, x, 1 );
if ( isnan( out ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out ) ) {
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( format( '%s:len=%d', pkg, len ), f );
}
}

main();
Loading