|
| 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 | +# zrot |
| 22 | + |
| 23 | +> Apply a plane rotation with real cosine and complex sine to a pair of complex vectors. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var zrot = require( '@stdlib/lapack/base/zrot' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### zrot( N, zx, strideX, zy, strideY, c, s ) |
| 34 | + |
| 35 | +Applies a plane rotation with real cosine and complex sine. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 39 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 40 | +var real = require( '@stdlib/complex/float64/real' ); |
| 41 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 42 | + |
| 43 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 44 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 45 | +var s = new Complex128( 0.0, 0.75 ); |
| 46 | + |
| 47 | +zrot( zx.length, zx, 1, zy, 1, 1.25, s ); |
| 48 | + |
| 49 | +var z = zy.get( 0 ); |
| 50 | +// returns <Complex128> |
| 51 | + |
| 52 | +var re = real( z ); |
| 53 | +// returns ~-1.5 |
| 54 | + |
| 55 | +var im = imag( z ); |
| 56 | +// returns ~0.75 |
| 57 | + |
| 58 | +z = zx.get( 0 ); |
| 59 | +// returns <Complex128> |
| 60 | + |
| 61 | +re = real( z ); |
| 62 | +// returns ~1.25 |
| 63 | + |
| 64 | +im = imag( z ); |
| 65 | +// returns ~2.5 |
| 66 | +``` |
| 67 | + |
| 68 | +The function has the following parameters: |
| 69 | + |
| 70 | +- **N**: number of indexed elements. |
| 71 | +- **zx**: first input [`Complex128Array`][@stdlib/array/complex128]. |
| 72 | +- **strideX**: index increment for `zx`. |
| 73 | +- **zy**: second input [`Complex128Array`][@stdlib/array/complex128]. |
| 74 | +- **strideY**: index increment for `zy`. |
| 75 | + |
| 76 | +The `N` and stride parameters determine how values from `zx` and `zy` are accessed at runtime. For example, to apply a plane rotation to every other element, |
| 77 | + |
| 78 | +```javascript |
| 79 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 80 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 81 | +var real = require( '@stdlib/complex/float64/real' ); |
| 82 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 83 | + |
| 84 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 85 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 86 | +var s = new Complex128( 0.0, 0.75 ); |
| 87 | + |
| 88 | +zrot( 2, zx, 2, zy, 2, 1.25, s ); |
| 89 | + |
| 90 | +var z = zy.get( 0 ); |
| 91 | +// returns <Complex128> |
| 92 | + |
| 93 | +var re = real( z ); |
| 94 | +// returns ~-1.5 |
| 95 | + |
| 96 | +var im = imag( z ); |
| 97 | +// returns ~0.75 |
| 98 | + |
| 99 | +z = zx.get( 0 ); |
| 100 | +// returns <Complex128> |
| 101 | + |
| 102 | +re = real( z ); |
| 103 | +// returns ~1.25 |
| 104 | + |
| 105 | +im = imag( z ); |
| 106 | +// returns ~2.5 |
| 107 | +``` |
| 108 | + |
| 109 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 110 | + |
| 111 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 112 | + |
| 113 | +```javascript |
| 114 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 115 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 116 | +var real = require( '@stdlib/complex/float64/real' ); |
| 117 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 118 | + |
| 119 | +// Initial arrays... |
| 120 | +var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 121 | +var zy0 = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 122 | + |
| 123 | +// Create offset views... |
| 124 | +var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 125 | +var zy1 = new Complex128Array( zy0.buffer, zy0.BYTES_PER_ELEMENT*2 ); // start at 3rd element |
| 126 | + |
| 127 | +var s = new Complex128( 0.0, 0.75 ); |
| 128 | + |
| 129 | +zrot( 2, zx1, -2, zy1, 1, 1.25, s ); |
| 130 | + |
| 131 | +var z = zy0.get( 2 ); |
| 132 | +// returns <Complex128> |
| 133 | + |
| 134 | +var re = real( z ); |
| 135 | +// returns ~-6 |
| 136 | + |
| 137 | +var im = imag( z ); |
| 138 | +// returns ~5.25 |
| 139 | + |
| 140 | +z = zx0.get( 3 ); |
| 141 | +// returns <Complex128> |
| 142 | + |
| 143 | +re = real( z ); |
| 144 | +// returns ~8.75 |
| 145 | + |
| 146 | +im = imag( z ); |
| 147 | +// returns ~10 |
| 148 | +``` |
| 149 | + |
| 150 | +#### zrot.ndarray( N, zx, strideX, offsetX, zy, strideY, offsetY, c, s ) |
| 151 | + |
| 152 | +Applies a plane rotation with real cosine and complex sine using alternative indexing semantics. |
| 153 | + |
| 154 | +```javascript |
| 155 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 156 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 157 | +var real = require( '@stdlib/complex/float64/real' ); |
| 158 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 159 | + |
| 160 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 161 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 162 | +var s = new Complex128( 0.0, 0.75 ); |
| 163 | + |
| 164 | +zrot.ndarray( zx.length, zx, 1, 0, zy, 1, 0, 1.25, s ); |
| 165 | + |
| 166 | +var z = zy.get( 0 ); |
| 167 | +// returns <Complex128> |
| 168 | + |
| 169 | +var re = real( z ); |
| 170 | +// returns ~-1.5 |
| 171 | + |
| 172 | +var im = imag( z ); |
| 173 | +// returns ~0.75 |
| 174 | + |
| 175 | +z = zx.get( 0 ); |
| 176 | +// returns <Complex128> |
| 177 | + |
| 178 | +re = real( z ); |
| 179 | +// returns ~1.25 |
| 180 | + |
| 181 | +im = imag( z ); |
| 182 | +// returns ~2.5 |
| 183 | +``` |
| 184 | + |
| 185 | +The function has the following additional parameters: |
| 186 | + |
| 187 | +- **offsetX**: starting index for `zx`. |
| 188 | +- **offsetY**: starting index for `zy`. |
| 189 | + |
| 190 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to apply a plane rotation to every other element starting from the second element, |
| 191 | + |
| 192 | +```javascript |
| 193 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 194 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 195 | +var real = require( '@stdlib/complex/float64/real' ); |
| 196 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 197 | + |
| 198 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 199 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 200 | +var s = new Complex128( 0.0, 0.75 ); |
| 201 | + |
| 202 | +zrot.ndarray( 2, zx, 2, 1, zy, 2, 1, 1.25, s ); |
| 203 | + |
| 204 | +var z = zy.get( 3 ); |
| 205 | +// returns <Complex128> |
| 206 | + |
| 207 | +var re = real( z ); |
| 208 | +// returns ~-6.0 |
| 209 | + |
| 210 | +var im = imag( z ); |
| 211 | +// returns ~5.25 |
| 212 | + |
| 213 | +z = zx.get( 1 ); |
| 214 | +// returns <Complex128> |
| 215 | + |
| 216 | +re = real( z ); |
| 217 | +// returns ~3.75 |
| 218 | + |
| 219 | +im = imag( z ); |
| 220 | +// returns ~5.0 |
| 221 | +``` |
| 222 | + |
| 223 | +</section> |
| 224 | + |
| 225 | +<!-- /.usage --> |
| 226 | + |
| 227 | +<section class="notes"> |
| 228 | + |
| 229 | +## Notes |
| 230 | + |
| 231 | +- If `N <= 0`, both functions leave `zx` and `zy` unchanged. |
| 232 | +- `zrot()` corresponds to the [LAPACK][lapack] routine [`zrot`][zrot]. |
| 233 | + |
| 234 | +</section> |
| 235 | + |
| 236 | +<!-- /.notes --> |
| 237 | + |
| 238 | +<section class="examples"> |
| 239 | + |
| 240 | +## Examples |
| 241 | + |
| 242 | +<!-- eslint no-undef: "error" --> |
| 243 | + |
| 244 | +```javascript |
| 245 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 246 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 247 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 248 | +var zcopy = require( '@stdlib/blas/base/zcopy' ); |
| 249 | +var zeros = require( '@stdlib/array/zeros' ); |
| 250 | +var logEach = require( '@stdlib/console/log-each' ); |
| 251 | +var zrot = require( '@stdlib/lapack/base/zrot' ); |
| 252 | + |
| 253 | +function rand() { |
| 254 | + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 255 | +} |
| 256 | + |
| 257 | +// Generate random input arrays: |
| 258 | +var zx = filledarrayBy( 10, 'complex128', rand ); |
| 259 | +var zxc = zcopy( zx.length, zx, 1, zeros( zx.length, 'complex128' ), 1 ); |
| 260 | + |
| 261 | +var zy = filledarrayBy( 10, 'complex128', rand ); |
| 262 | +var zyc = zcopy( zy.length, zy, 1, zeros( zy.length, 'complex128' ), 1 ); |
| 263 | + |
| 264 | +var s = new Complex128( 0.0, 0.75 ); |
| 265 | + |
| 266 | +// Apply a plane rotation: |
| 267 | +zrot( zx.length, zx, 1, zy, 1, 1.25, s ); |
| 268 | + |
| 269 | +// Print the results: |
| 270 | +logEach( '(%s,%s) => (%s,%s)', zxc, zyc, zx, zy ); |
| 271 | +``` |
| 272 | + |
| 273 | +</section> |
| 274 | + |
| 275 | +<!-- /.examples --> |
| 276 | + |
| 277 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 278 | + |
| 279 | +<section class="related"> |
| 280 | + |
| 281 | +</section> |
| 282 | + |
| 283 | +<!-- /.related --> |
| 284 | + |
| 285 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 286 | + |
| 287 | +<section class="links"> |
| 288 | + |
| 289 | +[lapack]: http://www.netlib.org/lapack |
| 290 | + |
| 291 | +[zrot]: https://netlib.org/lapack/explore-html/d1/d45/group__rot_gaac9d54e7408105ad6f4c810902e75b7a.html#gaac9d54e7408105ad6f4c810902e75b7a |
| 292 | + |
| 293 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 294 | + |
| 295 | +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128 |
| 296 | + |
| 297 | +</section> |
| 298 | + |
| 299 | +<!-- /.links --> |
0 commit comments