Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The function has the following parameters:
## Notes

- The input ndarray is copied **in-place** (i.e., the input ndarray is **mutated**).
- If a `target`, `start`, and/or `end` index is negative, the respective index is resolved by counting backward from the last element (where `-1` refers to the last element).
- If the `start` and `target` index ranges do not overlap, the `workspace` ndarray is unused and thus ignored.

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
The input ndarray is copied *in-place* (i.e., the input ndarray is
*mutated*).

If a `target`, `start`, and/or `end` index is negative, the respective
index is resolved by counting backward from the last element (where `-1`
refers to the last element).

If the `start` and `target` index ranges do not overlap, the `workspace`
ndarray is unused and thus ignored.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { typedndarray, complex64ndarray } from '@stdlib/types/ndarray';
* - a zero-dimensional ndarray specifying a source end index (exclusive).
* - a one-dimensional workspace ndarray.
*
* - If the `start` and `target` index ranges do not overlap, the `workspace` ndarray is unused and thus ignored.
*
* @param arrays - array-like object containing ndarrays
* @returns input ndarray
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' );
var clipIndex = require( '@stdlib/ndarray/base/clip-index' );
var getStride = require( '@stdlib/ndarray/base/stride' );
var getOffset = require( '@stdlib/ndarray/base/offset' );
var getData = require( '@stdlib/ndarray/base/data-buffer' );
Expand Down Expand Up @@ -72,24 +73,32 @@ var strided = require( '@stdlib/blas/ext/base/ccopy-within' ).ndarray;
* // returns <ndarray>[ <Complex64>[ 1.0, 2.0 ], <Complex64>[ 1.0, 2.0 ], <Complex64>[ 3.0, 4.0 ] ]
*/
function ccopyWithin( arrays ) {
var target;
var start;
var end;
var ws;
var wo;
var wd;
var xs;
var xo;
var xd;
var N;
var x;
var w;

x = arrays[ 0 ];
w = arrays[ 4 ];
N = numelDimension( x, 0 );
target = clipIndex( ndarraylike2scalar( arrays[ 1 ] ), N );
start = clipIndex( ndarraylike2scalar( arrays[ 2 ] ), N );
end = clipIndex( ndarraylike2scalar( arrays[ 3 ] ), N );
xd = getData( x );
xs = getStride( x, 0 );
xo = getOffset( x );
wd = getData( w );
ws = getStride( w, 0 );
wo = getOffset( w );
strided( numelDimension( x, 0 ), ndarraylike2scalar( arrays[ 1 ] ), ndarraylike2scalar( arrays[ 2 ] ), ndarraylike2scalar( arrays[ 3 ] ), xd, xs, xo, wd, ws, wo ); // eslint-disable-line max-len
strided( N, target, start, end, xd, xs, xo, wd, ws, wo );
return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,105 @@
t.end();
});

tape( 'the function supports a negative `target` index', function test( t ) {
var expected;
var actual;
var xbuf;
var wbuf;
var x;
var w;

xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
wbuf = new Complex64Array( 4 );

x = vector( xbuf, 4, 1, 0 );
w = vector( wbuf, 4, 1, 0 );

actual = ccopyWithin( [ x, scalar( -2 ), scalar( 0 ), scalar( 2 ), w ] );
expected = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0 ] );
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
wbuf = new Complex64Array( 3 );

x = vector( xbuf, 3, 1, 0 );
w = vector( wbuf, 3, 1, 0 );

actual = ccopyWithin( [ x, scalar( -100 ), scalar( 1 ), scalar( 3 ), w ] );
expected = new Complex64Array( [ 3.0, 4.0, 5.0, 6.0, 5.0, 6.0 ] );
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function supports a negative `start` index', function test( t ) {
var expected;
var actual;
var xbuf;
var wbuf;
var x;
var w;

xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
wbuf = new Complex64Array( 4 );

x = vector( xbuf, 4, 1, 0 );
w = vector( wbuf, 4, 1, 0 );

actual = ccopyWithin( [ x, scalar( 2 ), scalar( -4 ), scalar( 2 ), w ] );
expected = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0 ] );
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
wbuf = new Complex64Array( 3 );

x = vector( xbuf, 3, 1, 0 );
w = vector( wbuf, 3, 1, 0 );

actual = ccopyWithin( [ x, scalar( 1 ), scalar( -100 ), scalar( 3 ), w ] );
expected = new Complex64Array( [ 1.0, 2.0, 1.0, 2.0, 3.0, 4.0 ] );
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function supports a negative `end` index', function test( t ) {
var expected;
var actual;
var xbuf;
var wbuf;
var x;
var w;

xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
wbuf = new Complex64Array( 4 );

x = vector( xbuf, 4, 1, 0 );
w = vector( wbuf, 4, 1, 0 );

actual = ccopyWithin( [ x, scalar( 2 ), scalar( 0 ), scalar( -2 ), w ] );
expected = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0 ] );
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
wbuf = new Complex64Array( 4 );

x = vector( xbuf, 4, 1, 0 );
w = vector( wbuf, 4, 1, 0 );

actual = ccopyWithin( [ x, scalar( 0 ), scalar( 0 ), scalar( -100 ), w ] );
expected = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) {
var expected;
var actual;
Expand Down Expand Up @@ -308,14 +407,14 @@
var x;
var w;

xbuf = 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 ] );

Check warning on line 410 in lib/node_modules/@stdlib/blas/ext/base/ndarray/ccopy-within/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 99. Maximum allowed is 80
wbuf = new Complex64Array( 4 );

x = vector( xbuf, 4, -1, 4 );
w = vector( wbuf, 4, 1, 0 );

actual = ccopyWithin( [ x, scalar( 0 ), scalar( 2 ), scalar( 4 ), w ] );
expected = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 4.0, 5.0, 6.0, 11.0, 12.0 ] );

Check warning on line 417 in lib/node_modules/@stdlib/blas/ext/base/ndarray/ccopy-within/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 102. Maximum allowed is 80
t.strictEqual( actual, x, 'returns expected value' );
t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' );

Expand Down