|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 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 | +# caxpby |
| 22 | + |
| 23 | +> Multiply a single-precision complex floating-point strided array `x` by a constant and add the result to a single-precision complex floating-point strided array `y` multiplied by a constant. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +This BLAS extension implements the operation |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:axpby" align="center" raw="\mathbf{y} = \alpha \mathbf{x} + \beta \mathbf{y}" alt="Equation for axpby operation."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\mathbf{y} = \alpha \mathbf{x} + \beta \mathbf{y} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- </equation> --> |
| 36 | + |
| 37 | +This API is complementary to the package [`@stdlib/blas/base/caxpy`][@stdlib/blas/base/caxpy] and is a common BLAS extension in libraries such as Intel MKL, OpenBLAS, and others. |
| 38 | + |
| 39 | +</section> |
| 40 | + |
| 41 | +<!-- /.intro --> |
| 42 | + |
| 43 | +<section class="usage"> |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +```javascript |
| 48 | +var caxpby = require( '@stdlib/blas/ext/base/caxpby' ); |
| 49 | +``` |
| 50 | + |
| 51 | +#### caxpby( N, alpha, x, strideX, beta, y, strideY ) |
| 52 | + |
| 53 | +Multiplies a single-precision complex floating-point strided array `x` by a constant and adds the result to a single-precision complex floating-point strided array `y` multiplied by a constant. |
| 54 | + |
| 55 | +```javascript |
| 56 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 57 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 58 | + |
| 59 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); |
| 60 | +var y = new Complex64Array( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); |
| 61 | + |
| 62 | +var alpha = new Complex64( 2.0, 1.0 ); |
| 63 | +var beta = new Complex64( 1.0, -1.0 ); |
| 64 | + |
| 65 | +caxpby( x.length, alpha, x, 1, beta, y, 1 ); |
| 66 | +// y => <Complex64Array>[ 3.0, 4.0, 9.0, 5.0, 3.0, -2.0 ] |
| 67 | +``` |
| 68 | + |
| 69 | +The function has the following parameters: |
| 70 | + |
| 71 | +- **N**: number of indexed elements. |
| 72 | +- **alpha**: first scalar constant. |
| 73 | +- **x**: input [`Complex64Array`][@stdlib/array/complex64]. |
| 74 | +- **strideX**: stride length for `x`. |
| 75 | +- **beta**: second scalar constant. |
| 76 | +- **y**: output [`Complex64Array`][@stdlib/array/complex64]. |
| 77 | +- **strideY**: stride length for `y`. |
| 78 | + |
| 79 | +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to multiply every other element of `x` by `alpha` and add to every other element of `y` multiplied by `beta`: |
| 80 | + |
| 81 | +```javascript |
| 82 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 83 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 84 | + |
| 85 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 86 | +var y = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); |
| 87 | + |
| 88 | +var alpha = new Complex64( 2.0, 1.0 ); |
| 89 | +var beta = new Complex64( 1.0, -1.0 ); |
| 90 | + |
| 91 | +caxpby( 2, alpha, x, 2, beta, y, 2 ); |
| 92 | +// y => <Complex64Array>[ 15.0, 6.0, 9.0, 10.0, 27.0, 18.0, 13.0, 14.0 ] |
| 93 | +``` |
| 94 | + |
| 95 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 96 | + |
| 97 | +<!-- eslint-disable max-len --> |
| 98 | + |
| 99 | +```javascript |
| 100 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 101 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 102 | + |
| 103 | +// Initial arrays... |
| 104 | +var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); |
| 105 | +var y0 = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ); |
| 106 | + |
| 107 | +// Create offset views... |
| 108 | +var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 109 | +var y1 = new Complex64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element |
| 110 | + |
| 111 | +// Define scalar constants: |
| 112 | +var alpha = new Complex64( 2.0, 1.0 ); |
| 113 | +var beta = new Complex64( 1.0, -1.0 ); |
| 114 | + |
| 115 | +caxpby( 3, alpha, x1, 1, beta, y1, 1 ); |
| 116 | +// y0 => <Complex64Array>[ 7.0, 8.0, 9.0, 10.0, 25.0, 12.0, 31.0, 18.0, 37.0, 24.0 ] |
| 117 | +``` |
| 118 | + |
| 119 | +#### caxpby.ndarray( N, alpha, x, strideX, offsetX, beta, y, strideY, offsetY ) |
| 120 | + |
| 121 | +Multiplies a single-precision complex floating-point strided array `x` by a constant and adds the result to a single-precision complex floating-point strided array `y` multiplied by a constant using alternative indexing semantics. |
| 122 | + |
| 123 | +```javascript |
| 124 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 125 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 126 | + |
| 127 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); |
| 128 | +var y = new Complex64Array( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); |
| 129 | + |
| 130 | +var alpha = new Complex64( 2.0, 1.0 ); |
| 131 | +var beta = new Complex64( 1.0, -1.0 ); |
| 132 | + |
| 133 | +caxpby.ndarray( x.length, alpha, x, 1, 0, beta, y, 1, 0 ); |
| 134 | +// y => <Complex64Array>[ 3.0, 4.0, 9.0, 5.0, 3.0, -2.0 ] |
| 135 | +``` |
| 136 | + |
| 137 | +The function has the following additional parameters: |
| 138 | + |
| 139 | +- **offsetX**: starting index for `x`. |
| 140 | +- **offsetY**: starting index for `y`. |
| 141 | + |
| 142 | +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 multiply the last three elements of `x` by `alpha` and add to the last three elements of `y` multiplied by `beta`: |
| 143 | + |
| 144 | +<!-- eslint-disable max-len --> |
| 145 | + |
| 146 | +```javascript |
| 147 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 148 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 149 | + |
| 150 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); |
| 151 | +var y = new Complex64Array( [ 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0 ] ); |
| 152 | + |
| 153 | +var alpha = new Complex64( 2.0, 1.0 ); |
| 154 | +var beta = new Complex64( 1.0, -1.0 ); |
| 155 | + |
| 156 | +caxpby.ndarray( 3, alpha, x, 1, x.length-3, beta, y, 1, y.length-3 ); |
| 157 | +// y => <Complex64Array>[ 11.0, 12.0, 13.0, 14.0, 35.0, 18.0, 41.0, 24.0, 47.0, 30.0 ] |
| 158 | +``` |
| 159 | + |
| 160 | +</section> |
| 161 | + |
| 162 | +<!-- /.usage --> |
| 163 | + |
| 164 | +<section class="notes"> |
| 165 | + |
| 166 | +## Notes |
| 167 | + |
| 168 | +- If `N <= 0`, both functions return `y` unchanged. |
| 169 | + |
| 170 | +</section> |
| 171 | + |
| 172 | +<!-- /.notes --> |
| 173 | + |
| 174 | +<section class="examples"> |
| 175 | + |
| 176 | +## Examples |
| 177 | + |
| 178 | +<!-- eslint no-undef: "error" --> |
| 179 | + |
| 180 | +```javascript |
| 181 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 182 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 183 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 184 | +var logEach = require( '@stdlib/console/log-each' ); |
| 185 | +var caxpby = require( '@stdlib/blas/ext/base/caxpby' ); |
| 186 | + |
| 187 | +var xbuf = discreteUniform( 20, -100, 100, { |
| 188 | + 'dtype': 'float32' |
| 189 | +}); |
| 190 | +var ybuf = discreteUniform( 20, -100, 100, { |
| 191 | + 'dtype': 'float32' |
| 192 | +}); |
| 193 | +var x = new Complex64Array( xbuf.buffer ); |
| 194 | +var y = new Complex64Array( ybuf.buffer ); |
| 195 | +var alpha = new Complex64( 2.0, 1.0 ); |
| 196 | +var beta = new Complex64( 1.0, -1.0 ); |
| 197 | + |
| 198 | +caxpby( x.length, alpha, x, 1, beta, y, 1 ); |
| 199 | +logEach( '%s', y ); |
| 200 | +``` |
| 201 | + |
| 202 | +</section> |
| 203 | + |
| 204 | +<!-- /.examples --> |
| 205 | + |
| 206 | +<!-- C interface documentation. --> |
| 207 | + |
| 208 | +* * * |
| 209 | + |
| 210 | +<section class="c"> |
| 211 | + |
| 212 | +## C APIs |
| 213 | + |
| 214 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 215 | + |
| 216 | +<section class="intro"> |
| 217 | + |
| 218 | +</section> |
| 219 | + |
| 220 | +<!-- /.intro --> |
| 221 | + |
| 222 | +<!-- C usage documentation. --> |
| 223 | + |
| 224 | +<section class="usage"> |
| 225 | + |
| 226 | +### Usage |
| 227 | + |
| 228 | +```c |
| 229 | +#include "stdlib/blas/ext/base/caxpby.h" |
| 230 | +``` |
| 231 | + |
| 232 | +#### stdlib_strided_caxpby( N, alpha, \*X, strideX, beta, \*Y, strideY ) |
| 233 | + |
| 234 | +Multiplies a single-precision complex floating-point strided array `x` by a constant and adds the result to a single-precision complex floating-point strided array `y` multiplied by a constant. |
| 235 | + |
| 236 | +```c |
| 237 | +#include "stdlib/complex/float32/ctor.h" |
| 238 | + |
| 239 | +const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; |
| 240 | +float y[] = { 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; |
| 241 | +const stdlib_complex64_t alpha = stdlib_complex64( 2.0f, 1.0f ); |
| 242 | +const stdlib_complex64_t beta = stdlib_complex64( 1.0f, -1.0f ); |
| 243 | + |
| 244 | +stdlib_strided_caxpby( 4, alpha, (stdlib_complex64_t *)x, 1, beta, (stdlib_complex64_t *)y, 1 ); |
| 245 | +``` |
| 246 | +
|
| 247 | +The function accepts the following arguments: |
| 248 | +
|
| 249 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 250 | +- **alpha**: `[in] stdlib_complex64_t` first scalar constant. |
| 251 | +- **X**: `[in] stdlib_complex64_t*` input array. |
| 252 | +- **strideX**: `[in] CBLAS_INT` stride length for `X`. |
| 253 | +- **beta**: `[in] stdlib_complex64_t` second scalar constant. |
| 254 | +- **Y**: `[inout] stdlib_complex64_t*` output array. |
| 255 | +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. |
| 256 | +
|
| 257 | +```c |
| 258 | +void stdlib_strided_caxpby( const CBLAS_INT N, const stdlib_complex64_t alpha, const stdlib_complex64_t *X, const CBLAS_INT strideX, const stdlib_complex64_t beta, stdlib_complex64_t *Y, const CBLAS_INT strideY ); |
| 259 | +``` |
| 260 | + |
| 261 | +<!--lint disable maximum-heading-length--> |
| 262 | + |
| 263 | +#### stdlib_strided_caxpby_ndarray( N, alpha, \*X, strideX, offsetX, beta, \*Y, strideY, offsetY ) |
| 264 | + |
| 265 | +<!--lint enable maximum-heading-length--> |
| 266 | + |
| 267 | +Multiplies a single-precision complex floating-point strided array `x` by a constant and adds the result to a single-precision complex floating-point strided array `y` multiplied by a constant using alternative indexing semantics. |
| 268 | + |
| 269 | +```c |
| 270 | +#include "stdlib/complex/float32/ctor.h" |
| 271 | + |
| 272 | +const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; |
| 273 | +float y[] = { 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; |
| 274 | +const stdlib_complex64_t alpha = stdlib_complex64( 2.0f, 1.0f ); |
| 275 | +const stdlib_complex64_t beta = stdlib_complex64( 1.0f, -1.0f ); |
| 276 | + |
| 277 | +stdlib_strided_caxpby_ndarray( 4, alpha, (stdlib_complex64_t *)x, 1, 0, beta, (stdlib_complex64_t *)y, 1, 0 ); |
| 278 | +``` |
| 279 | +
|
| 280 | +The function accepts the following arguments: |
| 281 | +
|
| 282 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 283 | +- **alpha**: `[in] stdlib_complex64_t` first scalar constant. |
| 284 | +- **X**: `[in] stdlib_complex64_t*` input array. |
| 285 | +- **strideX**: `[in] CBLAS_INT` stride length for `X`. |
| 286 | +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. |
| 287 | +- **beta**: `[in] stdlib_complex64_t` second scalar constant. |
| 288 | +- **Y**: `[inout] stdlib_complex64_t*` output array. |
| 289 | +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. |
| 290 | +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. |
| 291 | +
|
| 292 | +```c |
| 293 | +void stdlib_strided_caxpby_ndarray( const CBLAS_INT N, const stdlib_complex64_t alpha, const stdlib_complex64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const stdlib_complex64_t beta, stdlib_complex64_t *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); |
| 294 | +``` |
| 295 | + |
| 296 | +</section> |
| 297 | + |
| 298 | +<!-- /.usage --> |
| 299 | + |
| 300 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 301 | + |
| 302 | +<section class="notes"> |
| 303 | + |
| 304 | +</section> |
| 305 | + |
| 306 | +<!-- /.notes --> |
| 307 | + |
| 308 | +<!-- C API usage examples. --> |
| 309 | + |
| 310 | +<section class="examples"> |
| 311 | + |
| 312 | +### Examples |
| 313 | + |
| 314 | +```c |
| 315 | +#include "stdlib/blas/ext/base/caxpby.h" |
| 316 | +#include "stdlib/complex/float32/ctor.h" |
| 317 | +#include "stdlib/complex/float32/real.h" |
| 318 | +#include "stdlib/complex/float32/imag.h" |
| 319 | +#include <stdio.h> |
| 320 | + |
| 321 | +int main( void ) { |
| 322 | + // Create strided arrays: |
| 323 | + const stdlib_complex64_t x[] = { |
| 324 | + stdlib_complex64( 1.0f, -2.0f ), |
| 325 | + stdlib_complex64( 3.0f, -4.0f ), |
| 326 | + stdlib_complex64( 5.0f, -6.0f ), |
| 327 | + stdlib_complex64( 7.0f, -8.0f ) |
| 328 | + }; |
| 329 | + stdlib_complex64_t y[] = { |
| 330 | + stdlib_complex64( 2.0f, 3.0f ), |
| 331 | + stdlib_complex64( 4.0f, 5.0f ), |
| 332 | + stdlib_complex64( 6.0f, 7.0f ), |
| 333 | + stdlib_complex64( 8.0f, 9.0f ) |
| 334 | + }; |
| 335 | + |
| 336 | + // Specify the number of indexed elements: |
| 337 | + const int N = 4; |
| 338 | + |
| 339 | + // Specify strides: |
| 340 | + const int strideX = 1; |
| 341 | + const int strideY = 1; |
| 342 | + |
| 343 | + // Define scalar constants: |
| 344 | + stdlib_complex64_t alpha = stdlib_complex64( 2.0f, 1.0f ); |
| 345 | + stdlib_complex64_t beta = stdlib_complex64( 1.0f, -1.0f ); |
| 346 | + |
| 347 | + // Multiply `x` by a constant and add to `y` multiplied by a constant: |
| 348 | + stdlib_strided_caxpby( N, alpha, x, strideX, beta, y, strideY ); |
| 349 | + |
| 350 | + // Print the result: |
| 351 | + for ( int i = 0; i < N; i++ ) { |
| 352 | + printf( "y[ %i ] = %f + %fi\n", i, stdlib_complex64_real( y[ i ] ), stdlib_complex64_imag( y[ i ] ) ); |
| 353 | + } |
| 354 | +} |
| 355 | +``` |
| 356 | +
|
| 357 | +</section> |
| 358 | +
|
| 359 | +<!-- /.examples --> |
| 360 | +
|
| 361 | +</section> |
| 362 | +
|
| 363 | +<!-- /.c --> |
| 364 | +
|
| 365 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 366 | +
|
| 367 | +<section class="related"> |
| 368 | +
|
| 369 | +</section> |
| 370 | +
|
| 371 | +<!-- /.related --> |
| 372 | +
|
| 373 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 374 | +
|
| 375 | +<section class="links"> |
| 376 | +
|
| 377 | +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 |
| 378 | +
|
| 379 | +[@stdlib/blas/base/caxpy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/caxpy |
| 380 | +
|
| 381 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 382 | +
|
| 383 | +<!-- <related-links> --> |
| 384 | +
|
| 385 | +<!-- </related-links> --> |
| 386 | +
|
| 387 | +</section> |
| 388 | +
|
| 389 | +<!-- /.links --> |
0 commit comments