|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# zdrot |
| 22 | + |
| 23 | +> Applies a plane rotation. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var zdrot = require( '@stdlib/blas/base/zdrot' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### zdrot( N, zx, strideX, zy, strideY, c, s ) |
| 34 | + |
| 35 | +Applies a plane rotation. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 39 | +var real = require( '@stdlib/complex/real' ); |
| 40 | +var imag = require( '@stdlib/complex/imag' ); |
| 41 | + |
| 42 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 43 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 44 | + |
| 45 | +zdrot( zx.length, zx, 1, zy, 1, 0.8, 0.6 ); |
| 46 | + |
| 47 | +var z = zy.get( 0 ); |
| 48 | +// returns <Complex128> |
| 49 | + |
| 50 | +var re = real( z ); |
| 51 | +// returns ~-0.6 |
| 52 | + |
| 53 | +var im = imag( z ); |
| 54 | +// returns ~-1.2 |
| 55 | + |
| 56 | +z = zx.get( 0 ); |
| 57 | +// returns <Complex128> |
| 58 | + |
| 59 | +re = real( z ); |
| 60 | +// returns ~0.8 |
| 61 | + |
| 62 | +im = imag( z ); |
| 63 | +// returns ~1.6 |
| 64 | +``` |
| 65 | + |
| 66 | +The function has the following parameters: |
| 67 | + |
| 68 | +- **N**: number of indexed elements. |
| 69 | +- **zx**: first input [`Complex128Array`][@stdlib/array/complex128]. |
| 70 | +- **strideX**: index increment for `zx`. |
| 71 | +- **zy**: second input [`Complex128Array`][@stdlib/array/complex128]. |
| 72 | +- **strideY**: index increment for `zy`. |
| 73 | + |
| 74 | +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, |
| 75 | + |
| 76 | +```javascript |
| 77 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 78 | +var real = require( '@stdlib/complex/real' ); |
| 79 | +var imag = require( '@stdlib/complex/imag' ); |
| 80 | + |
| 81 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 82 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 83 | + |
| 84 | +zdrot( 2, zx, 2, zy, 2, 0.8, 0.6 ); |
| 85 | + |
| 86 | +var z = zy.get( 0 ); |
| 87 | +// returns <Complex128> |
| 88 | + |
| 89 | +var re = real( z ); |
| 90 | +// returns ~-0.6 |
| 91 | + |
| 92 | +var im = imag( z ); |
| 93 | +// returns ~-1.2 |
| 94 | + |
| 95 | +z = zx.get( 0 ); |
| 96 | +// returns <Complex128> |
| 97 | + |
| 98 | +re = real( z ); |
| 99 | +// returns ~0.8 |
| 100 | + |
| 101 | +im = imag( z ); |
| 102 | +// returns ~1.6 |
| 103 | +``` |
| 104 | + |
| 105 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 106 | + |
| 107 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 108 | + |
| 109 | +```javascript |
| 110 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 111 | +var real = require( '@stdlib/complex/real' ); |
| 112 | +var imag = require( '@stdlib/complex/imag' ); |
| 113 | + |
| 114 | +// Initial arrays... |
| 115 | +var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 116 | +var zy0 = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 117 | + |
| 118 | +// Create offset views... |
| 119 | +var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 120 | +var zy1 = new Complex128Array( zy0.buffer, zy0.BYTES_PER_ELEMENT*2 ); // start at 3rd element |
| 121 | + |
| 122 | +zdrot( 2, zx1, -2, zy1, 1, 0.8, 0.6 ); |
| 123 | + |
| 124 | +var z = zy0.get( 2 ); |
| 125 | +// returns <Complex128> |
| 126 | + |
| 127 | +var re = real( z ); |
| 128 | +// returns ~-4.2 |
| 129 | + |
| 130 | +var im = imag( z ); |
| 131 | +// returns ~-4.8 |
| 132 | + |
| 133 | +z = zx0.get( 3 ); |
| 134 | +// returns <Complex128> |
| 135 | + |
| 136 | +re = real( z ); |
| 137 | +// returns ~5.6 |
| 138 | + |
| 139 | +im = imag( z ); |
| 140 | +// returns ~6.4 |
| 141 | +``` |
| 142 | + |
| 143 | +#### zdrot.ndarray( N, zx, strideX, offsetX, zy, strideY, offsetY, c, s ) |
| 144 | + |
| 145 | +Applies a plane rotation using alternative indexing semantics. |
| 146 | + |
| 147 | +```javascript |
| 148 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 149 | +var real = require( '@stdlib/complex/real' ); |
| 150 | +var imag = require( '@stdlib/complex/imag' ); |
| 151 | + |
| 152 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 153 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 154 | + |
| 155 | +zdrot.ndarray( zx.length, zx, 1, 0, zy, 1, 0, 0.8, 0.6 ); |
| 156 | + |
| 157 | +var z = zy.get( 0 ); |
| 158 | +// returns <Complex128> |
| 159 | + |
| 160 | +var re = real( z ); |
| 161 | +// returns ~-0.6 |
| 162 | + |
| 163 | +var im = imag( z ); |
| 164 | +// returns ~-1.2 |
| 165 | + |
| 166 | +z = zx.get( 0 ); |
| 167 | +// returns <Complex128> |
| 168 | + |
| 169 | +re = real( z ); |
| 170 | +// returns ~0.8 |
| 171 | + |
| 172 | +im = imag( z ); |
| 173 | +// returns ~1.6 |
| 174 | +``` |
| 175 | + |
| 176 | +The function has the following additional parameters: |
| 177 | + |
| 178 | +- **offsetX**: starting index for `zx`. |
| 179 | +- **offsetY**: starting index for `zy`. |
| 180 | + |
| 181 | +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, |
| 182 | + |
| 183 | +```javascript |
| 184 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 185 | +var real = require( '@stdlib/complex/real' ); |
| 186 | +var imag = require( '@stdlib/complex/imag' ); |
| 187 | + |
| 188 | +var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 189 | +var zy = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 190 | + |
| 191 | +zdrot.ndarray( 2, zx, 2, 1, zy, 2, 1, 0.8, 0.6 ); |
| 192 | + |
| 193 | +var z = zy.get( 3 ); |
| 194 | +// returns <Complex128> |
| 195 | + |
| 196 | +var re = real( z ); |
| 197 | +// returns ~-4.2 |
| 198 | + |
| 199 | +var im = imag( z ); |
| 200 | +// returns ~-4.8 |
| 201 | + |
| 202 | +z = zx.get( 1 ); |
| 203 | +// returns <Complex128> |
| 204 | + |
| 205 | +re = real( z ); |
| 206 | +// returns ~2.4 |
| 207 | + |
| 208 | +im = imag( z ); |
| 209 | +// returns ~3.2 |
| 210 | +``` |
| 211 | + |
| 212 | +</section> |
| 213 | + |
| 214 | +<!-- /.usage --> |
| 215 | + |
| 216 | +<section class="notes"> |
| 217 | + |
| 218 | +## Notes |
| 219 | + |
| 220 | +- If `N <= 0`, both functions leave `zx` and `zy` unchanged. |
| 221 | +- `zdrot()` corresponds to the [BLAS][blas] level 1 function [`zdrot`][zdrot]. |
| 222 | + |
| 223 | +</section> |
| 224 | + |
| 225 | +<!-- /.notes --> |
| 226 | + |
| 227 | +<section class="examples"> |
| 228 | + |
| 229 | +## Examples |
| 230 | + |
| 231 | +<!-- eslint no-undef: "error" --> |
| 232 | + |
| 233 | +```javascript |
| 234 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 235 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 236 | +var Complex128 = require( '@stdlib/complex/float64' ); |
| 237 | +var zcopy = require( '@stdlib/blas/base/zcopy' ); |
| 238 | +var zeros = require( '@stdlib/array/zeros' ); |
| 239 | +var logEach = require( '@stdlib/console/log-each' ); |
| 240 | +var zdrot = require( '@stdlib/blas/base/zdrot' ); |
| 241 | + |
| 242 | +function rand() { |
| 243 | + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 244 | +} |
| 245 | + |
| 246 | +// Generate random input arrays: |
| 247 | +var zx = filledarrayBy( 10, 'complex128', rand ); |
| 248 | +var zxc = zcopy( zx.length, zx, 1, zeros( zx.length, 'complex128' ), 1 ); |
| 249 | + |
| 250 | +var zy = filledarrayBy( 10, 'complex128', rand ); |
| 251 | +var zyc = zcopy( zy.length, zy, 1, zeros( zy.length, 'complex128' ), 1 ); |
| 252 | + |
| 253 | +// Apply a plane rotation: |
| 254 | +zdrot( zx.length, zx, 1, zy, 1, 0.8, 0.6 ); |
| 255 | + |
| 256 | +// Print the results: |
| 257 | +logEach( '(%s,%s) => (%s,%s)', zxc, zyc, zx, zy ); |
| 258 | +``` |
| 259 | + |
| 260 | +</section> |
| 261 | + |
| 262 | +<!-- /.examples --> |
| 263 | + |
| 264 | +<!-- C interface documentation. --> |
| 265 | + |
| 266 | +* * * |
| 267 | + |
| 268 | +<section class="c"> |
| 269 | + |
| 270 | +## C APIs |
| 271 | + |
| 272 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 273 | + |
| 274 | +<section class="intro"> |
| 275 | + |
| 276 | +</section> |
| 277 | + |
| 278 | +<!-- /.intro --> |
| 279 | + |
| 280 | +<!-- C usage documentation. --> |
| 281 | + |
| 282 | +<section class="usage"> |
| 283 | + |
| 284 | +### Usage |
| 285 | + |
| 286 | +```c |
| 287 | +#include "stdlib/blas/base/zdrot.h" |
| 288 | +``` |
| 289 | + |
| 290 | +#### c_zdrot( N, \*X, strideX, \*Y, strideY, c, s ) |
| 291 | + |
| 292 | +Applies a plane rotation. |
| 293 | + |
| 294 | +```c |
| 295 | +double x[] = { 1.0, 2.0, 3.0, 4.0 }; // interleaved real and imaginary components |
| 296 | +double y[] = { 5.0, 6.0, 7.0, 8.0 }; |
| 297 | + |
| 298 | +c_zdrot( 2, (void *)x, 1, (void *)Y, 1, 0.8, 0.6 ); |
| 299 | +``` |
| 300 | +
|
| 301 | +The function accepts the following arguments: |
| 302 | +
|
| 303 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 304 | +- **zx**: `[inout] void*` first input array. |
| 305 | +- **strideX**: `[in] CBLAS_INT` index increment for `zx`. |
| 306 | +- **zy**: `[inout] void*` second input array. |
| 307 | +- **strideY**: `[in] CBLAS_INT` index increment for `zy`. |
| 308 | +- **c**: `[in] double` cosine of the angle of rotation. |
| 309 | +- **s**: `[in] double` sine of the angle of rotation. |
| 310 | +
|
| 311 | +```c |
| 312 | +void c_zdrot( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY, const double c, const double s ); |
| 313 | +``` |
| 314 | + |
| 315 | +</section> |
| 316 | + |
| 317 | +<!-- /.usage --> |
| 318 | + |
| 319 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 320 | + |
| 321 | +<section class="notes"> |
| 322 | + |
| 323 | +</section> |
| 324 | + |
| 325 | +<!-- /.notes --> |
| 326 | + |
| 327 | +<!-- C API usage examples. --> |
| 328 | + |
| 329 | +<section class="examples"> |
| 330 | + |
| 331 | +### Examples |
| 332 | + |
| 333 | +```c |
| 334 | +#include "stdlib/blas/base/zdrot.h" |
| 335 | +#include <stdio.h> |
| 336 | + |
| 337 | +int main( void ) { |
| 338 | + // Create strided arrays: |
| 339 | + double zx[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; |
| 340 | + double zy[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 341 | + |
| 342 | + // Specify the number of elements: |
| 343 | + const int N = 4; |
| 344 | + |
| 345 | + // Specify stride lengths: |
| 346 | + const int strideX = 1; |
| 347 | + const int strideY = -1; |
| 348 | + |
| 349 | + // Copy elements: |
| 350 | + c_zdrot( N, (void *)zx, strideX, (void *)zy, strideY, 0.8, 0.6 ); |
| 351 | + |
| 352 | + // Print the result: |
| 353 | + for ( int i = 0; i < N; i++ ) { |
| 354 | + printf( "zx[ %i ] = %lf + %lfj\n", i, zx[ i*2 ], zx[ (i*2)+1 ] ); |
| 355 | + printf( "zy[ %i ] = %lf + %lfj\n", i, zy[ i*2 ], zy[ (i*2)+1 ] ); |
| 356 | + } |
| 357 | +} |
| 358 | +``` |
| 359 | +
|
| 360 | +</section> |
| 361 | +
|
| 362 | +<!-- /.examples --> |
| 363 | +
|
| 364 | +</section> |
| 365 | +
|
| 366 | +<!-- /.c --> |
| 367 | +
|
| 368 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 369 | +
|
| 370 | +<section class="related"> |
| 371 | +
|
| 372 | +</section> |
| 373 | +
|
| 374 | +<!-- /.related --> |
| 375 | +
|
| 376 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 377 | +
|
| 378 | +<section class="links"> |
| 379 | +
|
| 380 | +[blas]: http://www.netlib.org/blas |
| 381 | +
|
| 382 | +[zdrot]: http://www.netlib.org/lapack/explore-html/da/df6/group__complex__blas__level1.html |
| 383 | +
|
| 384 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 385 | +
|
| 386 | +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128 |
| 387 | +
|
| 388 | +</section> |
| 389 | +
|
| 390 | +<!-- /.links --> |
0 commit comments