-
-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into de…
…velop
- Loading branch information
Showing
34 changed files
with
4,329 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,256 @@ | ||
<!-- | ||
@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. | ||
--> | ||
|
||
# zaxpy | ||
|
||
> Scale a double-precision complex floating-point vector by a double-precision complex floating-point constant and add the result to a double-precision complex floating-point vector. | ||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var zaxpy = require( '@stdlib/blas/base/zaxpy' ); | ||
``` | ||
|
||
#### zaxpy( N, za, zx, strideX, zy, strideY ) | ||
|
||
Scales values from `zx` by `za` and adds the result to `zy`. | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require('@stdlib/complex/float64/ctor'); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); | ||
var zy = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); | ||
var za = new Complex128( 2.0, 2.0 ); | ||
|
||
zaxpy( 3, za, zx, 1, zy, 1 ); | ||
|
||
var z = zy.get( 0 ); | ||
// returns <Complex128> | ||
|
||
var re = real( z ); | ||
// returns -1.0 | ||
|
||
var im = imag( z ); | ||
// returns 7.0 | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **N**: number of indexed elements. | ||
- **za**: scalar [`Complex128`][@stdlib/complex/float64/ctor] constant. | ||
- **zx**: first input [`Complex128Array`][@stdlib/array/complex128]. | ||
- **strideX**: index increment for `zx`. | ||
- **zy**: second input [`Complex128Array`][@stdlib/array/complex128]. | ||
- **strideY**: index increment for `zy`. | ||
|
||
The `N` and stride parameters determine how values from `zx` are scaled by `za` and added to `zy`. For example, to scale every other value in `zx` by `za` and add the result to every other value of `zy`, | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float64/ctor' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); | ||
var zy = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); | ||
var za = new Complex128( 2.0, 2.0 ); | ||
|
||
zaxpy( 2, za, zx, 2, zy, 2 ); | ||
|
||
var z = zy.get( 0 ); | ||
// returns <Complex128> | ||
|
||
var re = real( z ); | ||
// returns -1.0 | ||
|
||
var im = imag( z ); | ||
// returns 7.0 | ||
``` | ||
|
||
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | ||
|
||
<!-- eslint-disable stdlib/capitalized-comments --> | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float64/ctor' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
// Initial arrays... | ||
var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); | ||
var zy0 = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); | ||
|
||
// Define a scalar constant: | ||
var za = new Complex128( 2.0, 2.0 ); | ||
|
||
// Create offset views... | ||
var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var zy1 = new Complex128Array( zy0.buffer, zy0.BYTES_PER_ELEMENT*2 ); // start at 3rd element | ||
|
||
// Scales values of `zx0` by `za` starting from second index and add the result to `zy0` starting from third index... | ||
zaxpy( 2, za, zx1, 1, zy1, 1 ); | ||
|
||
var z = zy0.get( 2 ); | ||
// returns <Complex128> | ||
|
||
var re = real( z ); | ||
// returns -1.0 | ||
|
||
var im = imag( z ); | ||
// returns 15.0 | ||
``` | ||
|
||
#### zaxpy.ndarray( N, za, zx, strideX, offsetX, zy, strideY, offsetY ) | ||
|
||
Scales values from `zx` by `za` and adds the result to `zy` using alternative indexing semantics. | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float64/ctor' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); | ||
var zy = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); | ||
var za = new Complex128( 2.0, 2.0 ); | ||
|
||
zaxpy.ndarray( 3, za, zx, 1, 0, zy, 1, 0 ); | ||
|
||
var z = zy.get( 0 ); | ||
// returns <Complex128> | ||
|
||
var re = real( z ); | ||
// returns -1.0 | ||
|
||
var im = imag( z ); | ||
// returns 7.0 | ||
``` | ||
|
||
The function has the following additional parameters: | ||
|
||
- **offsetX**: starting index for `zx`. | ||
- **offsetY**: starting index for `zy`. | ||
|
||
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 scale values in the first input strided array starting from the second element and add the result to the second input array starting from the second element, | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float64/ctor' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); | ||
var zy = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); | ||
var za = new Complex128( 2.0, 2.0 ); | ||
|
||
zaxpy.ndarray( 3, za, zx, 1, 1, zy, 1, 1 ); | ||
|
||
var z = zy.get( 3 ); | ||
// returns <Complex128> | ||
|
||
var re = real( z ); | ||
// returns -1.0 | ||
|
||
var im = imag( z ); | ||
// returns 31.0 | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- If `N <= 0`, both functions return `zy` unchanged. | ||
- `zaxpy()` corresponds to the [BLAS][blas] level 1 function [`zaxpy`][zaxpy]. | ||
|
||
</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 zcopy = require( '@stdlib/blas/base/zcopy' ); | ||
var zeros = require( '@stdlib/array/zeros' ); | ||
var logEach = require( '@stdlib/console/log-each' ); | ||
var zaxpy = require( '@stdlib/blas/base/zaxpy' ); | ||
|
||
function rand() { | ||
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); | ||
} | ||
|
||
var zx = filledarrayBy( 10, 'complex128', rand ); | ||
var zy = filledarrayBy( 10, 'complex128', rand ); | ||
var zyc = zcopy( zy.length, zy, 1, zeros( zy.length, 'complex128' ), 1 ); | ||
|
||
var za = new Complex128( 2.0, 2.0 ); | ||
|
||
// Scale values from `zx` by `za` and add the result to `zy`: | ||
zaxpy( zx.length, za, zx, 1, zy, 1 ); | ||
|
||
// Print the results: | ||
logEach( '(%s)*(%s) + (%s) = %s', za, zx, zyc, zy ); | ||
``` | ||
|
||
</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"> | ||
|
||
[blas]: http://www.netlib.org/blas | ||
|
||
[zaxpy]: https://www.netlib.org/lapack/explore-html/d5/d4b/group__axpy_ga0b7bac1f4d42514074a48f14f5f9caa0.html#ga0b7bac1f4d42514074a48f14f5f9caa0 | ||
|
||
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
||
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128 | ||
|
||
[@stdlib/complex/float64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/ctor | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
115 changes: 115 additions & 0 deletions
115
lib/node_modules/@stdlib/blas/base/zaxpy/benchmark/benchmark.js
This file contains 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,115 @@ | ||
/** | ||
* @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 Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex128 = require( '@stdlib/complex/float64/ctor' ); | ||
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); | ||
var pkg = require( './../package.json' ).name; | ||
var zaxpy = require( './../lib/zaxpy.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 viewY; | ||
var za; | ||
var zx; | ||
var zy; | ||
|
||
zx = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); | ||
zy = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); | ||
|
||
viewY = reinterpret( zy, 0 ); | ||
|
||
za = new Complex128( 1.0, 0.0 ); | ||
|
||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
zaxpy( zx.length, za, zx, 1, zy, 1 ); | ||
if ( isnan( viewY[ i%(len*2) ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( viewY[ i%(len*2) ] ) ) { | ||
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.
520cf07
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
The above coverage report was generated for the changes in this push.