Skip to content

Commit 76aac9c

Browse files
feat: add blas/ext/base/ndarray/zwxdy
PR-URL: #16430 Reviewed-by: Athan Reines <kgryte@gmail.com> Closes: stdlib-js/metr-issue-tracker#1106 Ref: #14404
1 parent 87ab9cf commit 76aac9c

10 files changed

Lines changed: 968 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# zwxdy
22+
23+
> Divide elements of a one-dimensional double-precision complex floating-point ndarray by the corresponding elements of a second one-dimensional double-precision complex floating-point ndarray and assign the results to elements in a third one-dimensional double-precision complex floating-point ndarray.
24+
25+
<section class="intro">
26+
27+
This BLAS extension implements the operation
28+
29+
<!-- <equation class="equation" label="eq:wxdy" align="center" raw="\mathbf{w} = \mathbf{x} \oslash \mathbf{y}" alt="Equation for wxdy operation."> -->
30+
31+
```math
32+
\mathbf{w} = \mathbf{x} \oslash \mathbf{y}
33+
```
34+
35+
<!-- </equation> -->
36+
37+
where `⊘` denotes the [Hadamard division][hadamard-division].
38+
39+
</section>
40+
41+
<!-- /.intro -->
42+
43+
<section class="usage">
44+
45+
## Usage
46+
47+
```javascript
48+
var zwxdy = require( '@stdlib/blas/ext/base/ndarray/zwxdy' );
49+
```
50+
51+
#### zwxdy( arrays )
52+
53+
Divides elements of a one-dimensional double-precision complex floating-point ndarray by the corresponding elements of a second one-dimensional double-precision complex floating-point ndarray and assigns the results to elements in a third one-dimensional double-precision complex floating-point ndarray.
54+
55+
```javascript
56+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
57+
58+
var x = new Complex128Vector( [ 4.0, 6.0, 12.0, 8.0, 16.0, 8.0 ] );
59+
var y = new Complex128Vector( [ 1.0, 1.0, 2.0, 2.0, 4.0, 4.0 ] );
60+
var w = new Complex128Vector( 3 );
61+
62+
zwxdy( [ x, y, w ] );
63+
// w => <ndarray>[ <Complex128>[ 5.0, 1.0 ], <Complex128>[ 5.0, -1.0 ], <Complex128>[ 3.0, -1.0 ] ]
64+
```
65+
66+
The function has the following parameters:
67+
68+
- **arrays**: array-like object containing the following ndarrays:
69+
70+
- first one-dimensional input ndarray.
71+
- second one-dimensional input ndarray.
72+
- a one-dimensional output ndarray.
73+
74+
</section>
75+
76+
<!-- /.usage -->
77+
78+
<section class="notes">
79+
80+
</section>
81+
82+
<!-- /.notes -->
83+
84+
<section class="examples">
85+
86+
## Examples
87+
88+
<!-- eslint no-undef: "error" -->
89+
90+
```javascript
91+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
92+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
93+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
94+
var zwxdy = require( '@stdlib/blas/ext/base/ndarray/zwxdy' );
95+
96+
var opts = {
97+
'dtype': 'float64'
98+
};
99+
100+
var x = new Complex128Vector( discreteUniform( 20, -100, 100, opts ) );
101+
console.log( ndarray2array( x ) );
102+
103+
var y = new Complex128Vector( discreteUniform( 20, 1, 100, opts ) );
104+
console.log( ndarray2array( y ) );
105+
106+
var w = new Complex128Vector( 10 );
107+
108+
zwxdy( [ x, y, w ] );
109+
console.log( ndarray2array( w ) );
110+
```
111+
112+
</section>
113+
114+
<!-- /.examples -->
115+
116+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
117+
118+
<section class="related">
119+
120+
</section>
121+
122+
<!-- /.related -->
123+
124+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
125+
126+
<section class="links">
127+
128+
[hadamard-division]: https://en.wikipedia.org/wiki/Hadamard_product_(matrices)#Analogous_operations
129+
130+
</section>
131+
132+
<!-- /.links -->
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
27+
var format = require( '@stdlib/string/format' );
28+
var pkg = require( './../package.json' ).name;
29+
var zwxdy = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - ndarray length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var xbuf;
43+
var ybuf;
44+
var x;
45+
var y;
46+
var w;
47+
48+
xbuf = uniform( len*2, -100.0, 100.0, {
49+
'dtype': 'float64'
50+
});
51+
ybuf = uniform( len*2, 1.0, 100.0, {
52+
'dtype': 'float64'
53+
});
54+
x = new Complex128Vector( xbuf.buffer );
55+
y = new Complex128Vector( ybuf.buffer );
56+
w = new Complex128Vector( len );
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var out;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
out = zwxdy( [ x, y, w ] );
72+
if ( typeof out !== 'object' ) {
73+
b.fail( 'should return an ndarray' );
74+
}
75+
}
76+
b.toc();
77+
if ( typeof out !== 'object' ) {
78+
b.fail( 'should return an ndarray' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
}
83+
}
84+
85+
86+
// MAIN //
87+
88+
/**
89+
* Main execution sequence.
90+
*
91+
* @private
92+
*/
93+
function main() {
94+
var len;
95+
var min;
96+
var max;
97+
var f;
98+
var i;
99+
100+
min = 1; // 10^min
101+
max = 6; // 10^max
102+
103+
for ( i = min; i <= max; i++ ) {
104+
len = pow( 10, i );
105+
f = createBenchmark( len );
106+
bench( format( '%s:len=%d', pkg, len ), f );
107+
}
108+
}
109+
110+
main();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
{{alias}}( arrays )
3+
Divides elements of a one-dimensional double-precision complex floating-
4+
point ndarray by the corresponding elements of a second one-dimensional
5+
double-precision complex floating-point ndarray and assigns the results to
6+
elements in a third one-dimensional double-precision complex floating-point
7+
ndarray.
8+
9+
Parameters
10+
----------
11+
arrays: ArrayLikeObject<ndarray>
12+
Array-like object containing the following ndarrays:
13+
14+
- first one-dimensional input ndarray.
15+
- second one-dimensional input ndarray.
16+
- a one-dimensional output ndarray.
17+
18+
Returns
19+
-------
20+
out: ndarray
21+
Output ndarray.
22+
23+
Examples
24+
--------
25+
> var xbuf = [ 4.0, 6.0, 12.0, 8.0 ];
26+
> var x = new {{alias:@stdlib/ndarray/vector/complex128}}( xbuf );
27+
> var ybuf = [ 1.0, 1.0, 2.0, 2.0 ];
28+
> var y = new {{alias:@stdlib/ndarray/vector/complex128}}( ybuf );
29+
> var w = new {{alias:@stdlib/ndarray/vector/complex128}}( 2 );
30+
> {{alias}}( [ x, y, w ] )
31+
<ndarray>[ <Complex128>[ 5.0, 1.0 ], <Complex128>[ 5.0, -1.0 ] ]
32+
33+
See Also
34+
--------
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { complex128ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Divides elements of a one-dimensional double-precision complex floating-point ndarray by the corresponding elements of a second one-dimensional double-precision complex floating-point ndarray and assigns the results to elements in a third one-dimensional double-precision complex floating-point ndarray.
27+
*
28+
* ## Notes
29+
*
30+
* - The function expects the following ndarrays:
31+
*
32+
* - first one-dimensional input ndarray.
33+
* - second one-dimensional input ndarray.
34+
* - a one-dimensional output ndarray.
35+
*
36+
* @param arrays - array-like object containing ndarrays
37+
* @returns output ndarray
38+
*
39+
* @example
40+
* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
41+
*
42+
* var x = new Complex128Vector( [ 4.0, 6.0, 12.0, 8.0, 16.0, 8.0 ] );
43+
* var y = new Complex128Vector( [ 1.0, 1.0, 2.0, 2.0, 4.0, 4.0 ] );
44+
* var w = new Complex128Vector( 3 );
45+
*
46+
* var out = zwxdy( [ x, y, w ] );
47+
* // returns <ndarray>[ <Complex128>[ 5.0, 1.0 ], <Complex128>[ 5.0, -1.0 ], <Complex128>[ 3.0, -1.0 ] ]
48+
*/
49+
declare function zwxdy( arrays: [ complex128ndarray, complex128ndarray, complex128ndarray ] ): complex128ndarray;
50+
51+
52+
// EXPORTS //
53+
54+
export = zwxdy;

0 commit comments

Comments
 (0)