|
| 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 | +# csscal |
| 22 | + |
| 23 | +> Scale a single-precision complex floating-point vector by a single-precision floating-point constant. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var csscal = require( '@stdlib/blas/base/csscal' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### csscal( N, alpha, x, strideX ) |
| 34 | + |
| 35 | +Scales a single-precision complex floating-point vector by a single-precision floating-point constant. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 39 | + |
| 40 | +var x = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); |
| 41 | + |
| 42 | +csscal( 3, 2.0, x, 1 ); |
| 43 | +// x => <Complex64Array>[ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] |
| 44 | +``` |
| 45 | + |
| 46 | +The function has the following parameters: |
| 47 | + |
| 48 | +- **N**: number of indexed elements. |
| 49 | +- **alpha**: scalar constant. |
| 50 | +- **x**: input [`Complex64Array`][@stdlib/array/complex64]. |
| 51 | +- **strideX**: stride length for `x`. |
| 52 | + |
| 53 | +The `N` and stride parameters determine which elements in `x` are scaled by `alpha`. For example, to scale every other element in `x` by `alpha`, |
| 54 | + |
| 55 | +```javascript |
| 56 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 57 | + |
| 58 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 59 | + |
| 60 | +csscal( 2, 2.0, x, 2 ); |
| 61 | +// x => <Complex64Array>[ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ] |
| 62 | +``` |
| 63 | + |
| 64 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 65 | + |
| 66 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 67 | + |
| 68 | +```javascript |
| 69 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 70 | + |
| 71 | +// Initial array: |
| 72 | +var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 73 | + |
| 74 | +// Create an offset view: |
| 75 | +var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 76 | + |
| 77 | +// Scale every element in `x1`: |
| 78 | +csscal( 3, 2.0, x1, 1 ); |
| 79 | +// x0 => <Complex64Array>[ 1.0, 2.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0 ] |
| 80 | +``` |
| 81 | + |
| 82 | +#### csscal.ndarray( N, alpha, x, strideX, offsetX ) |
| 83 | + |
| 84 | +Scales a single-precision complex floating-point vector by a single-precision floating-point constant using alternative indexing semantics. |
| 85 | + |
| 86 | +```javascript |
| 87 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 88 | + |
| 89 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 90 | + |
| 91 | +csscal.ndarray( 3, 2.0, x, 1, 0 ); |
| 92 | +// x => <Complex64Array>[ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] |
| 93 | +``` |
| 94 | + |
| 95 | +The function has the following additional parameters: |
| 96 | + |
| 97 | +- **offsetX**: starting index for `x`. |
| 98 | + |
| 99 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to scale every other element in the input strided array starting from the second element, |
| 100 | + |
| 101 | +```javascript |
| 102 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 103 | + |
| 104 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 105 | + |
| 106 | +csscal.ndarray( 2, 2.0, x, 2, 1 ); |
| 107 | +// x => <Complex64Array>[ 1.0, 2.0, 6.0, 8.0, 5.0, 6.0, 14.0, 16.0 ] |
| 108 | +``` |
| 109 | + |
| 110 | +</section> |
| 111 | + |
| 112 | +<!-- /.usage --> |
| 113 | + |
| 114 | +<section class="notes"> |
| 115 | + |
| 116 | +## Notes |
| 117 | + |
| 118 | +- If `N <= 0`, both functions return `x` unchanged. |
| 119 | +- `csscal()` corresponds to the [BLAS][blas] level 1 function [`csscal`][csscal]. |
| 120 | + |
| 121 | +</section> |
| 122 | + |
| 123 | +<!-- /.notes --> |
| 124 | + |
| 125 | +<section class="examples"> |
| 126 | + |
| 127 | +## Examples |
| 128 | + |
| 129 | +<!-- eslint no-undef: "error" --> |
| 130 | + |
| 131 | +```javascript |
| 132 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 133 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 134 | +var Complex64 = require( '@stdlib/complex/float32/ctor' ); |
| 135 | +var csscal = require( '@stdlib/blas/base/csscal' ); |
| 136 | + |
| 137 | +function rand() { |
| 138 | + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 139 | +} |
| 140 | + |
| 141 | +var x = filledarrayBy( 10, 'complex64', rand ); |
| 142 | +console.log( x.toString() ); |
| 143 | + |
| 144 | +csscal( x.length, 2.0, x, 1 ); |
| 145 | +console.log( x.toString() ); |
| 146 | +``` |
| 147 | + |
| 148 | +</section> |
| 149 | + |
| 150 | +<!-- /.examples --> |
| 151 | + |
| 152 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 153 | + |
| 154 | +<section class="related"> |
| 155 | + |
| 156 | +</section> |
| 157 | + |
| 158 | +<!-- /.related --> |
| 159 | + |
| 160 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 161 | + |
| 162 | +<section class="links"> |
| 163 | + |
| 164 | +[blas]: http://www.netlib.org/blas |
| 165 | + |
| 166 | +[csscal]: https://www.netlib.org/lapack/explore-html/d2/de8/group__scal_ga40d50a435a5fcf16cf41fa80d746819f.html#ga40d50a435a5fcf16cf41fa80d746819f |
| 167 | + |
| 168 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 169 | + |
| 170 | +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 |
| 171 | + |
| 172 | +</section> |
| 173 | + |
| 174 | +<!-- /.links --> |
0 commit comments