Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c8ed3b

Browse files
ShabiShett07kgrytestdlib-bot
authored
feat: add strided and assign APIs to complex/float32/base/add
PR-URL: #5391 Closes: #5196 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: stdlib-bot <noreply@stdlib.io>
1 parent 04b1546 commit 7c8ed3b

File tree

13 files changed

+1194
-72
lines changed

13 files changed

+1194
-72
lines changed

‎lib/node_modules/@stdlib/complex/float32/base/add/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,61 @@ var v = add( z, z );
4949
// returns <Complex64>[ -3.0, 5.0 ]
5050
```
5151

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

54109
<!-- /.usage -->
Lines changed: 70 additions & 0 deletions
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 add = 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 = add.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+
});
Lines changed: 68 additions & 0 deletions
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 add = 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 = add.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/add/docs/repl.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,93 @@
2626
> var im = {{alias:@stdlib/complex/float32/imag}}( out )
2727
6.0
2828

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /