Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0c4f9ae
feat: add blas/ext/base/dcopy-within
headlessNode Oct 13, 2025
9724d8b
chore: update copyright years
stdlib-bot Oct 13, 2025
bfff2d6
refactor: apply suggestions from code review
headlessNode Oct 19, 2025
1b523b0
refactor: apply suggestions from code review
headlessNode Oct 19, 2025
9928164
docs: apply suggestions from code review
headlessNode Oct 19, 2025
49f2ef5
refactor: negative test cases
headlessNode Oct 19, 2025
d3a5f82
Merge branch 'stdlib-js:develop' into dcopy-within
headlessNode Mar 7, 2026
106602c
refactor: apply suggestions from code review
headlessNode Mar 7, 2026
5f284da
fix: apply suggestions from code review
headlessNode Mar 7, 2026
b9f2837
fix: failing tests
headlessNode Mar 7, 2026
6981271
fix: failing tests
headlessNode Mar 7, 2026
c86fb46
fix: lint errors
headlessNode Mar 7, 2026
de38b29
fix: apply suggestions from code review
headlessNode Mar 10, 2026
8361acf
fix: apply suggestions from code review
headlessNode Mar 11, 2026
f2bfaa5
Merge branch 'develop' into dcopy-within
headlessNode Jul 21, 2026
bac137e
refactor: apply suggestions from code review
headlessNode Jul 21, 2026
f28d3e5
Merge branch 'develop' into dcopy-within
headlessNode Aug 2, 2026
606115f
fix: apply suggestions from code review
headlessNode Aug 2, 2026
6d5b049
Apply suggestions from code review
kgryte Aug 2, 2026
d3b90a5
Apply suggestions from code review
kgryte Aug 2, 2026
a4090ae
Apply suggestions from code review
kgryte Aug 2, 2026
5b759ce
Apply suggestions from code review
kgryte Aug 2, 2026
5ecbc33
Apply suggestions from code review
kgryte Aug 2, 2026
3e94a1a
Apply suggestions from code review
kgryte Aug 2, 2026
2399198
Apply suggestions from code review
kgryte Aug 2, 2026
6e069c3
fix: docs descriptions
headlessNode Aug 2, 2026
9cebefd
Merge branch 'develop' into dcopy-within
headlessNode Aug 2, 2026
0b17b70
fix: cleanup
headlessNode Aug 2, 2026
9ae8e58
Apply suggestions from code review
kgryte Aug 2, 2026
221eaa2
Apply suggestions from code review
kgryte Aug 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 323 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/dcopy-within/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# dcopyWithin

> Perform an in-place copy of elements within a double-precision floating-point strided array.

<section class="usage">

## Usage

```javascript
var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' );
```

#### dcopyWithin( N, target, start, end, x, strideX, workspace, strideW )

Performs an in-place copy of elements within a double-precision floating-point strided array.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var w = new Float64Array( x.length );

dcopyWithin( x.length, 3, 1, 4, x, 1, w, 1 );
// x => <Float64Array>[ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **target**: target index.
- **start**: source start index (inclusive).
- **end**: source end index (exclusive).
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: stride length for `x`.
- **workspace**: workspace [`Float64Array`][@stdlib/array/float64]. Must have at least `N` indexed elements.
- **strideW**: stride length for `workspace`.

The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to copy every other element:

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] );
var w = new Float64Array( 3 );

dcopyWithin( 3, 0, 1, 6, x, 2, w, 1 );
// x => <Float64Array>[ 3.0, 0.0, 5.0, 0.0, 5.0, 0.0, 7.0, 0.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

// Initial array...
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );

// Create an offset view...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Create a workspace array...
var w = new Float64Array( 6 );

// Copy within the view...
dcopyWithin( 6, 0, 3, 6, x1, 1, w, 1 );
// x0 => <Float64Array>[ 1.0, 5.0, 6.0, 7.0, 5.0, 6.0, 7.0, 8.0 ]
```

<!-- lint disable maximum-heading-length -->

#### dcopyWithin.ndarray( N, target, start, end, x, strideX, offsetX, workspace, strideW, offsetW )

Performs an in-place copy of elements within a double-precision floating-point strided array using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var w = new Float64Array( x.length );

dcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0, w, 1, 0 );
// x => <Float64Array>[ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **offsetW**: starting index for `workspace`.

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 copy elements starting from the third element:

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var w = new Float64Array( 4 );

dcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2, w, 1, 0 );
// x => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 7.0, 8.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return the strided array unchanged.
- If `target >= N`, both functions return the strided array unchanged.
- If `start >= end`, both functions return the strided array unchanged.
- If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored.
- Both functions **mutate** the provided input strided array.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var zeros = require( '@stdlib/array/zeros' );
var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' );

var x = discreteUniform( 10, 0, 500, {
'dtype': 'float64'
});
console.log( x );

var w = zeros( 10, 'float64' );

// Copy the first 3 elements to positions 5, 6, 7:
dcopyWithin( 10, 5, 0, 3, x, 1, w, 1 );
console.log( x );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/ext/base/dcopy_within.h"
```

#### stdlib_strided_dcopy_within( N, target, start, end, \*X, strideX, \*W, strideW )

Performs an in-place copy of elements within a double-precision floating-point strided array.

```c
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
double w[ 6 ];

stdlib_strided_dcopy_within( 6, 3, 1, 4, x, 1, w, 1 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **target**: `[in] CBLAS_INT` target index.
- **start**: `[in] CBLAS_INT` source start index (inclusive).
- **end**: `[in] CBLAS_INT` source end index (exclusive).
- **X**: `[inout] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **W**: `[out] double*` workspace array. Must have at least `N` indexed elements.
- **strideW**: `[in] CBLAS_INT` stride length for `W`.

```c
void stdlib_strided_dcopy_within( const CBLAS_INT N, const CBLAS_INT target, const CBLAS_INT start, const CBLAS_INT end, double *X, const CBLAS_INT strideX, double *W, const CBLAS_INT strideW );
```

#### stdlib_strided_dcopy_within_ndarray( N, target, start, end, \*X, strideX, offsetX, \*W, strideW, offsetW )

Performs an in-place copy of elements within a double-precision floating-point strided array using alternative indexing semantics.

```c
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
double w[ 6 ];

stdlib_strided_dcopy_within_ndarray( 4, 2, 0, 2, x, 1, 1, w, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **target**: `[in] CBLAS_INT` target index.
- **start**: `[in] CBLAS_INT` source start index (inclusive).
- **end**: `[in] CBLAS_INT` source end index (exclusive).
- **X**: `[inout] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **W**: `[out] double*` workspace array. Must have at least `N` indexed elements.
- **strideW**: `[in] CBLAS_INT` stride length for `W`.
- **offsetW**: `[in] CBLAS_INT` starting index for `W`.

```c
void stdlib_strided_dcopy_within_ndarray( const CBLAS_INT N, const CBLAS_INT target, const CBLAS_INT start, const CBLAS_INT end, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *W, const CBLAS_INT strideW, const CBLAS_INT offsetW );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/ext/base/dcopy_within.h"
#include <stdio.h>

int main( void ) {
// Create a strided array:
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };

// Create a workspace array:
double w[ 8 ];

// Specify the number of indexed elements:
const int N = 8;

// Specify strides:
const int strideX = 1;
const int strideW = 1;

// Copy elements:
stdlib_strided_dcopy_within( N, 4, 1, 4, x, strideX, w, strideW );

// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "x[ %i ] = %lf\n", i, x[ i ] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
Loading