|
| 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 | +# czeroTo |
| 22 | + |
| 23 | +> Fill a single-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from zero. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var czeroTo = require( '@stdlib/blas/ext/base/czero-to' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### czeroTo( N, x, strideX ) |
| 34 | + |
| 35 | +Fills a single-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from zero. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 39 | + |
| 40 | +var x = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 41 | + |
| 42 | +czeroTo( x.length, x, 1 ); |
| 43 | +// x => <Complex64Array>[ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] |
| 44 | +``` |
| 45 | + |
| 46 | +The function has the following parameters: |
| 47 | + |
| 48 | +- **N**: number of indexed elements. |
| 49 | +- **x**: input [`Complex64Array`][@stdlib/array/complex64]. |
| 50 | +- **strideX**: stride length. |
| 51 | + |
| 52 | +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element: |
| 53 | + |
| 54 | +<!-- eslint-disable max-len --> |
| 55 | + |
| 56 | +```javascript |
| 57 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 58 | + |
| 59 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 60 | + |
| 61 | +czeroTo( 3, x, 2 ); |
| 62 | +// x => <Complex64Array>[ 0.0, 0.0, 3.0, 4.0, 1.0, 0.0, 7.0, 8.0, 2.0, 0.0, 11.0, 12.0 ] |
| 63 | +``` |
| 64 | + |
| 65 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 66 | + |
| 67 | +<!-- eslint-disable max-len --> |
| 68 | + |
| 69 | +```javascript |
| 70 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 71 | + |
| 72 | +// Initial array... |
| 73 | +var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 74 | + |
| 75 | +// Create an offset view... |
| 76 | +var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 77 | + |
| 78 | +// Fill every other element... |
| 79 | +czeroTo( 3, x1, 2 ); |
| 80 | +// x0 => <Complex64Array>[ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 1.0, 0.0, 9.0, 10.0, 2.0, 0.0 ] |
| 81 | +``` |
| 82 | + |
| 83 | +#### czeroTo.ndarray( N, x, strideX, offsetX ) |
| 84 | + |
| 85 | +Fills a single-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from zero using alternative indexing semantics. |
| 86 | + |
| 87 | +```javascript |
| 88 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 89 | + |
| 90 | +var x = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 91 | + |
| 92 | +czeroTo.ndarray( x.length, x, 1, 0 ); |
| 93 | +// x => <Complex64Array>[ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] |
| 94 | +``` |
| 95 | + |
| 96 | +The function has the following additional parameters: |
| 97 | + |
| 98 | +- **offsetX**: starting index. |
| 99 | + |
| 100 | +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 access only the last three elements: |
| 101 | + |
| 102 | +<!-- eslint-disable max-len --> |
| 103 | + |
| 104 | +```javascript |
| 105 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 106 | + |
| 107 | +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 108 | + |
| 109 | +czeroTo.ndarray( 3, x, 1, x.length-3 ); |
| 110 | +// x => <Complex64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] |
| 111 | +``` |
| 112 | + |
| 113 | +</section> |
| 114 | + |
| 115 | +<!-- /.usage --> |
| 116 | + |
| 117 | +<section class="notes"> |
| 118 | + |
| 119 | +## Notes |
| 120 | + |
| 121 | +- If `N <= 0`, both functions return `x` unchanged. |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.notes --> |
| 126 | + |
| 127 | +<section class="examples"> |
| 128 | + |
| 129 | +## Examples |
| 130 | + |
| 131 | +<!-- eslint no-undef: "error" --> |
| 132 | + |
| 133 | +```javascript |
| 134 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 135 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 136 | +var czeroTo = require( '@stdlib/blas/ext/base/czero-to' ); |
| 137 | + |
| 138 | +var xbuf = discreteUniform( 20, -100, 100, { |
| 139 | + 'dtype': 'float32' |
| 140 | +}); |
| 141 | +var x = new Complex64Array( xbuf.buffer ); |
| 142 | +console.log( x ); |
| 143 | + |
| 144 | +czeroTo( x.length, x, 1 ); |
| 145 | +console.log( x ); |
| 146 | +``` |
| 147 | + |
| 148 | +</section> |
| 149 | + |
| 150 | +<!-- /.examples --> |
| 151 | + |
| 152 | +<!-- C interface documentation. --> |
| 153 | + |
| 154 | +* * * |
| 155 | + |
| 156 | +<section class="c"> |
| 157 | + |
| 158 | +## C APIs |
| 159 | + |
| 160 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 161 | + |
| 162 | +<section class="intro"> |
| 163 | + |
| 164 | +</section> |
| 165 | + |
| 166 | +<!-- /.intro --> |
| 167 | + |
| 168 | +<!-- C usage documentation. --> |
| 169 | + |
| 170 | +<section class="usage"> |
| 171 | + |
| 172 | +### Usage |
| 173 | + |
| 174 | +```c |
| 175 | +#include "stdlib/blas/ext/base/czero_to.h" |
| 176 | +``` |
| 177 | + |
| 178 | +#### stdlib_strided_czero_to( N, \*X, strideX ) |
| 179 | + |
| 180 | +Fills a single-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from zero. |
| 181 | + |
| 182 | +```c |
| 183 | +#include "stdlib/complex/float32/ctor.h" |
| 184 | + |
| 185 | +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; |
| 186 | + |
| 187 | +stdlib_strided_czero_to( 4, (stdlib_complex64_t *)x, 1 ); |
| 188 | +``` |
| 189 | +
|
| 190 | +The function accepts the following arguments: |
| 191 | +
|
| 192 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 193 | +- **X**: `[out] stdlib_complex64_t*` input array. |
| 194 | +- **strideX**: `[in] CBLAS_INT` stride length. |
| 195 | +
|
| 196 | +```c |
| 197 | +void API_SUFFIX(stdlib_strided_czero_to)( const CBLAS_INT N, stdlib_complex64_t *X, const CBLAS_INT strideX ); |
| 198 | +``` |
| 199 | + |
| 200 | +#### stdlib_strided_czero_to_ndarray( N, \*X, strideX, offsetX ) |
| 201 | + |
| 202 | +Fills a single-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from zero using alternative indexing semantics. |
| 203 | + |
| 204 | +```c |
| 205 | +#include "stdlib/complex/float32/ctor.h" |
| 206 | + |
| 207 | +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; |
| 208 | + |
| 209 | +stdlib_strided_czero_to_ndarray( 4, (stdlib_complex64_t *)x, 1, 0 ); |
| 210 | +``` |
| 211 | +
|
| 212 | +The function accepts the following arguments: |
| 213 | +
|
| 214 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 215 | +- **X**: `[out] stdlib_complex64_t*` input array. |
| 216 | +- **strideX**: `[in] CBLAS_INT` stride length. |
| 217 | +- **offsetX**: `[in] CBLAS_INT` starting index. |
| 218 | +
|
| 219 | +```c |
| 220 | +void API_SUFFIX(stdlib_strided_czero_to_ndarray)( const CBLAS_INT N, stdlib_complex64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); |
| 221 | +``` |
| 222 | + |
| 223 | +</section> |
| 224 | + |
| 225 | +<!-- /.usage --> |
| 226 | + |
| 227 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 228 | + |
| 229 | +<section class="notes"> |
| 230 | + |
| 231 | +</section> |
| 232 | + |
| 233 | +<!-- /.notes --> |
| 234 | + |
| 235 | +<!-- C API usage examples. --> |
| 236 | + |
| 237 | +<section class="examples"> |
| 238 | + |
| 239 | +### Examples |
| 240 | + |
| 241 | +```c |
| 242 | +#include "stdlib/blas/ext/base/czero_to.h" |
| 243 | +#include "stdlib/complex/float32/ctor.h" |
| 244 | +#include <stdio.h> |
| 245 | + |
| 246 | +int main( void ) { |
| 247 | + // Create a strided array of interleaved real and imaginary components: |
| 248 | + float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; |
| 249 | + |
| 250 | + // Specify the number of elements: |
| 251 | + const int N = 4; |
| 252 | + |
| 253 | + // Specify a stride: |
| 254 | + const int strideX = 1; |
| 255 | + |
| 256 | + // Fill the array: |
| 257 | + stdlib_strided_czero_to( N, (stdlib_complex64_t *)x, strideX ); |
| 258 | + |
| 259 | + // Print the result: |
| 260 | + for ( int i = 0; i < 8; i++ ) { |
| 261 | + printf( "x[ %i ] = %f\n", i, x[ i ] ); |
| 262 | + } |
| 263 | +} |
| 264 | +``` |
| 265 | +
|
| 266 | +</section> |
| 267 | +
|
| 268 | +<!-- /.examples --> |
| 269 | +
|
| 270 | +</section> |
| 271 | +
|
| 272 | +<!-- /.c --> |
| 273 | +
|
| 274 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 275 | +
|
| 276 | +<section class="related"> |
| 277 | +
|
| 278 | +</section> |
| 279 | +
|
| 280 | +<!-- /.related --> |
| 281 | +
|
| 282 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 283 | +
|
| 284 | +<section class="links"> |
| 285 | +
|
| 286 | +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 |
| 287 | +
|
| 288 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 289 | +
|
| 290 | +</section> |
| 291 | +
|
| 292 | +<!-- /.links --> |
0 commit comments