|
| 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 | +# dcopy-within |
| 22 | + |
| 23 | +> Perform an in-place copy of elements within a double-precision floating-point array. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### dcopyWithin( N, target, x, strideX, start, end ) |
| 34 | + |
| 35 | +Performs an in-place copy of elements within a double-precision floating-point array. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 39 | + |
| 40 | +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 41 | + |
| 42 | +dcopyWithin( 3, 2, x, 1, 1, 2 ); |
| 43 | +// x => <Float64Array>[ 1.0, 2.0, 2.0, 4.0, 5.0, 6.0 ] |
| 44 | +``` |
| 45 | + |
| 46 | +The function has the following parameters: |
| 47 | + |
| 48 | +- **N**: number of indexed elements. |
| 49 | +- **target**: target index. |
| 50 | +- **x**: input [`Float64Array`][@stdlib/array/float64]. |
| 51 | +- **strideX**: stride length. |
| 52 | +- **start**: source start index. |
| 53 | +- **end**: source end index. |
| 54 | + |
| 55 | +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to copy every other element: |
| 56 | + |
| 57 | +```javascript |
| 58 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 59 | + |
| 60 | +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 61 | + |
| 62 | +dcopyWithin( 3, 0, x, 2, 1, 6 ); |
| 63 | +// x => <Float64Array>[ 3.0, 2.0, 5.0, 4.0, 7.0, 6.0, 7.0, 8.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( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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 | +// Copy within the view... |
| 78 | +dcopyWithin( 2, 0, x1, 1, 2, 5 ); |
| 79 | +// x0 => <Float64Array>[ 1.0, 4.0, 5.0, 4.0, 5.0, 6.0 ] |
| 80 | +``` |
| 81 | + |
| 82 | +#### dcopyWithin.ndarray( N, target, x, strideX, offsetX, start, end ) |
| 83 | + |
| 84 | +Performs an in-place copy of elements within a double-precision floating-point array using alternative indexing semantics. |
| 85 | + |
| 86 | +```javascript |
| 87 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 88 | + |
| 89 | +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 90 | + |
| 91 | +dcopyWithin.ndarray( 2, 2, x, 1, 1, 0, 5 ); |
| 92 | +// x => <Float64Array>[ 1.0, 2.0, 3.0, 2.0, 3.0, 6.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 copy elements starting from the second element: |
| 100 | + |
| 101 | +```javascript |
| 102 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 103 | + |
| 104 | +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 105 | + |
| 106 | +dcopyWithin.ndarray( 2, 2, x, 1, 2, 0, 2 ); |
| 107 | +// x => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] |
| 108 | +``` |
| 109 | + |
| 110 | +</section> |
| 111 | + |
| 112 | +<!-- /.usage --> |
| 113 | + |
| 114 | +<section class="notes"> |
| 115 | + |
| 116 | +## Notes |
| 117 | + |
| 118 | +- If `N <= 0`, both functions return the strided array unchanged. |
| 119 | +- Both functions **mutate** the provided input strided array. |
| 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/array/discrete-uniform' ); |
| 133 | +var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' ); |
| 134 | + |
| 135 | +var x = discreteUniform( 10, 0, 500, { |
| 136 | + 'dtype': 'float64' |
| 137 | +}); |
| 138 | +console.log( x ); |
| 139 | + |
| 140 | +// Copy the first 3 elements to positions 5, 6, 7: |
| 141 | +dcopyWithin( 3, 5, x, 1, 0, 3 ); |
| 142 | +console.log( x ); |
| 143 | + |
| 144 | +// Copy every other element starting from the second element: |
| 145 | +dcopyWithin( 5, 0, x, 1, 1, 9 ); |
| 146 | +console.log( x ); |
| 147 | +``` |
| 148 | + |
| 149 | +</section> |
| 150 | + |
| 151 | +<!-- /.examples --> |
| 152 | + |
| 153 | +<!-- C interface documentation. --> |
| 154 | + |
| 155 | +* * * |
| 156 | + |
| 157 | +<section class="c"> |
| 158 | + |
| 159 | +## C APIs |
| 160 | + |
| 161 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 162 | + |
| 163 | +<section class="intro"> |
| 164 | + |
| 165 | +</section> |
| 166 | + |
| 167 | +<!-- /.intro --> |
| 168 | + |
| 169 | +<!-- C usage documentation. --> |
| 170 | + |
| 171 | +<section class="usage"> |
| 172 | + |
| 173 | +### Usage |
| 174 | + |
| 175 | +```c |
| 176 | +#include "stdlib/blas/ext/base/dcopy_within.h" |
| 177 | +``` |
| 178 | + |
| 179 | +#### stdlib_strided_dcopy_within( N, target, \*x, strideX, start, end ) |
| 180 | + |
| 181 | +Performs an in-place copy of elements within a double-precision floating-point array. |
| 182 | + |
| 183 | +```c |
| 184 | +const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; |
| 185 | + |
| 186 | +stdlib_strided_dcopy_within( 3, 3, x, 1, 1, 4 ); |
| 187 | +``` |
| 188 | +
|
| 189 | +The function accepts the following arguments: |
| 190 | +
|
| 191 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 192 | +- **target**: `[in] CBLAS_INT` target index. |
| 193 | +- **x**: `[inout] double*` input array. |
| 194 | +- **strideX**: `[in] CBLAS_INT` stride length. |
| 195 | +- **start**: `[in] CBLAS_INT` source start index. |
| 196 | +- **end**: `[in] CBLAS_INT` source end index. |
| 197 | +
|
| 198 | +```c |
| 199 | +void stdlib_strided_dcopy_within( const CBLAS_INT N, const CBLAS_INT target, double *x, const CBLAS_INT strideX, const CBLAS_INT start, const CBLAS_INT end ); |
| 200 | +``` |
| 201 | + |
| 202 | +<!-- lint disable maximum-heading-length --> |
| 203 | + |
| 204 | +### stdlib_strided_dcopy_within_ndarray( N, target, \*x, strideX, offsetX, start, end ) |
| 205 | + |
| 206 | +<!-- lint enable maximum-heading-length --> |
| 207 | + |
| 208 | +Performs an in-place copy of elements within a double-precision floating-point array using alternative indexing semantics. |
| 209 | + |
| 210 | +```c |
| 211 | +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; |
| 212 | + |
| 213 | +stdlib_strided_dcopy_within_ndarray( 2, 2, x, 1, 1, 0, 2 ); |
| 214 | +``` |
| 215 | +
|
| 216 | +The function accepts the following arguments: |
| 217 | +
|
| 218 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 219 | +- **target**: `[in] CBLAS_INT` target index. |
| 220 | +- **x**: `[inout] double*` input array. |
| 221 | +- **strideX**: `[in] CBLAS_INT` stride length. |
| 222 | +- **offsetX**: `[in] CBLAS_INT` starting index. |
| 223 | +- **start**: `[in] CBLAS_INT` source start index. |
| 224 | +- **end**: `[in] CBLAS_INT` source end index. |
| 225 | +
|
| 226 | +```c |
| 227 | +void stdlib_strided_dcopy_within_ndarray( const CBLAS_INT N, const CBLAS_INT target, double *x, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT start, const CBLAS_INT end ); |
| 228 | +``` |
| 229 | + |
| 230 | +</section> |
| 231 | + |
| 232 | +<!-- /.usage --> |
| 233 | + |
| 234 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 235 | + |
| 236 | +<section class="notes"> |
| 237 | + |
| 238 | +</section> |
| 239 | + |
| 240 | +<!-- /.notes --> |
| 241 | + |
| 242 | +<!-- C API usage examples. --> |
| 243 | + |
| 244 | +<section class="examples"> |
| 245 | + |
| 246 | +### Examples |
| 247 | + |
| 248 | +```c |
| 249 | +#include "stdlib/blas/ext/base/dcopy_within.h" |
| 250 | +#include <stdio.h> |
| 251 | + |
| 252 | +int main( void ) { |
| 253 | + // Create a strided array: |
| 254 | + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; |
| 255 | + |
| 256 | + // Specify the number of elements to copy: |
| 257 | + const int N = 3; |
| 258 | + |
| 259 | + // Specify a stride: |
| 260 | + const int strideX = 1; |
| 261 | + |
| 262 | + // Copy elements starting from index 1 to index 4: |
| 263 | + stdlib_strided_dcopy_within( N, 4, x, strideX, 1, 4 ); |
| 264 | + |
| 265 | + // Print the result: |
| 266 | + for ( int i = 0; i < 8; i++ ) { |
| 267 | + printf( "x[ %i ] = %lf\n", i, x[ i ] ); |
| 268 | + } |
| 269 | +} |
| 270 | +``` |
| 271 | +
|
| 272 | +</section> |
| 273 | +
|
| 274 | +<!-- /.examples --> |
| 275 | +
|
| 276 | +</section> |
| 277 | +
|
| 278 | +<!-- /.c --> |
| 279 | +
|
| 280 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 281 | +
|
| 282 | +<section class="related"> |
| 283 | +
|
| 284 | +</section> |
| 285 | +
|
| 286 | +<!-- /.related --> |
| 287 | +
|
| 288 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 289 | +
|
| 290 | +<section class="links"> |
| 291 | +
|
| 292 | +[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64 |
| 293 | +
|
| 294 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 295 | +
|
| 296 | +<!-- <related-links> --> |
| 297 | +
|
| 298 | +<!-- </related-links> --> |
| 299 | +
|
| 300 | +</section> |
| 301 | +
|
| 302 | +<!-- /.links --> |
0 commit comments