Skip to content

Commit dfbf338

Browse files
feat: add assign and strided methods to complex/float64/base/div
PR-URL: #7771 Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent 8c20ca4 commit dfbf338

File tree

15 files changed

+3912
-1066
lines changed

15 files changed

+3912
-1066
lines changed

lib/node_modules/@stdlib/complex/float64/base/div/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,61 @@ var v = cdiv( z1, z2 );
5050
// returns <Complex128>[ 5.0, 3.0 ]
5151
```
5252

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

55110
<!-- /.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 isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var cdiv = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
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 Float64Array( 2 );
54+
55+
b.tic();
56+
for ( i = 0; i < b.iterations; i++ ) {
57+
j = i % N;
58+
k = ( i+1 ) % N;
59+
out = cdiv.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 ( isnan( out[ 0 ] ) || isnan( 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var cdiv = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
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 Float64Array( 2 );
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
j = ( i % N ) * 2;
57+
out = cdiv.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 ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) {
64+
b.fail( 'should not return NaN' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
});

lib/node_modules/@stdlib/complex/float64/base/div/docs/repl.txt

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,92 @@
2828
> var im = {{alias:@stdlib/complex/float64/imag}}( y )
2929
3.0
3030

31-
See Also
31+
32+
{{alias}}.assign( re1, im1, re2, im2, out, strideOut, offsetOut )
33+
Divides two double-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
3265
--------
66+
> var out = new {{alias:@stdlib/array/float64}}( 2 );
67+
> {{alias}}.assign( -13.0, -1.0, -2.0, 1.0, out, 1, 0 )
68+
<Float64Array>[ 5.0, 3.0 ]
69+
3370

71+
{{alias}}.strided( z1, sz1, oz1, z2, sz2, oz2, out, so, oo )
72+
Divides two double-precision complex floating-point numbers stored in real-
73+
valued strided array views and assigns results to a provided strided output
74+
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/float64}}( [ -13.0, -1.0 ] );
113+
> var z2 = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0 ] );
114+
> var out = new {{alias:@stdlib/array/float64}}( 2 );
115+
> {{alias}}.strided( z1, 1, 0, z2, 1, 0, out, 1, 0 )
116+
<Float64Array>[ 5.0, 3.0 ]
117+
118+
See Also
119+
--------

lib/node_modules/@stdlib/complex/float64/base/div/docs/types/index.d.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,79 @@
2121
/// <reference types="@stdlib/types"/>
2222

2323
import { Complex128 } from '@stdlib/types/complex';
24+
import { Collection, NumericArray } from '@stdlib/types/array';
25+
26+
/**
27+
* Interface for dividing two double-precision complex floating-point numbers.
28+
*/
29+
interface Cdiv {
30+
/**
31+
* Divides two double-precision complex floating-point numbers.
32+
*
33+
* @param z1 - complex number
34+
* @param z2 - complex number
35+
* @returns result
36+
*
37+
* @example
38+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
39+
*
40+
* var z1 = new Complex128( -13.0, -1.0 );
41+
* var z2 = new Complex128( -2.0, 1.0 );
42+
*
43+
* var out = cdiv( z1, z2 );
44+
* // returns <Complex128>[ 5.0, 3.0 ]
45+
*/
46+
( z1: Complex128, z2: Complex128 ): Complex128;
47+
48+
/**
49+
* Divides two double-precision complex floating-point numbers and assigns results to a provided output array.
50+
*
51+
* @param re1 - real component of the first complex number
52+
* @param im1 - imaginary component of the first complex number
53+
* @param re2 - real component of the second complex number
54+
* @param im2 - imaginary component of the second complex number
55+
* @param out - output array
56+
* @param strideOut - stride length
57+
* @param offsetOut - starting index
58+
* @returns output array
59+
*
60+
* @example
61+
* var Float64Array = require( '@stdlib/array/float64' );
62+
*
63+
* var out = new Float64Array( 2 );
64+
* var v = cdiv.assign( -13.0, -1.0, -2.0, 1.0, out, 1, 0 );
65+
* // returns <Float64Array>[ 5.0, 3.0 ]
66+
*
67+
* var bool = ( out === v );
68+
* // returns true
69+
*/
70+
assign<T extends NumericArray | Collection<number>>( re1: number, im1: number, re2: number, im2: number, out: T, strideOut: number, offsetOut: number ): T;
71+
72+
/**
73+
* Divides two double-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array.
74+
*
75+
* @param z1 - first complex number view
76+
* @param strideZ1 - stride length for `z1`
77+
* @param offsetZ1 - starting index for `z1`
78+
* @param z2 - second complex number view
79+
* @param strideZ2 - stride length for `z2`
80+
* @param offsetZ2 - starting index for `z2`
81+
* @param out - output array
82+
* @param strideOut - stride length for `out`
83+
* @param offsetOut - starting index for `out`
84+
* @returns output array
85+
*
86+
* @example
87+
* var Float64Array = require( '@stdlib/array/float64' );
88+
*
89+
* var z1 = new Float64Array( [ -13.0, -1.0 ] );
90+
* var z2 = new Float64Array( [ -2.0, 1.0 ] );
91+
*
92+
* var out = cdiv.strided( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 );
93+
* // returns <Float64Array>[ 5.0, 3.0 ]
94+
*/
95+
strided<T extends NumericArray | Collection<number>, U extends NumericArray | Collection<number>, V extends NumericArray | Collection<number>>( z1: T, strideZ1: number, offsetZ1: number, z2: U, strideZ2: number, offsetZ2: number, out: V, strideOut: number, offsetOut: number ): V;
96+
}
2497

2598
/**
2699
* Divides two double-precision complex floating-point numbers.
@@ -38,7 +111,7 @@ import { Complex128 } from '@stdlib/types/complex';
38111
* var out = cdiv( z1, z2 );
39112
* // returns <Complex128>[ 5.0, 3.0 ]
40113
*/
41-
declare function cdiv( z1: Complex128, z2: Complex128 ): Complex128;
114+
declare var cdiv: Cdiv;
42115

43116

44117
// EXPORTS //

0 commit comments

Comments
 (0)