Skip to content

Commit e223021

Browse files
ShabiShett07kgrytestdlib-bot
committed
feat: add strided and assign APIs to complex/float32/base/mul
PR-URL: stdlib-js#5205 Closes: stdlib-js#5203 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent f42098f commit e223021

File tree

13 files changed

+1212
-73
lines changed

13 files changed

+1212
-73
lines changed

lib/node_modules/@stdlib/complex/float32/base/mul/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,61 @@ var im = imagf( v );
5858
// returns -1.0
5959
```
6060

61+
#### mul.assign( re1, im1, re2, im2, out, strideOut, offsetOut )
62+
63+
Multiplies two single-precision complex floating-point numbers and assigns results to a provided output array.
64+
65+
```javascript
66+
var Float32Array = require( '@stdlib/array/float32' );
67+
68+
var out = new Float32Array( 2 );
69+
var v = mul.assign( 5.0, 3.0, -2.0, 1.0, out, 1, 0 );
70+
// returns <Float32Array>[ -13.0, -1.0 ]
71+
72+
var bool = ( out === v );
73+
// returns true
74+
```
75+
76+
The function supports the following parameters:
77+
78+
- **re1**: real component of the first complex number.
79+
- **im1**: imaginary component of the first complex number.
80+
- **re2**: real component of the second complex number.
81+
- **im2**: imaginary component of the second complex number.
82+
- **out**: output array.
83+
- **strideOut**: stride length for `out`.
84+
- **offsetOut**: starting index for `out`.
85+
86+
#### mul.strided( z1, sz1, oz1, z2, sz2, oz2, out, so, oo )
87+
88+
Multiplies two single-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array.
89+
90+
```javascript
91+
var Float32Array = require( '@stdlib/array/float32' );
92+
93+
var z1 = new Float32Array( [ 5.0, 3.0 ] );
94+
var z2 = new Float32Array( [ -2.0, 1.0 ] );
95+
var out = new Float32Array( 2 );
96+
97+
var v = mul.strided( z1, 1, 0, z2, 1, 0, out, 1, 0 );
98+
// returns <Float32Array>[ -13.0, -1.0 ]
99+
100+
var bool = ( out === v );
101+
// returns true
102+
```
103+
104+
The function supports the following parameters:
105+
106+
- **z1**: first complex number strided array view.
107+
- **sz1**: stride length for `z1`.
108+
- **oz1**: starting index for `z1`.
109+
- **z2**: second complex number strided array view.
110+
- **sz2**: stride length for `z2`.
111+
- **oz2**: starting index for `z2`.
112+
- **out**: output array.
113+
- **so**: stride length for `out`.
114+
- **oo**: starting index for `out`.
115+
61116
</section>
62117

63118
<!-- /.usage -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var Float32Array = require( '@stdlib/array/float32' );
27+
var pkg = require( './../package.json' ).name;
28+
var mul = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float32'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg+':assign', function benchmark( b ) {
41+
var out;
42+
var re;
43+
var im;
44+
var N;
45+
var i;
46+
var j;
47+
var k;
48+
49+
N = 100;
50+
re = uniform( N, -500.0, 500.0, options );
51+
im = uniform( N, -500.0, 500.0, options );
52+
53+
out = new Float32Array( 2 );
54+
55+
b.tic();
56+
for ( i = 0; i < b.iterations; i++ ) {
57+
j = i % N;
58+
k = ( i+1 ) % N;
59+
out = mul.assign( re[ j ], im[ j ], re[ k ], im[ k ], out, 1, 0 );
60+
if ( typeof out !== 'object' ) {
61+
b.fail( 'should return an object' );
62+
}
63+
}
64+
b.toc();
65+
if ( isnanf( out[ 0 ] ) || isnanf( out[ 1 ] ) ) {
66+
b.fail( 'should not return NaN' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var Float32Array = require( '@stdlib/array/float32' );
27+
var pkg = require( './../package.json' ).name;
28+
var mul = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float32'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg+':strided', function benchmark( b ) {
41+
var out;
42+
var z1;
43+
var z2;
44+
var N;
45+
var i;
46+
var j;
47+
48+
N = 50;
49+
z1 = uniform( N*2, -500.0, 500.0, options );
50+
z2 = uniform( N*2, -500.0, 500.0, options );
51+
52+
out = new Float32Array( 2 );
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
j = ( i % N ) * 2;
57+
out = mul.strided( z1, 1, j, z2, 1, j, out, 1, 0 );
58+
if ( typeof out !== 'object' ) {
59+
b.fail( 'should return an object' );
60+
}
61+
}
62+
b.toc();
63+
if ( isnanf( out[ 0 ] ) || isnanf( out[ 1 ] ) ) {
64+
b.fail( 'should not return NaN' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
});

lib/node_modules/@stdlib/complex/float32/base/mul/docs/repl.txt

+87
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,93 @@
2828
> var im = {{alias:@stdlib/complex/float32/imag}}( out )
2929
-1.0
3030

31+
32+
{{alias}}.assign( re1, im1, re2, im2, out, strideOut, offsetOut )
33+
Multiplies two single-precision complex floating-point numbers and assigns
34+
results to a provided output array.
35+
36+
Parameters
37+
----------
38+
re1: number
39+
Real component of the first complex number.
40+
41+
im1: number
42+
Imaginary component of the first complex number.
43+
44+
re2: number
45+
Real component of the second complex number.
46+
47+
im2: number
48+
Imaginary component of the second complex number.
49+
50+
out: ArrayLikeObject
51+
Output array.
52+
53+
strideOut: integer
54+
Stride length.
55+
56+
offsetOut: integer
57+
Starting index.
58+
59+
Returns
60+
-------
61+
out: ArrayLikeObject
62+
Output array.
63+
64+
Examples
65+
--------
66+
> var out = new {{alias:@stdlib/array/float32}}( 2 );
67+
> {{alias}}.assign( 5.0, 3.0, -2.0, 1.0, out, 1, 0 )
68+
<Float32Array>[ -13.0, -1.0 ]
69+
70+
71+
{{alias}}.strided( z1, sz1, oz1, z2, sz2, oz2, out, so, oo )
72+
Multiplies two single-precision complex floating-point numbers stored in
73+
real-valued strided array views and assigns results to a provided strided
74+
output array.
75+
76+
Parameters
77+
----------
78+
z1: ArrayLikeObject
79+
First complex number view.
80+
81+
sz1: integer
82+
Stride length for `z1`.
83+
84+
oz1: integer
85+
Starting index for `z1`.
86+
87+
z2: ArrayLikeObject
88+
Second complex number view.
89+
90+
sz2: integer
91+
Stride length for `z2`.
92+
93+
oz2: integer
94+
Starting index for `z2`.
95+
96+
out: ArrayLikeObject
97+
Output array.
98+
99+
so: integer
100+
Stride length for `out`.
101+
102+
oo: integer
103+
Starting index for `out`.
104+
105+
Returns
106+
-------
107+
out: ArrayLikeObject
108+
Output array.
109+
110+
Examples
111+
--------
112+
> var z1 = new {{alias:@stdlib/array/float32}}( [ 5.0, 3.0 ] );
113+
> var z2 = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0 ] );
114+
> var out = new {{alias:@stdlib/array/float32}}( 2 );
115+
> {{alias}}.strided( z1, 1, 0, z2, 1, 0, out, 1, 0 )
116+
<Float32Array>[ -13.0, -1.0 ]
117+
31118
See Also
32119
--------
33120

0 commit comments

Comments
 (0)