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