|
| 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 | +# crot |
| 22 | + |
| 23 | +> Apply a plane rotation with real cosine and complex sine to a pair of single-precision complex floating-point vectors. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var crot = require( '@stdlib/lapack/base/crot' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### crot( N, cx, strideCX, cy, strideCY, c, s ) |
| 34 | + |
| 35 | +Applies a plane rotation with real cosine and complex sine. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 39 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 40 | +var realf = require( '@stdlib/complex/float32/real' ); |
| 41 | +var imagf = require( '@stdlib/complex/float32/imag' ); |
| 42 | + |
| 43 | +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 44 | +var cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 45 | +var s = new Complex64( 0.0, 0.75 ); |
| 46 | + |
| 47 | +crot( cx.length, cx, 1, cy, 1, 1.25, s ); |
| 48 | + |
| 49 | +var z = cy.get( 0 ); |
| 50 | +// returns <Complex64> |
| 51 | + |
| 52 | +var re = realf( z ); |
| 53 | +// returns ~-1.5 |
| 54 | + |
| 55 | +var im = imagf( z ); |
| 56 | +// returns ~0.75 |
| 57 | + |
| 58 | +z = cx.get( 0 ); |
| 59 | +// returns <Complex64> |
| 60 | + |
| 61 | +re = realf( z ); |
| 62 | +// returns ~1.25 |
| 63 | + |
| 64 | +im = imagf( z ); |
| 65 | +// returns ~2.5 |
| 66 | +``` |
| 67 | + |
| 68 | +The function has the following parameters: |
| 69 | + |
| 70 | +- **N**: number of indexed elements. |
| 71 | +- **cx**: first input [`Complex64Array`][@stdlib/array/complex64]. |
| 72 | +- **strideCX**: stride length for `cx`. |
| 73 | +- **cy**: second input [`Complex64Array`][@stdlib/array/complex64]. |
| 74 | +- **strideCY**: stride length for `cy`. |
| 75 | + |
| 76 | +The `N` and stride parameters determine how values from `cx` and `cy` are accessed at runtime. For example, to apply a plane rotation to every other element, |
| 77 | + |
| 78 | +```javascript |
| 79 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 80 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 81 | +var realf = require( '@stdlib/complex/float32/real' ); |
| 82 | +var imagf = require( '@stdlib/complex/float32/imag' ); |
| 83 | + |
| 84 | +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 85 | +var cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 86 | +var s = new Complex64( 0.0, 0.75 ); |
| 87 | + |
| 88 | +crot( 2, cx, 2, cy, 2, 1.25, s ); |
| 89 | + |
| 90 | +var z = cy.get( 0 ); |
| 91 | +// returns <Complex64> |
| 92 | + |
| 93 | +var re = realf( z ); |
| 94 | +// returns ~-1.5 |
| 95 | + |
| 96 | +var im = imagf( z ); |
| 97 | +// returns ~0.75 |
| 98 | + |
| 99 | +z = cx.get( 0 ); |
| 100 | +// returns <Complex64> |
| 101 | + |
| 102 | +re = realf( z ); |
| 103 | +// returns ~1.25 |
| 104 | + |
| 105 | +im = imagf( 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 Complex64Array = require( '@stdlib/array/complex64' ); |
| 115 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 116 | +var realf = require( '@stdlib/complex/float32/real' ); |
| 117 | +var imagf = require( '@stdlib/complex/float32/imag' ); |
| 118 | + |
| 119 | +// Initial arrays... |
| 120 | +var cx0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 121 | +var cy0 = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 122 | + |
| 123 | +// Create offset views... |
| 124 | +var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 125 | +var cy1 = new Complex64Array( cy0.buffer, cy0.BYTES_PER_ELEMENT*2 ); // start at 3rd element |
| 126 | + |
| 127 | +var s = new Complex64( 0.0, 0.75 ); |
| 128 | + |
| 129 | +crot( 2, cx1, -2, cy1, 1, 1.25, s ); |
| 130 | + |
| 131 | +var z = cy0.get( 2 ); |
| 132 | +// returns <Complex64> |
| 133 | + |
| 134 | +var re = realf( z ); |
| 135 | +// returns ~-6 |
| 136 | + |
| 137 | +var im = imagf( z ); |
| 138 | +// returns ~5.25 |
| 139 | + |
| 140 | +z = cx0.get( 3 ); |
| 141 | +// returns <Complex64> |
| 142 | + |
| 143 | +re = realf( z ); |
| 144 | +// returns ~8.75 |
| 145 | + |
| 146 | +im = imagf( z ); |
| 147 | +// returns ~10 |
| 148 | +``` |
| 149 | + |
| 150 | +#### crot.ndarray( N, cx, strideCX, offsetCX, cy, strideCY, offsetCY, c, s ) |
| 151 | + |
| 152 | +Applies a plane rotation with real cosine and complex sine using alternative indexing semantics. |
| 153 | + |
| 154 | +```javascript |
| 155 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 156 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 157 | +var realf = require( '@stdlib/complex/float32/real' ); |
| 158 | +var imagf = require( '@stdlib/complex/float32/imag' ); |
| 159 | + |
| 160 | +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 161 | +var cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 162 | +var s = new Complex64( 0.0, 0.75 ); |
| 163 | + |
| 164 | +crot.ndarray( cx.length, cx, 1, 0, cy, 1, 0, 1.25, s ); |
| 165 | + |
| 166 | +var z = cy.get( 0 ); |
| 167 | +// returns <Complex64> |
| 168 | + |
| 169 | +var re = realf( z ); |
| 170 | +// returns ~-1.5 |
| 171 | + |
| 172 | +var im = imagf( z ); |
| 173 | +// returns ~0.75 |
| 174 | + |
| 175 | +z = cx.get( 0 ); |
| 176 | +// returns <Complex64> |
| 177 | + |
| 178 | +re = realf( z ); |
| 179 | +// returns ~1.25 |
| 180 | + |
| 181 | +im = imagf( z ); |
| 182 | +// returns ~2.5 |
| 183 | +``` |
| 184 | + |
| 185 | +The function has the following additional parameters: |
| 186 | + |
| 187 | +- **offsetCX**: starting index for `cx`. |
| 188 | +- **offsetCY**: starting index for `cy`. |
| 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 Complex64Array = require( '@stdlib/array/complex64' ); |
| 194 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 195 | +var realf = require( '@stdlib/complex/float32/real' ); |
| 196 | +var imagf = require( '@stdlib/complex/float32/imag' ); |
| 197 | + |
| 198 | +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 199 | +var cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 200 | +var s = new Complex64( 0.0, 0.75 ); |
| 201 | + |
| 202 | +crot.ndarray( 2, cx, 2, 1, cy, 2, 1, 1.25, s ); |
| 203 | + |
| 204 | +var z = cy.get( 3 ); |
| 205 | +// returns <Complex64> |
| 206 | + |
| 207 | +var re = realf( z ); |
| 208 | +// returns ~-6.0 |
| 209 | + |
| 210 | +var im = imagf( z ); |
| 211 | +// returns ~5.25 |
| 212 | + |
| 213 | +z = cx.get( 1 ); |
| 214 | +// returns <Complex64> |
| 215 | + |
| 216 | +re = realf( z ); |
| 217 | +// returns ~3.75 |
| 218 | + |
| 219 | +im = imagf( 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 `cx` and `cy` unchanged. |
| 232 | +- `crot()` corresponds to the [LAPACK][lapack] routine [`crot`][crot]. |
| 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 Complex64 = require( '@stdlib/complex/float32/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 crot = require( '@stdlib/lapack/base/crot' ); |
| 252 | + |
| 253 | +function rand() { |
| 254 | + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 255 | +} |
| 256 | + |
| 257 | +// Generate random input arrays: |
| 258 | +var cx = filledarrayBy( 10, 'complex64', rand ); |
| 259 | +var cxc = zcopy( cx.length, cx, 1, zeros( cx.length, 'complex64' ), 1 ); |
| 260 | + |
| 261 | +var cy = filledarrayBy( 10, 'complex64', rand ); |
| 262 | +var cyc = zcopy( cy.length, cy, 1, zeros( cy.length, 'complex64' ), 1 ); |
| 263 | + |
| 264 | +var s = new Complex64( 0.0, 0.75 ); |
| 265 | + |
| 266 | +// Apply a plane rotation: |
| 267 | +crot( cx.length, cx, 1, cy, 1, 1.25, s ); |
| 268 | + |
| 269 | +// Print the results: |
| 270 | +logEach( '(%s,%s) => (%s,%s)', cxc, cyc, cx, cy ); |
| 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 | +[crot]: https://netlib.org/lapack/explore-html/d1/d45/group__rot_ga25544801d45dcabdec7b24d863ebea9c.html#ga25544801d45dcabdec7b24d863ebea9c |
| 292 | + |
| 293 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 294 | + |
| 295 | +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 |
| 296 | + |
| 297 | +</section> |
| 298 | + |
| 299 | +<!-- /.links --> |
0 commit comments