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