|
| 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 | +# zdscal |
| 22 | + |
| 23 | +> Scale a double-precision complex floating-point vector by a double-precision floating-point constant. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var zdscal = require( '@stdlib/blas/base/zdscal' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### zdscal( N, da, zx, strideZX ) |
| 34 | + |
| 35 | +Scales a double-precision complex floating-point vector by a double-precision floating-point constant. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 39 | +var real = require( '@stdlib/complex/float64/real' ); |
| 40 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 41 | + |
| 42 | +var zx = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); |
| 43 | + |
| 44 | +zdscal( 3, 2.0, zx, 1 ); |
| 45 | + |
| 46 | +var z = zx.get( 0 ); |
| 47 | +// returns <Complex128> |
| 48 | + |
| 49 | +var re = real( z ); |
| 50 | +// returns 2.0 |
| 51 | + |
| 52 | +var im = imag( z ); |
| 53 | +// returns 2.0 |
| 54 | +``` |
| 55 | + |
| 56 | +The function has the following parameters: |
| 57 | + |
| 58 | +- **N**: number of indexed elements. |
| 59 | +- **da**: scalar constant. |
| 60 | +- **zx**: input [`Complex128Array`][@stdlib/array/complex128]. |
| 61 | +- **strideZX**: stride length for `zx`. |
| 62 | + |
| 63 | +The `N` and stride parameters determine which elements in `zx` are scaled by `da`. For example, to scale every other element in `zx` by `da`, |
| 64 | + |
| 65 | +```javascript |
| 66 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 67 | +var real = require( '@stdlib/complex/float64/real' ); |
| 68 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 69 | + |
| 70 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 71 | + |
| 72 | +zdscal( 2, 2.0, zx, 2 ); |
| 73 | + |
| 74 | +var z = zx.get( 2 ); |
| 75 | +// returns <Complex128> |
| 76 | + |
| 77 | +var re = real( z ); |
| 78 | +// returns 10.0 |
| 79 | + |
| 80 | +var im = imag( z ); |
| 81 | +// returns 12.0 |
| 82 | +``` |
| 83 | + |
| 84 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 85 | + |
| 86 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 87 | + |
| 88 | +```javascript |
| 89 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 90 | +var real = require( '@stdlib/complex/float64/real' ); |
| 91 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 92 | + |
| 93 | +// Initial array: |
| 94 | +var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 95 | + |
| 96 | +// Create an offset view: |
| 97 | +var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 98 | + |
| 99 | +// Scale every element in `zx1`: |
| 100 | +zdscal( 3, 2.0, zx1, 1 ); |
| 101 | + |
| 102 | +var z = zx0.get( 0 ); |
| 103 | +// returns <Complex128> |
| 104 | + |
| 105 | +var re = real( z ); |
| 106 | +// returns 1.0 |
| 107 | + |
| 108 | +var im = imag( z ); |
| 109 | +// returns 2.0 |
| 110 | + |
| 111 | +z = zx0.get( 1 ); |
| 112 | +// returns <Complex128> |
| 113 | + |
| 114 | +re = real( z ); |
| 115 | +// returns 6.0 |
| 116 | + |
| 117 | +im = imag( z ); |
| 118 | +// returns 8.0 |
| 119 | +``` |
| 120 | + |
| 121 | +#### zdscal.ndarray( N, da, zx, strideZX, offsetZX ) |
| 122 | + |
| 123 | +Scales a double-precision complex floating-point vector by a double-precision floating-point constant using alternative indexing semantics. |
| 124 | + |
| 125 | +```javascript |
| 126 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 127 | +var real = require( '@stdlib/complex/float64/real' ); |
| 128 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 129 | + |
| 130 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 131 | + |
| 132 | +zdscal.ndarray( 3, 2.0, zx, 1, 0 ); |
| 133 | + |
| 134 | +var z = zx.get( 0 ); |
| 135 | +// returns <Complex128> |
| 136 | + |
| 137 | +var re = real( z ); |
| 138 | +// returns 2.0 |
| 139 | + |
| 140 | +var im = imag( z ); |
| 141 | +// returns 4.0 |
| 142 | +``` |
| 143 | + |
| 144 | +The function has the following additional parameters: |
| 145 | + |
| 146 | +- **offsetZX**: starting index for `zx`. |
| 147 | + |
| 148 | +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 element in the input strided array starting from the second element, |
| 149 | + |
| 150 | +```javascript |
| 151 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 152 | +var real = require( '@stdlib/complex/float64/real' ); |
| 153 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 154 | + |
| 155 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 156 | + |
| 157 | +zdscal.ndarray( 2, 2.0, zx, 2, 1 ); |
| 158 | + |
| 159 | +var z = zx.get( 3 ); |
| 160 | +// returns <Complex128> |
| 161 | + |
| 162 | +var re = real( z ); |
| 163 | +// returns 14.0 |
| 164 | + |
| 165 | +var im = imag( z ); |
| 166 | +// returns 16.0 |
| 167 | +``` |
| 168 | + |
| 169 | +</section> |
| 170 | + |
| 171 | +<!-- /.usage --> |
| 172 | + |
| 173 | +<section class="notes"> |
| 174 | + |
| 175 | +## Notes |
| 176 | + |
| 177 | +- If `N <= 0`, both functions return `zx` unchanged. |
| 178 | +- `zdscal()` corresponds to the [BLAS][blas] level 1 function [`zdscal`][zdscal]. |
| 179 | + |
| 180 | +</section> |
| 181 | + |
| 182 | +<!-- /.notes --> |
| 183 | + |
| 184 | +<section class="examples"> |
| 185 | + |
| 186 | +## Examples |
| 187 | + |
| 188 | +<!-- eslint no-undef: "error" --> |
| 189 | + |
| 190 | +```javascript |
| 191 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 192 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 193 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 194 | +var zdscal = require( '@stdlib/blas/base/zdscal' ); |
| 195 | + |
| 196 | +function rand() { |
| 197 | + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 198 | +} |
| 199 | + |
| 200 | +var zx = filledarrayBy( 10, 'complex128', rand ); |
| 201 | +console.log( zx.toString() ); |
| 202 | + |
| 203 | +zdscal( zx.length, 2.0, zx, 1 ); |
| 204 | +console.log( zx.toString() ); |
| 205 | +``` |
| 206 | + |
| 207 | +</section> |
| 208 | + |
| 209 | +<!-- /.examples --> |
| 210 | + |
| 211 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 212 | + |
| 213 | +<section class="related"> |
| 214 | + |
| 215 | +</section> |
| 216 | + |
| 217 | +<!-- /.related --> |
| 218 | + |
| 219 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 220 | + |
| 221 | +<section class="links"> |
| 222 | + |
| 223 | +[blas]: http://www.netlib.org/blas |
| 224 | + |
| 225 | +[zdscal]: https://www.netlib.org/lapack/explore-html/d2/de8/group__scal_ga40d50a435a5fcf16cf41fa80d746819f.html#ga40d50a435a5fcf16cf41fa80d746819f |
| 226 | + |
| 227 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 228 | + |
| 229 | +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128 |
| 230 | + |
| 231 | +</section> |
| 232 | + |
| 233 | +<!-- /.links --> |
0 commit comments