Skip to content

Commit f7c3e59

Browse files
committed
feat: add complex/float64/base/scale
--- 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 894885f commit f7c3e59

35 files changed

+3292
-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+
# scale
22+
23+
> Scale a double-precision complex floating-point number by a real-valued double-precision floating-point scalar constant.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var scale = require( '@stdlib/complex/float64/base/scale' );
37+
```
38+
39+
#### scale( alpha, z )
40+
41+
Scales a double-precision complex floating-point number by a real-valued double-precision floating-point scalar constant.
42+
43+
```javascript
44+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
45+
var real = require( '@stdlib/complex/float64/real' );
46+
var imag = require( '@stdlib/complex/float64/imag' );
47+
48+
var z = new Complex128( 5.0, 3.0 );
49+
50+
var v = scale( 5.0, z );
51+
// returns <Complex128>
52+
53+
var re = real( v );
54+
// returns 25.0
55+
56+
var im = imag( v );
57+
// returns 15.0
58+
```
59+
60+
The function supports the following parameters:
61+
62+
- **alpha**: real-valued scalar constant.
63+
- **z**: [complex number][@stdlib/complex/float64/ctor].
64+
65+
#### scale.assign( alpha, re1, im1, out, strideOut, offsetOut )
66+
67+
Scales a double-precision complex floating-point number by a real-valued double-precision floating-point scalar constant and assigns results to a provided output array.
68+
69+
```javascript
70+
var Float64Array = require( '@stdlib/array/float64' );
71+
72+
var out = new Float64Array( 2 );
73+
var v = scale.assign( 5.0, 5.0, 3.0, out, 1, 0 );
74+
// returns <Float64Array>[ 25.0, 15.0 ]
75+
76+
var bool = ( out === v );
77+
// returns true
78+
```
79+
80+
The function supports the following parameters:
81+
82+
- **alpha**: real-valued scalar constant.
83+
- **re**: real component of the complex number.
84+
- **im**: imaginary component of the complex number.
85+
- **out**: output array.
86+
- **strideOut**: stride length for `out`.
87+
- **offsetOut**: starting index for `out`.
88+
89+
#### scale.strided( alpha, z, sz, oz, out, so, oo )
90+
91+
Scales a double-precision complex floating-point number stored in a real-valued strided array view by a real-valued double-precision floating-point scalar constant and assigns results to a provided strided output array.
92+
93+
```javascript
94+
var Float64Array = require( '@stdlib/array/float64' );
95+
96+
var z = new Float64Array( [ 5.0, 3.0 ] );
97+
var out = new Float64Array( 2 );
98+
99+
var v = scale.strided( 5.0, z, 1, 0, out, 1, 0 );
100+
// returns <Float64Array>[ 25.0, 15.0 ]
101+
102+
var bool = ( out === v );
103+
// returns true
104+
```
105+
106+
The function supports the following parameters:
107+
108+
- **alpha**: real-valued scalar constant.
109+
- **z**: complex number strided array view.
110+
- **sz**: stride length for `z`.
111+
- **oz**: starting index for `z`.
112+
- **out**: output array.
113+
- **so**: stride length for `out`.
114+
- **oo**: starting index for `out`.
115+
116+
</section>
117+
118+
<!-- /.usage -->
119+
120+
<section class="examples">
121+
122+
## Examples
123+
124+
<!-- eslint no-undef: "error" -->
125+
126+
```javascript
127+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
128+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
129+
var scale = require( '@stdlib/complex/float64/base/scale' );
130+
131+
var rand = discreteUniform( -50, 50 );
132+
133+
var z1;
134+
var z2;
135+
var i;
136+
for ( i = 0; i < 100; i++ ) {
137+
z1 = new Complex128( rand(), rand() );
138+
z2 = scale( 5.0, z1 );
139+
console.log( '(%s) * 5.0 = %s', z1.toString(), z2.toString() );
140+
}
141+
```
142+
143+
</section>
144+
145+
<!-- /.examples -->
146+
147+
<!-- C interface documentation. -->
148+
149+
* * *
150+
151+
<section class="c">
152+
153+
## C APIs
154+
155+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
156+
157+
<section class="intro">
158+
159+
</section>
160+
161+
<!-- /.intro -->
162+
163+
<!-- C usage documentation. -->
164+
165+
<section class="usage">
166+
167+
### Usage
168+
169+
```c
170+
#include "stdlib/complex/float64/base/scale.h"
171+
```
172+
173+
#### stdlib_base_complex128_scale( alpha, z )
174+
175+
Scales a double-precision complex floating-point number by a real-valued double-precision floating-point scalar constant.
176+
177+
```c
178+
#include "stdlib/complex/float64/ctor.h"
179+
#include "stdlib/complex/float64/real.h"
180+
#include "stdlib/complex/float64/imag.h"
181+
182+
stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 );
183+
184+
stdlib_complex128_t out = stdlib_base_complex128_scale( 5.0, z );
185+
186+
double re = stdlib_complex128_real( out );
187+
// returns 25.0
188+
189+
double im = stdlib_complex128_imag( out );
190+
// returns 15.0
191+
```
192+
193+
The function accepts the following arguments:
194+
195+
- **alpha**: `[in] double` scalar constant.
196+
- **z**: `[in] stdlib_complex128_t` complex number.
197+
198+
```c
199+
stdlib_complex128_t stdlib_base_complex128_scale( const double alpha, const stdlib_complex128_t z );
200+
```
201+
202+
</section>
203+
204+
<!-- /.usage -->
205+
206+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
207+
208+
<section class="notes">
209+
210+
</section>
211+
212+
<!-- /.notes -->
213+
214+
<!-- C API usage examples. -->
215+
216+
<section class="examples">
217+
218+
### Examples
219+
220+
```c
221+
#include "stdlib/complex/float64/base/scale.h"
222+
#include "stdlib/complex/float64/ctor.h"
223+
#include "stdlib/complex/float64/reim.h"
224+
#include <stdio.h>
225+
226+
int main( void ) {
227+
const stdlib_complex128_t x[] = {
228+
stdlib_complex128( 3.14, 1.5 ),
229+
stdlib_complex128( -3.14, 1.5 ),
230+
stdlib_complex128( 0.0, -0.0 ),
231+
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
232+
};
233+
234+
stdlib_complex128_t v;
235+
stdlib_complex128_t y;
236+
double re;
237+
double im;
238+
int i;
239+
for ( i = 0; i < 4; i++ ) {
240+
v = x[ i ];
241+
stdlib_complex128_reim( v, &re, &im );
242+
printf( "z = %lf + %lfi\n", re, im );
243+
244+
y = stdlib_base_complex128_scale( 5.0, v );
245+
stdlib_complex128_reim( y, &re, &im );
246+
printf( "scale(5.0, z) = %lf + %lfi\n", re, im );
247+
}
248+
}
249+
```
250+
251+
</section>
252+
253+
<!-- /.examples -->
254+
255+
</section>
256+
257+
<!-- /.c -->
258+
259+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
260+
261+
<section class="related">
262+
263+
</section>
264+
265+
<!-- /.related -->
266+
267+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
268+
269+
<section class="links">
270+
271+
[@stdlib/complex/float64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/ctor
272+
273+
</section>
274+
275+
<!-- /.links -->
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 scale = 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+
48+
N = 100;
49+
re = uniform( N, -500.0, 500.0, options );
50+
im = uniform( N, -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;
57+
out = scale.assign( 5.0, re[ j ], im[ 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+
});

0 commit comments

Comments
 (0)