2
2
3
3
@license Apache-2.0
4
4
5
- Copyright (c) 2024 The Stdlib Authors.
5
+ Copyright (c) 2025 The Stdlib Authors.
6
6
7
7
Licensed under the Apache License, Version 2.0 (the "License");
8
8
you may not use this file except in compliance with the License.
@@ -30,39 +30,39 @@ limitations under the License.
30
30
var zscal = require ( ' @stdlib/blas/base/zscal' );
31
31
```
32
32
33
- #### zscal( N, za, zx , strideX )
33
+ #### zscal( N, alpha, x , strideX )
34
34
35
- Scales values from ` zx ` by ` za ` .
35
+ Scales values from ` x ` by ` alpha ` .
36
36
37
37
``` javascript
38
38
var Complex128Array = require ( ' @stdlib/array/complex128' );
39
39
var Complex128 = require ( ' @stdlib/complex/float64/ctor' );
40
40
41
- var zx = new Complex128Array ( [ 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ] );
42
- var za = new Complex128 ( 2.0 , 0.0 );
41
+ var x = new Complex128Array ( [ 1.0 , 1.0 , 1.0 , 1.0 , 1.0 , 1.0 ] );
42
+ var alpha = new Complex128 ( 2.0 , 0.0 );
43
43
44
- zscal ( 3 , za, zx , 1 );
45
- // zx => <Complex128Array>[ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ]
44
+ zscal ( 3 , alpha, x , 1 );
45
+ // x => <Complex128Array>[ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ]
46
46
```
47
47
48
48
The function has the following parameters:
49
49
50
50
- ** N** : number of indexed elements.
51
- - ** za ** : scalar [ ` Complex128 ` ] [ @stdlib/complex/float64/ctor ] constant.
52
- - ** zx ** : input [ ` Complex128Array ` ] [ @stdlib/array/complex128 ] .
53
- - ** strideX** : index increment for ` zx ` .
51
+ - ** alpha ** : scalar [ ` Complex128 ` ] [ @stdlib/complex/float64/ctor ] constant.
52
+ - ** x ** : input [ ` Complex128Array ` ] [ @stdlib/array/complex128 ] .
53
+ - ** strideX** : index increment for ` x ` .
54
54
55
- The ` N ` and stride parameters determine how values from ` zx ` are scaled by ` za ` . For example, to scale every other value in ` zx ` by ` za ` ,
55
+ The ` N ` and stride parameters determine how values from ` x ` are scaled by ` alpha ` . For example, to scale every other value in ` x ` by ` alpha ` ,
56
56
57
57
``` javascript
58
58
var Complex128Array = require ( ' @stdlib/array/complex128' );
59
59
var Complex128 = require ( ' @stdlib/complex/float64/ctor' );
60
60
61
- var zx = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] );
62
- var za = new Complex128 ( 2.0 , 0.0 );
61
+ var x = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] );
62
+ var alpha = new Complex128 ( 2.0 , 0.0 );
63
63
64
- zscal ( 2 , za, zx , 2 );
65
- // zx => <Complex128Array>[ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ]
64
+ zscal ( 2 , alpha, x , 2 );
65
+ // x => <Complex128Array>[ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ]
66
66
```
67
67
68
68
Note that indexing is relative to the first index. To introduce an offset, use [ ` typed array ` ] [ mdn-typed-array ] views.
@@ -74,49 +74,49 @@ var Complex128Array = require( '@stdlib/array/complex128' );
74
74
var Complex128 = require ( ' @stdlib/complex/float64/ctor' );
75
75
76
76
// Initial array:
77
- var zx0 = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] );
77
+ var x0 = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] );
78
78
79
79
// Define a scalar constant:
80
- var za = new Complex128 ( 2.0 , 2.0 );
80
+ var alpha = new Complex128 ( 2.0 , 2.0 );
81
81
82
82
// Create an offset view:
83
- var zx1 = new Complex128Array ( zx0 .buffer , zx0 .BYTES_PER_ELEMENT * 1 ); // start at 2nd element
83
+ var x1 = new Complex128Array ( x0 .buffer , x0 .BYTES_PER_ELEMENT * 1 ); // start at 2nd element
84
84
85
85
// Scales every other value from `zx1` by `za`...
86
- zscal ( 3 , za, zx1 , 1 );
87
- // zx0 => <Complex128Array>[ 1.0, 2.0, -2.0, 14.0, -2.0, 22.0, -2.0, 30.0 ]
86
+ zscal ( 3 , alpha, x1 , 1 );
87
+ // x0 => <Complex128Array>[ 1.0, 2.0, -2.0, 14.0, -2.0, 22.0, -2.0, 30.0 ]
88
88
```
89
89
90
- #### zscal.ndarray( N, za, zx , strideX, offsetX )
90
+ #### zscal.ndarray( N, alpha, x , strideX, offsetX )
91
91
92
- Scales values from ` zx ` by ` za ` using alternative indexing semantics.
92
+ Scales values from ` x ` by ` alpha ` using alternative indexing semantics.
93
93
94
94
``` javascript
95
95
var Complex128Array = require ( ' @stdlib/array/complex128' );
96
96
var Complex128 = require ( ' @stdlib/complex/float64/ctor' );
97
97
98
- var zx = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 ] );
99
- var za = new Complex128 ( 2.0 , 2.0 );
98
+ var x = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 ] );
99
+ var alpha = new Complex128 ( 2.0 , 2.0 );
100
100
101
- zscal .ndarray ( 3 , za, zx , 1 , 0 );
102
- // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
101
+ zscal .ndarray ( 3 , alpha, x , 1 , 0 );
102
+ // x => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
103
103
```
104
104
105
105
The function has the following additional parameters:
106
106
107
- - ** offsetX** : starting index for ` zx ` .
107
+ - ** offsetX** : starting index for ` x ` .
108
108
109
109
While [ ` typed array ` ] [ mdn-typed-array ] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to scale every other value in the input strided array starting from the second element,
110
110
111
111
``` javascript
112
112
var Complex128Array = require ( ' @stdlib/array/complex128' );
113
113
var Complex128 = require ( ' @stdlib/complex/float64/ctor' );
114
114
115
- var zx = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] );
116
- var za = new Complex128 ( 2.0 , 2.0 );
115
+ var x = new Complex128Array ( [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] );
116
+ var alpha = new Complex128 ( 2.0 , 2.0 );
117
117
118
- zscal .ndarray ( 2 , za, zx , 2 , 1 );
119
- // zx => <Complex128Array>[ 1.0, 2.0, -2.0, 14.0, 5.0, 6.0, -2.0, 30.0 ]
118
+ zscal .ndarray ( 2 , alpha, x , 2 , 1 );
119
+ // x => <Complex128Array>[ 1.0, 2.0, -2.0, 14.0, 5.0, 6.0, -2.0, 30.0 ]
120
120
```
121
121
122
122
</section >
@@ -127,7 +127,7 @@ zscal.ndarray( 2, za, zx, 2, 1 );
127
127
128
128
## Notes
129
129
130
- - If ` N <= 0 ` or ` strideX <= 0 ` , both functions return ` zx ` unchanged.
130
+ - If ` N <= 0 ` , both functions return ` x ` unchanged.
131
131
- ` zscal() ` corresponds to the [ BLAS] [ blas ] level 1 function [ ` zscal ` ] [ zscal ] .
132
132
133
133
</section >
@@ -150,15 +150,15 @@ function rand() {
150
150
return new Complex128 ( discreteUniform ( 0 , 10 ), discreteUniform ( - 5 , 5 ) );
151
151
}
152
152
153
- var zx = filledarrayBy ( 10 , ' complex128' , rand );
154
- console .log ( zx .toString () );
153
+ var x = filledarrayBy ( 10 , ' complex128' , rand );
154
+ console .log ( x .toString () );
155
155
156
- var za = new Complex128 ( 2.0 , 2.0 );
157
- console .log ( za .toString () );
156
+ var alpha = new Complex128 ( 2.0 , 2.0 );
157
+ console .log ( alpha .toString () );
158
158
159
- // Scales elements from `zx ` by `za `:
160
- zscal ( zx .length , za, zx , 1 );
161
- console .log ( zx .get ( zx .length - 1 ).toString () );
159
+ // Scales elements from `x ` by `alpha `:
160
+ zscal ( x .length , alpha, x , 1 );
161
+ console .log ( x .get ( x .length - 1 ).toString () );
162
162
```
163
163
164
164
</section >
@@ -191,28 +191,53 @@ console.log( zx.get( zx.length-1 ).toString() );
191
191
#include " stdlib/blas/base/zscal.h"
192
192
```
193
193
194
- #### c_zscal( N, za , \* ZX , strideX )
194
+ #### c_zscal( N, alpha , \* X , strideX )
195
195
196
- Scales values from ` ZX ` by ` za ` .
196
+ Scales values from ` X ` by ` alpha ` .
197
197
198
198
``` c
199
199
#include " stdlib/complex/float64/ctor.h"
200
200
201
- double zx [] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
202
- const stdlib_complex128_t za = stdlib_complex128( 2.0, 2.0 );
201
+ double x [] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
202
+ const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 );
203
203
204
- c_zscal ( 4, za , (void * )zx , 1 );
204
+ c_zscal ( 4, alpha , (void * )x , 1 );
205
205
```
206
206
207
207
The function accepts the following arguments:
208
208
209
209
- **N**: `[in] CBLAS_INT` number of indexed elements.
210
- - **za **: `[in] stdlib_complex128_t` scalar constant.
211
- - **ZX **: `[inout] void*` input array.
212
- - **strideX**: `[in] CBLAS_INT` index increment for `ZX `.
210
+ - **alpha **: `[in] stdlib_complex128_t` scalar constant.
211
+ - **X **: `[inout] void*` input array.
212
+ - **strideX**: `[in] CBLAS_INT` index increment for `X `.
213
213
214
214
```c
215
- void c_zscal( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX );
215
+ void c_zscal( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX );
216
+ ```
217
+
218
+ #### c_zscal_ndarray( N, alpha, \* X, strideX, offsetX )
219
+
220
+ Scales values from ` X ` by ` alpha ` using alternative indexing semantics.
221
+
222
+ ``` c
223
+ #include " stdlib/complex/float64/ctor.h"
224
+
225
+ double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
226
+ const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 );
227
+
228
+ c_zscal_ndarray ( 4, alpha, (void * )x, 1, 0 );
229
+ ```
230
+
231
+ The function accepts the following arguments:
232
+
233
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
234
+ - **alpha**: `[in] stdlib_complex128_t` scalar constant.
235
+ - **X**: `[inout] void*` input array.
236
+ - **strideX**: `[in] CBLAS_INT` index increment for `X`.
237
+ - **offsetX**: `[in] CBLAS_INT` starting index for `X`.
238
+
239
+ ```c
240
+ void c_zscal_ndarray( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
216
241
```
217
242
218
243
</section >
@@ -240,10 +265,10 @@ void c_zscal( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const C
240
265
241
266
int main ( void ) {
242
267
// Create a strided array of interleaved real and imaginary components:
243
- double zx [ ] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
268
+ double x [ ] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
244
269
245
270
// Create a complex scalar:
246
- const stdlib_complex128_t ca = stdlib_complex128( 2.0, 2.0 );
271
+ const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 );
247
272
248
273
// Specify the number of elements:
249
274
const int N = 4;
@@ -252,11 +277,19 @@ int main( void ) {
252
277
const int strideX = 1;
253
278
254
279
// Scale the elements of the array:
255
- c_zscal( N, za, (void *)zx, strideX );
280
+ c_zscal( N, alpha, (void *)x, strideX );
281
+
282
+ // Print the result:
283
+ for ( int i = 0; i < N; i++ ) {
284
+ printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] );
285
+ }
286
+
287
+ // Scale the elements of the array using alternative indexing semantics:
288
+ c_zscal_ndarray( N, alpha, (void *)x, -strideX, N-1 );
256
289
257
290
// Print the result:
258
291
for ( int i = 0; i < N; i++ ) {
259
- printf( "zx [ %i ] = %f + %fj \n", i, zx [ i*2 ], zx [ (i*2)+1 ] );
292
+ printf( "x [ %i ] = %lf + %lfj \n", i, x [ i*2 ], x [ (i*2)+1 ] );
260
293
}
261
294
}
262
295
```
0 commit comments