-
-
Notifications
You must be signed in to change notification settings - Fork 860
feat: add blas/base/zdotc
#6847
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
Open
ShabiShett07
wants to merge
38
commits into
stdlib-js:develop
Choose a base branch
from
ShabiShett07:feature/zdotc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,929
−0
Open
Changes from 21 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
5de6a6c
feat: add blas/base/zdotc
ShabiShett07 ad235af
chore: update test cases
ShabiShett07 ed6aa67
chore: update benchmark
ShabiShett07 7e96ed3
remove: unused package
ShabiShett07 c476dcd
chore: update benchmark
ShabiShett07 75faea6
chore: update benchmark
ShabiShett07 d311880
chore: update benchmark
ShabiShett07 47d0d11
chore: minor clean-up
ShabiShett07 3b21b66
Merge remote-tracking branch 'upstream/develop' into feature/zdotc
stdlib-bot d4a3658
chore: minor clean-up
ShabiShett07 60948ab
chore: minor clean-up
ShabiShett07 78eaf99
chore: minor clean-up
ShabiShett07 ea01d64
chore: minor clean-up
ShabiShett07 9224753
chore: minor clean-up
ShabiShett07 ad201c7
chore: add test cases
ShabiShett07 4c7f204
chore: add example
ShabiShett07 74acecc
chore: add test cases
ShabiShett07 074a514
chore: minor clean-up
ShabiShett07 b4af45e
chore: minor clean-up
ShabiShett07 7db92dc
chore: minor clean-up
ShabiShett07 89ca94f
chore: minor clean-up
ShabiShett07 7ab8988
chore: update repl
ShabiShett07 6bdafd4
chore: add decimals
ShabiShett07 e6f7fcb
chore: minor clean-up
ShabiShett07 28f46bf
chore: minor clean-up
ShabiShett07 0c6bd31
chore: minor clean-up
ShabiShett07 90a8006
chore: minor clean-up
ShabiShett07 58795df
chore: minor clean-up
ShabiShett07 6643700
chore: minor clean-up
ShabiShett07 150acca
chore: minor clean-up
ShabiShett07 4b77044
chore: minor clean-up
ShabiShett07 d44a1de
chore: minor clean-up
ShabiShett07 e57c2f3
chore: clean-up
ShabiShett07 e11fbab
Merge remote-tracking branch 'upstream/develop' into feature/zdotc
stdlib-bot 0baf6ee
chore: clean-up
ShabiShett07 846ac66
chore: clean-up
ShabiShett07 a4cb922
chore: minor clean-up
ShabiShett07 ab59952
chore: clean-up
ShabiShett07 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,182 @@ | ||
<!-- | ||
|
||
@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. | ||
|
||
--> | ||
|
||
# zdotc | ||
|
||
> Calculate the dot product of two double-precision complex vectors. | ||
|
||
<section class="intro"> | ||
|
||
The [dot product][dot-product] (or scalar product) is defined as | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var zdotc = require( '@stdlib/blas/base/zdotc' ); | ||
``` | ||
|
||
#### zdotc( N, x, strideX, y, strideY ) | ||
|
||
Calculates the dot product `x^H * y` of complex vectors `x` and `y`. | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float32/ctor' ); | ||
|
||
var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); | ||
var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); | ||
|
||
var z = zdotc( x.length, x, 1, y, 1 ); | ||
// returns <Complex128>[ 54.0, -80.0 ] | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **N**: number of indexed elements. | ||
- **x**: input [`Complex128Array`][@stdlib/array/complex128]. | ||
- **strideX**: index increment for `x`. | ||
- **y**: input [`Complex128Array`][@stdlib/array/complex128]. | ||
- **strideY**: index increment for `y`. | ||
|
||
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order, | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float32/ctor' ); | ||
|
||
var x = new Complex128Array( [ -1.0, -9.0, 2.0, -8.0 ] ); | ||
var y = new Complex128Array( [ -5.0, 1.0, -6.0, 7.0 ] ); | ||
|
||
var z = zdotc( x.length, x, 1, y, -1 ); | ||
// returns <Complex128>[ -75.0, -99.0 ] | ||
``` | ||
|
||
#### zdotc.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) | ||
|
||
Calculates the dot product `x^H * y` of `x` and `y` using alternative indexing semantics. | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float32/ctor' ); | ||
|
||
var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); | ||
var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); | ||
|
||
var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); | ||
// returns <Complex128>[ 54.0, -80.0 ] | ||
``` | ||
|
||
The function has the following additional parameters: | ||
|
||
- **offsetX**: starting index for `x`. | ||
- **offsetY**: starting index for `y`. | ||
|
||
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 2 elements in `y` in reverse order | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float32/ctor' ); | ||
|
||
var x = new Complex128Array( [ 7.0, -8.0, -1.0, -9.0 ] ); | ||
var y = new Complex128Array( [ 6.0, -6.0, -9.0, 5.0 ] ); | ||
|
||
var z = zdotc.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); | ||
// returns <Complex128>[ -55.0, 23.0 ] | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- If `N <= 0`, both functions return complex128 with real and imagnary as `0.0`. | ||
- `zdotc()` corresponds to the [BLAS][blas] level 1 function [`zdotc`][zdotc]. | ||
|
||
</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/float32/ctor' ); | ||
var zdotc = require( '@stdlib/blas/base/zdotc' ); | ||
|
||
function rand() { | ||
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( 1, 5 ) ); | ||
} | ||
|
||
var x = filledarrayBy( 10, 'complex128', rand ); | ||
console.log( x.toString() ); | ||
|
||
var y = filledarrayBy( 10, 'complex128', rand ); | ||
console.log( y.toString() ); | ||
|
||
// Perform dot product of x and y | ||
var z = zdotc.ndarray( x.length, x, 1, 0, y, 1, 0 ); | ||
console.log( z ); | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- 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"> | ||
|
||
[dot-product]: https://en.wikipedia.org/wiki/Dot_product | ||
|
||
[blas]: http://www.netlib.org/blas | ||
|
||
[zdotc]: https://www.netlib.org/lapack/explore-html-3.6.1/d2/df9/group__complex16__blas__level1_ga45b00bad9285ff50cd86e97dfb04facd.html | ||
|
||
[@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 | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
109 changes: 109 additions & 0 deletions
109
lib/node_modules/@stdlib/blas/base/zdotc/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,109 @@ | ||
/** | ||
* @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 pow = require( '@stdlib/math/base/special/pow' ); | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var real = require( '@stdlib/complex/float64/real' ); | ||
var pkg = require( './../package.json' ).name; | ||
var zdotc = require( './../lib/zdotc.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; | ||
var y; | ||
|
||
x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); | ||
y = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); | ||
|
||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = zdotc( x.length, x, 1, y, 1 ); | ||
if ( isnan( real( z ) ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( real( z ) ) ) { | ||
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(); |
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.