Skip to content

Commit d346a88

Browse files
committed
feat: add complex/float64/base/add3
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent e4442f2 commit d346a88

File tree

35 files changed

+3669
-0
lines changed

35 files changed

+3669
-0
lines changed
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# add3
22+
23+
> Compute the sum of three double-precision complex floating-point numbers.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var add3 = require( '@stdlib/complex/float64/base/add3' );
37+
```
38+
39+
#### add3( z1, z2, z3 )
40+
41+
Computes the sum of three double-precision complex floating-point numbers.
42+
43+
```javascript
44+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
45+
46+
var z = new Complex128( -1.5, 2.5 );
47+
48+
var v = add3( z, z, z );
49+
// returns <Complex128>[ -4.5, 7.5 ]
50+
```
51+
52+
The function supports the following parameters:
53+
54+
- **z1**: first complex number.
55+
- **z2**: second complex number.
56+
- **z3**: third complex number.
57+
58+
#### add3.assign( re1, im1, re2, im2, re3, im3, out, strideOut, offsetOut )
59+
60+
Computes the sum of three double-precision complex floating-point numbers and assigns results to a provided output array.
61+
62+
```javascript
63+
var Float64Array = require( '@stdlib/array/float64' );
64+
65+
var out = new Float64Array( 2 );
66+
var v = add3.assign( 5.0, 3.0, -2.0, 1.0, 5.0, 3.0, out, 1, 0 );
67+
// returns <Float64Array>[ 8.0, 7.0 ]
68+
69+
var bool = ( out === v );
70+
// returns true
71+
```
72+
73+
The function supports the following parameters:
74+
75+
- **re1**: real component of the first complex number.
76+
- **im1**: imaginary component of the first complex number.
77+
- **re2**: real component of the second complex number.
78+
- **im2**: imaginary component of the second complex number.
79+
- **re3**: real component of the third complex number.
80+
- **im3**: imaginary component of the third complex number.
81+
- **out**: output array.
82+
- **strideOut**: stride length for `out`.
83+
- **offsetOut**: starting index for `out`.
84+
85+
#### add3.strided( z1, sz1, oz1, z2, sz2, oz2, z3, sz3, oz3, out, so, oo )
86+
87+
Computes the sum of three double-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array.
88+
89+
```javascript
90+
var Float64Array = require( '@stdlib/array/float64' );
91+
92+
var z1 = new Float64Array( [ 5.0, 3.0 ] );
93+
var z2 = new Float64Array( [ -2.0, 1.0 ] );
94+
var z3 = new Float64Array( [ 5.0, 3.0 ] );
95+
var out = new Float64Array( 2 );
96+
97+
var v = add3.strided( z1, 1, 0, z2, 1, 0, z3, 1, 0, out, 1, 0 );
98+
// returns <Float64Array>[ 8.0, 7.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+
- **z3**: third complex number strided array view.
113+
- **sz3**: stride length for `z3`.
114+
- **oz3**: starting index for `z3`.
115+
- **out**: output array.
116+
- **so**: stride length for `out`.
117+
- **oo**: starting index for `out`.
118+
119+
</section>
120+
121+
<!-- /.usage -->
122+
123+
<section class="examples">
124+
125+
## Examples
126+
127+
<!-- eslint no-undef: "error" -->
128+
129+
```javascript
130+
var Complex128Array = require( '@stdlib/array/complex128' );
131+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
132+
var logEachMap = require( '@stdlib/console/log-each-map' );
133+
var add3 = require( '@stdlib/complex/float64/base/add3' );
134+
135+
// Generate arrays of random values:
136+
var z1 = new Complex128Array( discreteUniform( 200, -50, 50 ) );
137+
var z2 = new Complex128Array( discreteUniform( 200, -50, 50 ) );
138+
var z3 = new Complex128Array( discreteUniform( 200, -50, 50 ) );
139+
140+
// Perform element-wise addition:
141+
logEachMap( '(%s) + (%s) + (%s) = %s', z1, z2, z3, add3 );
142+
```
143+
144+
</section>
145+
146+
<!-- /.examples -->
147+
148+
<!-- C interface documentation. -->
149+
150+
* * *
151+
152+
<section class="c">
153+
154+
## C APIs
155+
156+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
157+
158+
<section class="intro">
159+
160+
</section>
161+
162+
<!-- /.intro -->
163+
164+
<!-- C usage documentation. -->
165+
166+
<section class="usage">
167+
168+
### Usage
169+
170+
```c
171+
#include "stdlib/complex/float64/base/add3.h"
172+
```
173+
174+
#### stdlib_base_complex128_add3( z1, z2, z3 )
175+
176+
Computes the sum of three double-precision complex floating-point numbers.
177+
178+
```c
179+
#include "stdlib/complex/float64/ctor.h"
180+
#include "stdlib/complex/float64/real.h"
181+
#include "stdlib/complex/float64/imag.h"
182+
183+
stdlib_complex128_t z = stdlib_complex128( 3.0, -2.0 );
184+
185+
stdlib_complex128_t out = stdlib_base_complex128_add3( z, z, z );
186+
187+
double re = stdlib_complex128_real( out );
188+
// returns 9.0
189+
190+
double im = stdlib_complex128_imag( out );
191+
// returns -6.0
192+
```
193+
194+
The function accepts the following arguments:
195+
196+
- **z1**: `[in] stdlib_complex128_t` first input value.
197+
- **z2**: `[in] stdlib_complex128_t` second input value.
198+
- **z3**: `[in] stdlib_complex128_t` third input value.
199+
200+
```c
201+
stdlib_complex128_t stdlib_base_complex128_add3( const stdlib_complex128_t z1, const stdlib_complex128_t z2, const stdlib_complex128_t z3 );
202+
```
203+
204+
</section>
205+
206+
<!-- /.usage -->
207+
208+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
209+
210+
<section class="notes">
211+
212+
</section>
213+
214+
<!-- /.notes -->
215+
216+
<!-- C API usage examples. -->
217+
218+
<section class="examples">
219+
220+
### Examples
221+
222+
```c
223+
#include "stdlib/complex/float64/base/add3.h"
224+
#include "stdlib/complex/float64/ctor.h"
225+
#include "stdlib/complex/float64/reim.h"
226+
#include <stdio.h>
227+
228+
int main( void ) {
229+
const stdlib_complex128_t x[] = {
230+
stdlib_complex128( 3.14, 1.5 ),
231+
stdlib_complex128( -3.14, 1.5 ),
232+
stdlib_complex128( 0.0, -0.0 ),
233+
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
234+
};
235+
236+
stdlib_complex128_t v;
237+
stdlib_complex128_t y;
238+
double re;
239+
double im;
240+
int i;
241+
for ( i = 0; i < 4; i++ ) {
242+
v = x[ i ];
243+
stdlib_complex128_reim( v, &re, &im );
244+
printf( "z = %lf + %lfi\n", re, im );
245+
246+
y = stdlib_base_complex128_add3( v, v, v );
247+
stdlib_complex128_reim( y, &re, &im );
248+
printf( "add3(z, z, z) = %lf + %lfi\n", re, im );
249+
}
250+
}
251+
```
252+
253+
</section>
254+
255+
<!-- /.examples -->
256+
257+
</section>
258+
259+
<!-- /.c -->
260+
261+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
262+
263+
<section class="related">
264+
265+
</section>
266+
267+
<!-- /.related -->
268+
269+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
270+
271+
<section class="links">
272+
273+
</section>
274+
275+
<!-- /.links -->
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var format = require( '@stdlib/string/format' );
28+
var pkg = require( './../package.json' ).name;
29+
var add3 = require( './../lib' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// MAIN //
40+
41+
bench( format( '%s:assign', pkg ), function benchmark( b ) {
42+
var out;
43+
var re;
44+
var im;
45+
var N;
46+
var i;
47+
var j;
48+
var k;
49+
50+
N = 100;
51+
re = uniform( N, -500.0, 500.0, options );
52+
im = uniform( N, -500.0, 500.0, options );
53+
54+
out = new Float64Array( 2 );
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
j = i % N;
59+
k = ( i+1 ) % N;
60+
out = add3.assign( re[ j ], im[ j ], re[ k ], im[ k ], re[ j ], im[ k ], out, 1, 0 ); // eslint-disable-line max-len
61+
if ( typeof out !== 'object' ) {
62+
b.fail( 'should return an object' );
63+
}
64+
}
65+
b.toc();
66+
if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
});

0 commit comments

Comments
 (0)