Skip to content

Commit 0fa6ac9

Browse files
kgrytesaurabhraghuvanshii
authored andcommitted
feat: add assign method
--- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - 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 ac0412b commit 0fa6ac9

File tree

10 files changed

+601
-76
lines changed

10 files changed

+601
-76
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ var im = imag( v );
5858
// returns -1.0
5959
```
6060

61+
#### mul.assign( re1, im1, re2, im2, out, strideOut, offsetOut )
62+
63+
Multiplies two double-precision complex floating-point numbers and assigns results to a provided output array.
64+
65+
```javascript
66+
var Float64Array = require( '@stdlib/array/float64' );
67+
68+
var out = new Float64Array( 2 );
69+
var v = mul.assign( 5.0, 3.0, -2.0, 1.0, out, 1, 0 );
70+
// returns <Float64Array>[ -13.0, -1.0 ]
71+
72+
var bool = ( out === v );
73+
// returns true
74+
```
75+
6176
</section>
6277

6378
<!-- /.usage -->
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 mul = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg+':assign', function benchmark( b ) {
34+
var out;
35+
var re;
36+
var im;
37+
var N;
38+
var i;
39+
var j;
40+
var k;
41+
42+
N = 100;
43+
re = uniform( N, -500.0, 500.0 );
44+
im = uniform( N, -500.0, 500.0 );
45+
46+
out = new Float64Array( 2 );
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
j = i % N;
51+
k = ( i+1 ) % N;
52+
out = mul.assign( re[ j ], im[ j ], re[ k ], im[ k ], out, 1, 0 );
53+
if ( typeof out !== 'object' ) {
54+
b.fail( 'should return an object' );
55+
}
56+
}
57+
b.toc();
58+
if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) {
59+
b.fail( 'should not return NaN' );
60+
}
61+
b.pass( 'benchmark finished' );
62+
b.end();
63+
});

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,45 @@
2828
> var im = {{alias:@stdlib/complex/float64/imag}}( out )
2929
-1.0
3030

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

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,65 @@
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 multiplying two double-precision complex floating-point numbers.
28+
*/
29+
interface Mul {
30+
/**
31+
* Multiplies 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+
* var real = require( '@stdlib/complex/float64/real' );
40+
* var imag = require( '@stdlib/complex/float64/imag' );
41+
*
42+
* var z1 = new Complex128( 5.0, 3.0 );
43+
* // returns <Complex128>
44+
*
45+
* var z2 = new Complex128( -2.0, 1.0 );
46+
* // returns <Complex128>
47+
*
48+
* var out = mul( z1, z2 );
49+
* // returns <Complex128>
50+
*
51+
* var re = real( out );
52+
* // returns -13.0
53+
*
54+
* var im = imag( out );
55+
* // returns -1.0
56+
*/
57+
( z1: Complex128, z2: Complex128 ): Complex128;
58+
59+
/**
60+
* Multiplies two double-precision complex floating-point numbers and assigns results to a provided output array.
61+
*
62+
* @param re1 - real component of the first complex number
63+
* @param im1 - imaginary component of the first complex number
64+
* @param re2 - real component of the second complex number
65+
* @param im2 - imaginary component of the second complex number
66+
* @param out - output array
67+
* @param strideOut - stride length
68+
* @param offsetOut - starting index
69+
* @returns output array
70+
*
71+
* @example
72+
* var Float64Array = require( '@stdlib/array/float64' );
73+
*
74+
* var out = new Float64Array( 2 );
75+
* var v = mul.assign( 5.0, 3.0, -2.0, 1.0, out, 1, 0 );
76+
* // returns <Float64Array>[ -13.0, -1.0 ]
77+
*
78+
* var bool = ( out === v );
79+
* // returns true
80+
*/
81+
assign<T extends NumericArray | Collection<number>>( re1: number, im1: number, re2: number, im2: number, out: T, strideOut: number, offsetOut: number ): T;
82+
}
2483

2584
/**
2685
* Multiplies two double-precision complex floating-point numbers.
@@ -48,8 +107,18 @@ import { Complex128 } from '@stdlib/types/complex';
48107
*
49108
* var im = imag( out );
50109
* // returns -1.0
110+
*
111+
* @example
112+
* var Float64Array = require( '@stdlib/array/float64' );
113+
*
114+
* var out = new Float64Array( 2 );
115+
* var v = mul.assign( 5.0, 3.0, -2.0, 1.0, out, 1, 0 );
116+
* // returns <Float64Array>[ -13.0, -1.0 ]
117+
*
118+
* var bool = ( out === v );
119+
* // returns true
51120
*/
52-
declare function mul( z1: Complex128, z2: Complex128 ): Complex128;
121+
declare var mul: Mul;
53122

54123

55124
// EXPORTS //

lib/node_modules/@stdlib/complex/float64/base/mul/docs/types/test.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,121 @@ import mul = require( './index' );
6565
mul( z ); // $ExpectError
6666
mul( z, z, z ); // $ExpectError
6767
}
68+
69+
// Attached to the main export is an `assign` method which returns a collection...
70+
{
71+
mul.assign( 1.0, 1.0, 1.0, 1.0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array
72+
mul.assign( 1.0, 1.0, 1.0, 1.0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array
73+
mul.assign( 1.0, 1.0, 1.0, 1.0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[]
74+
}
75+
76+
// The compiler throws an error if the `assign` method is provided a first argument which is not a number...
77+
{
78+
const out = new Float64Array( 2 );
79+
80+
mul.assign( true, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
81+
mul.assign( false, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
82+
mul.assign( null, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
83+
mul.assign( undefined, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
84+
mul.assign( '5', 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
85+
mul.assign( [], 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
86+
mul.assign( {}, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
87+
mul.assign( ( x: number ): number => x, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError
88+
}
89+
90+
// The compiler throws an error if the `assign` method is provided a second argument which is not a number...
91+
{
92+
const out = new Float64Array( 2 );
93+
94+
mul.assign( 1.0, true, 3.0, 4.0, out, 1, 0 ); // $ExpectError
95+
mul.assign( 1.0, false, 3.0, 4.0, out, 1, 0 ); // $ExpectError
96+
mul.assign( 1.0, null, 3.0, 4.0, out, 1, 0 ); // $ExpectError
97+
mul.assign( 1.0, undefined, 3.0, 4.0, out, 1, 0 ); // $ExpectError
98+
mul.assign( 1.0, '5', 3.0, 4.0, out, 1, 0 ); // $ExpectError
99+
mul.assign( 1.0, [], 3.0, 4.0, out, 1, 0 ); // $ExpectError
100+
mul.assign( 1.0, {}, 3.0, 4.0, out, 1, 0 ); // $ExpectError
101+
mul.assign( 1.0, ( x: number ): number => x, 3.0, 4.0, out, 1, 0 ); // $ExpectError
102+
}
103+
104+
// The compiler throws an error if the `assign` method is provided a third argument which is not a number...
105+
{
106+
const out = new Float64Array( 2 );
107+
108+
mul.assign( 1.0, 2.0, true, 4.0, out, 1, 0 ); // $ExpectError
109+
mul.assign( 1.0, 2.0, false, 4.0, out, 1, 0 ); // $ExpectError
110+
mul.assign( 1.0, 2.0, null, 4.0, out, 1, 0 ); // $ExpectError
111+
mul.assign( 1.0, 2.0, undefined, 4.0, out, 1, 0 ); // $ExpectError
112+
mul.assign( 1.0, 2.0, '5', 4.0, out, 1, 0 ); // $ExpectError
113+
mul.assign( 1.0, 2.0, [], 4.0, out, 1, 0 ); // $ExpectError
114+
mul.assign( 1.0, 2.0, {}, 4.0, out, 1, 0 ); // $ExpectError
115+
mul.assign( 1.0, 2.0, ( x: number ): number => x, 4.0, out, 1, 0 ); // $ExpectError
116+
}
117+
118+
// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number...
119+
{
120+
const out = new Float64Array( 2 );
121+
122+
mul.assign( 1.0, 2.0, 3.0, true, out, 1, 0 ); // $ExpectError
123+
mul.assign( 1.0, 2.0, 3.0, false, out, 1, 0 ); // $ExpectError
124+
mul.assign( 1.0, 2.0, 3.0, null, out, 1, 0 ); // $ExpectError
125+
mul.assign( 1.0, 2.0, 3.0, undefined, out, 1, 0 ); // $ExpectError
126+
mul.assign( 1.0, 2.0, 3.0, '5', out, 1, 0 ); // $ExpectError
127+
mul.assign( 1.0, 2.0, 3.0, [], out, 1, 0 ); // $ExpectError
128+
mul.assign( 1.0, 2.0, 3.0, {}, out, 1, 0 ); // $ExpectError
129+
mul.assign( 1.0, 2.0, 3.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError
130+
}
131+
132+
// The compiler throws an error if the `assign` method is provided a fifth argument which is not a collection...
133+
{
134+
mul.assign( 1.0, 2.0, 3.0, 4.0, 1, 1, 0 ); // $ExpectError
135+
mul.assign( 1.0, 2.0, 3.0, 4.0, true, 1, 0 ); // $ExpectError
136+
mul.assign( 1.0, 2.0, 3.0, 4.0, false, 1, 0 ); // $ExpectError
137+
mul.assign( 1.0, 2.0, 3.0, 4.0, null, 1, 0 ); // $ExpectError
138+
mul.assign( 1.0, 2.0, 3.0, 4.0, undefined, 1, 0 ); // $ExpectError
139+
mul.assign( 1.0, 2.0, 3.0, 4.0, '5', 1, 0 ); // $ExpectError
140+
mul.assign( 1.0, 2.0, 3.0, 4.0, [ '5' ], 1, 0 ); // $ExpectError
141+
mul.assign( 1.0, 2.0, 3.0, 4.0, {}, 1, 0 ); // $ExpectError
142+
mul.assign( 1.0, 2.0, 3.0, 4.0, ( x: number ): number => x, 1, 0 ); // $ExpectError
143+
}
144+
145+
// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number...
146+
{
147+
const out = new Float64Array( 2 );
148+
149+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, true, 0 ); // $ExpectError
150+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, false, 0 ); // $ExpectError
151+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, null, 0 ); // $ExpectError
152+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, undefined, 0 ); // $ExpectError
153+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, '5', 0 ); // $ExpectError
154+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, [], 0 ); // $ExpectError
155+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, {}, 0 ); // $ExpectError
156+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, ( x: number ): number => x, 0 ); // $ExpectError
157+
}
158+
159+
// The compiler throws an error if the `assign` method is provided a seventh argument which is not a number...
160+
{
161+
const out = new Float64Array( 2 );
162+
163+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, true, 0 ); // $ExpectError
164+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, false, 0 ); // $ExpectError
165+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, null, 0 ); // $ExpectError
166+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, undefined, 0 ); // $ExpectError
167+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, '5', 0 ); // $ExpectError
168+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, [], 0 ); // $ExpectError
169+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, {}, 0 ); // $ExpectError
170+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, ( x: number ): number => x, 0 ); // $ExpectError
171+
}
172+
173+
// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
174+
{
175+
const out = new Float64Array( 2 );
176+
177+
mul.assign(); // $ExpectError
178+
mul.assign( 1.0 ); // $ExpectError
179+
mul.assign( 1.0, 2.0 ); // $ExpectError
180+
mul.assign( 1.0, 2.0, 3.0 ); // $ExpectError
181+
mul.assign( 1.0, 2.0, 3.0, 4.0 ); // $ExpectError
182+
mul.assign( 1.0, 2.0, 3.0, 4.0, out ); // $ExpectError
183+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, 1 ); // $ExpectError
184+
mul.assign( 1.0, 2.0, 3.0, 4.0, out, 1, 0, {} ); // $ExpectError
185+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
// MAIN //
22+
23+
/**
24+
* Multiplies two double-precision complex floating-point numbers and assigns results to a provided output array.
25+
*
26+
* @param {number} re1 - real component of the first complex number
27+
* @param {number} im1 - imaginary component of the first complex number
28+
* @param {number} re2 - real component of the second complex number
29+
* @param {number} im2 - imaginary component of the second complex number
30+
* @param {Collection} out - output array
31+
* @param {integer} strideOut - stride length
32+
* @param {NonNegativeInteger} offsetOut - starting index
33+
* @returns {Collection} output array
34+
*
35+
* @example
36+
* var Float64Array = require( '@stdlib/array/float64' );
37+
*
38+
* var out = assign( 5.0, 3.0, -2.0, 1.0, new Float64Array( 2 ), 1, 0 );
39+
* // returns <Float64Array>[ -13.0, -1.0 ]
40+
*/
41+
function assign( re1, im1, re2, im2, out, strideOut, offsetOut ) {
42+
out[ offsetOut ] = (re1*re2) - (im1*im2);
43+
out[ offsetOut+strideOut ] = (re1*im2) + (im1*re2);
44+
return out;
45+
}
46+
47+
48+
// EXPORTS //
49+
50+
module.exports = assign;

0 commit comments

Comments
 (0)