-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add blas/base/dzasum
#4697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,680
−0
Merged
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
cbead2a
feat: add blas/base/dzasum
gururaj1512 9ef0e0e
add repl.txt
gururaj1512 cb2094f
fix: copyright years
gururaj1512 6cafe5a
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot 998b584
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot 114b390
bench: update variable naming
ShabiShett07 9860165
docs: update variable naming and jsdoc
ShabiShett07 10ba7b3
chore: add ndarray example
ShabiShett07 2a604f9
docs: update jsdoc and variable naming
ShabiShett07 5a3cb83
chore: update markdown
ShabiShett07 88559fb
fix: linting in package.json
ShabiShett07 1a3dc71
chore: update markdown example
ShabiShett07 f4c25fe
chore: convert tabs to spaces
ShabiShett07 3f9142b
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot 12df660
Merge remote-tracking branch 'upstream/develop' into blas-dzasum
stdlib-bot db49dbd
Merge remote-tracking branch 'origin/develop' into blas-dzasum
MeKaustubh07 c3291eb
fix: add C API placeholder and refactor readme according to standard …
MeKaustubh07 1305408
chore: fix description in package.json
MeKaustubh07 64cb6e5
chore: update the JS test implementation
MeKaustubh07 840afdc
chore: update and cleanup for lib files
MeKaustubh07 0ff8764
chore: update examples
MeKaustubh07 874d1e6
chore: update bench
MeKaustubh07 dc49006
chore: update documentation
MeKaustubh07 c19837b
chore: final docs changes
MeKaustubh07 d53c798
Apply suggestions from code review
kgryte 469533d
Apply suggestions from code review
kgryte c361802
Apply suggestions from code review
kgryte 46ee2fd
Apply suggestions from code review
kgryte 877619b
Apply suggestions from code review
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 vector. | ||
|
|
||
| <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 vector. | ||
|
kgryte marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```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**: index increment for `x`. | ||
|
kgryte marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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 vector using alternative indexing semantics. | ||
|
kgryte marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```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 index, | ||
|
kgryte marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```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
104
lib/node_modules/@stdlib/blas/base/dzasum/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.