From e4dfd1962861909c43e1cef698b4151660869c4b Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 10 Mar 2026 16:12:36 +0500 Subject: [PATCH 1/8] feat: add blas/ext/base/gcopy-within --- .../blas/ext/base/gcopy-within/README.md | 166 +++++++++ .../base/gcopy-within/benchmark/benchmark.js | 98 +++++ .../benchmark/benchmark.ndarray.js | 98 +++++ .../blas/ext/base/gcopy-within/docs/repl.txt | 111 ++++++ .../base/gcopy-within/docs/types/index.d.ts | 97 +++++ .../ext/base/gcopy-within/docs/types/test.ts | 171 +++++++++ .../ext/base/gcopy-within/examples/index.js | 35 ++ .../blas/ext/base/gcopy-within/lib/index.js | 59 +++ .../blas/ext/base/gcopy-within/lib/main.js | 53 +++ .../blas/ext/base/gcopy-within/lib/ndarray.js | 104 ++++++ .../blas/ext/base/gcopy-within/package.json | 68 ++++ .../blas/ext/base/gcopy-within/test/test.js | 38 ++ .../ext/base/gcopy-within/test/test.main.js | 346 ++++++++++++++++++ .../base/gcopy-within/test/test.ndarray.js | 317 ++++++++++++++++ 14 files changed, 1761 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md new file mode 100644 index 000000000000..732d38cebd16 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -0,0 +1,166 @@ + + +# gcopy-within + +> Perform an in-place copy of elements within a strided array. + +
+ +## Usage + +```javascript +var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); +``` + +#### gcopyWithin( N, target, start, end, x, strideX ) + +Performs an in-place copy of elements within a strided array. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +gcopyWithin( x.length, 3, 1, 4, x, 1 ); +// x => [ 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. +- **end**: source end index (exclusive). +- **x**: input array-like object. +- **strideX**: stride length. + +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 x = [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ]; + +gcopyWithin( 3, 0, 1, 6, x, 2 ); +// x => [ 3.0, 0.0, 5.0, 0.0, 7.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 + +// Copy within the view... +gcopyWithin( 3, 0, 2, 5, x1, 1 ); +// x0 => [ 1.0, 4.0, 5.0, 6.0, 5.0, 6.0, 7.0, 8.0 ] +``` + +#### gcopyWithin.ndarray( N, target, start, end, x, strideX, offsetX ) + +Performs an in-place copy of elements within a strided array using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); +// x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +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: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 1 ); +// x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the strided array unchanged. +- If `target >= N`, both functions return the strided array unchanged. +- Both functions **mutate** the provided input strided array. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); + +var x = discreteUniform( 10, 0, 500, { + 'dtype': 'generic' +}); +console.log( x ); + +// Copy the first 3 elements to positions 5, 6, 7: +gcopyWithin( 10, 5, 0, 3, x, 1 ); +console.log( x ); + +// Copy every other element starting from the second element: +gcopyWithin( 5, 0, 1, 9, x, 1 ); +console.log( x ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js new file mode 100644 index 000000000000..5ae5d0dab7d1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js @@ -0,0 +1,98 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var gcopyWithin = require( './../lib/main.js' ); +var pkg = require( './../package.json' ).name; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, { + 'dtype': 'generic' + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gcopyWithin( len, 0, 0, len-1, x, 1 ); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..b0bc8df5755f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js @@ -0,0 +1,98 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var gcopyWithin = require( './../lib/ndarray.js' ); +var pkg = require( './../package.json' ).name; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, { + 'dtype': 'generic' + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gcopyWithin( len, 0, 0, len-1, x, 1, 0 ); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt new file mode 100644 index 000000000000..b4afa956aab0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt @@ -0,0 +1,111 @@ + +{{alias}}( N, target, start, end, x, strideX ) + Performs an in-place copy of elements within a strided array. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns the strided array unchanged. + + If `target >= N`, the function returns the strided array unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + target: integer + Target index. + + start: integer + Source start index. + + end: integer + Source end index (exclusive). + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > {{alias}}( 3, 2, 1, 2, x, 1 ) + [ 1.0, 2.0, 2.0, 4.0, 5.0, 6.0 ] + + // Using `N` and stride parameters: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + > {{alias}}( 3, 0, 1, 6, x, 2 ) + [ 3.0, 2.0, 5.0, 4.0, 7.0, 6.0, 7.0, 8.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 2, 0, 2, 5, x1, 1 ) + [ 4.0, 5.0, 4.0, 5.0, 6.0 ] + > x0 + [ 1.0, 4.0, 5.0, 4.0, 5.0, 6.0 ] + + +{{alias}}.ndarray( N, target, start, end, x, strideX, offsetX ) + Performs an in-place copy of elements within a strided array using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + target: integer + Target index. + + start: integer + Source start index. + + end: integer + Source end index (exclusive). + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > {{alias}}.ndarray( 4, 2, 0, 2, x, 1, 1 ) + [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] + + // Using an index offset: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > {{alias}}.ndarray( 4, 3, 0, 1, x, 1, 2 ) + [ 1.0, 2.0, 3.0, 4.0, 5.0, 3.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts new file mode 100644 index 000000000000..3250bad5c7f1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts @@ -0,0 +1,97 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Interface describing `gcopyWithin`. +*/ +interface Routine { + /** + * Performs an in-place copy of elements within a strided array. + * + * @param N - number of indexed elements + * @param target - target index + * @param start - source start index + * @param end - source end index + * @param x - input array + * @param strideX - stride length + * @returns input array + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * + * gcopyWithin( x.length, 3, 1, 4, x, 1 ); + * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] + */ + ( N: number, target: number, start: number, end: number, x: Collection, strideX: number ): Collection; + + /** + * Performs an in-place copy of elements within a strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param target - target index + * @param start - source start index + * @param end - source end index + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns input array + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * + * gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); + * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] + */ + ndarray( N: number, target: number, start: number, end: number, x: Collection, strideX: number, offsetX: number ): Collection; +} + +/** +* Performs an in-place copy of elements within a strided array. +* +* @param N - number of indexed elements +* @param target - target index +* @param start - source start index +* @param end - source end index +* @param x - input array +* @param strideX - stride length +* @returns input array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcopyWithin( 6, 3, 1, 4, x, 1 ); +* // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcopyWithin.ndarray( 6, 3, 1, 4, x, 1, 0 ); +* // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ +declare var gcopyWithin: Routine; + + +// EXPORTS // + +export = gcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts new file mode 100644 index 000000000000..688c0e717567 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts @@ -0,0 +1,171 @@ +/* +* @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. +*/ + +import gcopyWithin = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, 1, 4, x, 1 ); // $ExpectType Collection +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( '3', 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( true, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( false, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( null, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( undefined, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( [], 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( {}, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( ( x: number ): number => x, 3, 1, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, '3', 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, true, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, false, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, null, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, undefined, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, [], 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, {}, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, ( x: number ): number => x, 1, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, '1', 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, true, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, false, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, null, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, undefined, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, [], 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, {}, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, ( x: number ): number => x, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, 1, '2', x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, true, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, false, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, null, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, undefined, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, [], x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, {}, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, 1, 2, 10, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, true, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, false, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, null, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, undefined, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, 1, 2, x, '4' ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, true ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, false ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, null ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, undefined ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, [] ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, {} ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + const x = new Float64Array( 10 ); + + gcopyWithin(); // $ExpectError + gcopyWithin( x.length ); // $ExpectError + gcopyWithin( x.length, 3 ); // $ExpectError + gcopyWithin( x.length, 3, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); // $ExpectType Collection +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcopyWithin.ndarray( '2', 3, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( true, 3, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( false, 3, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( null, 3, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( undefined, 3, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( [], 2, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( {}, 2, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( ( x: number ): number => x, 2, 1, 2, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 2, 10, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, true, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, false, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, null, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, undefined, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided insufficient arguments... +{ + const x = new Float64Array( 10 ); + + gcopyWithin.ndarray(); // $ExpectError + gcopyWithin.ndarray( x.length ); // $ExpectError + gcopyWithin.ndarray( x.length, 3 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js new file mode 100644 index 000000000000..0aa922b1510d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gcopyWithin = require( './../lib' ); + +var x = discreteUniform( 10, 0, 500, { + 'dtype': 'generic' +}); +console.log( x ); + +// Copy the first 3 elements to positions 5, 6, 7: +gcopyWithin( 10, 5, 0, 3, x, 1 ); +console.log( x ); + +// Copy every other element starting from the second element: +gcopyWithin( 5, 0, 1, 9, x, 1 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js new file mode 100644 index 000000000000..5a4ac36f1e08 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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. +*/ + +'use strict'; + +/** +* Perform an in-place copy of elements within a strided array. +* +* @module @stdlib/blas/ext/base/gcopy-within +* +* @example +* var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcopyWithin( x.length, 3, 1, 4, x, 1 ); +* // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +* +* @example +* var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); +* // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js new file mode 100644 index 000000000000..99ac580afe77 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js @@ -0,0 +1,53 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Performs an in-place copy of elements within a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} target - target index +* @param {integer} start - source start index +* @param {integer} end - source end index +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {Collection} input array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcopyWithin( x.length, 3, 1, 4, x, 1 ); +* // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ +function gcopyWithin( N, target, start, end, x, strideX ) { + return ndarray( N, target, start, end, x, strideX, stride2offset( N, strideX ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js new file mode 100644 index 000000000000..3d18294a3cd5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js @@ -0,0 +1,104 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var min = require( '@stdlib/math/base/special/min' ); +var max = require( '@stdlib/math/base/special/max' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; + + +// MAIN // + +/** +* Performs an in-place copy of elements within a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} target - target index +* @param {integer} start - source start index +* @param {integer} end - source end index +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {Collection} input array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcopyWithin( x.length, 3, 1, 4, x, 1, 0 ); +* // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ +function gcopyWithin( N, target, start, end, x, strideX, offsetX ) { + var flg; + var tei; + var sei; + var tsi; + var ssi; + var tmp; + var cl; + + if ( N <= 0 ) { + return x; + } + if ( target >= N ) { + return x; + } + + flg = false; + + // Resolve copy length: + cl = min( abs( end - start ), N ); + + if ( cl <= 0 ) { + return x; + } + + // Calculate source and target indices: + ssi = offsetX + ( start * strideX ); + sei = ssi + ( ( cl - 1 ) * strideX ); + tsi = offsetX + ( target * strideX ); + tei = tsi + ( ( cl - 1 ) * strideX ); + + // Check if source and target regions overlap: + if ( + !( max( ssi, sei ) < min( tsi, tei ) || + max( tsi, tei ) < min( ssi, sei ) ) + ) { + flg = true; + } + + if ( flg ) { + // Create a temporary copy of source elements: + tmp = []; + gcopy( cl, x, strideX, ssi, tmp, 1, 0 ); + + // Copy from temporary array to target position: + gcopy( cl, tmp, 1, 0, x, strideX, tsi ); + } else { + gcopy( cl, x, strideX, ssi, x, strideX, tsi ); + } + return x; +} + + +// EXPORTS // + +module.exports = gcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/package.json new file mode 100644 index 000000000000..321403385e27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/ext/base/gcopy-within", + "version": "0.0.0", + "description": "Perform an in-place copy of elements within a strided array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "copy", + "copywithin", + "within", + "move", + "strided", + "array", + "ndarray", + "generic" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.js new file mode 100644 index 000000000000..aca07397b274 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.js @@ -0,0 +1,38 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var gcopyWithin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gcopyWithin.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js new file mode 100644 index 000000000000..6a440903b158 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js @@ -0,0 +1,346 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gcopyWithin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gcopyWithin.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided strided array', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + actual = gcopyWithin( 6, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 4, 5, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies values within the provided strided array (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + actual = gcopyWithin( 6, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles overlapping copy regions', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + + actual = gcopyWithin( 5, 2, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles overlapping copy regions (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + + actual = gcopyWithin( 5, 2, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a stride parameter', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 2, 0, 1, 4, x, 2 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + x = toAccessorArray( buf ); + expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 2, 0, 1, 4, x, 2 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing negative strides', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 3, 0, 1, 3, x, -1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 4, 0, 2, 4, x, -1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing negative strides (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 3, 0, 1, 3, x, -1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 0, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0` (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 0, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N`', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N` (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `start` equals `end`', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 0, 2, 2, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `start` equals `end` (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 0, 2, 2, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var x1; + + // Initial array... + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, // 3 + 6.0, // 4 + 7.0, + 8.0 + ]); + + // Create offset view... + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + gcopyWithin( 3, 0, 2, 5, x1, 1 ); + + expected = new Float64Array( [ 1.0, 4.0, 5.0, 6.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.deepEqual( x0, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js new file mode 100644 index 000000000000..c7e6b2df2db6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js @@ -0,0 +1,317 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gcopyWithin = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gcopyWithin.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided strided array', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + actual = gcopyWithin( 6, 3, 1, 4, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + + actual = gcopyWithin( 5, 2, 0, 3, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies values within the provided strided array (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + actual = gcopyWithin( 6, 3, 1, 4, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an offset parameter', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 2.0, 3.0 ]; + + actual = gcopyWithin( 4, 3, 0, 2, x, 1, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing an offset parameter (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 2.0, 3.0 ]; + + actual = gcopyWithin( 4, 3, 0, 2, x, 1, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a stride parameter', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 2, 0, 1, 4, x, 2, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + x = toAccessorArray( buf ); + expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 2, 0, 1, 4, x, 2, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing negative strides', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 4, 0, 2, 4, x, -1, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing negative strides (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0` (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N`', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N` (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `start` equals `end`', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `start` equals `end` (accessors)', function test( t ) { + var expected; + var actual; + var buf; + var x; + + buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = toAccessorArray( buf ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + t.end(); +}); From 7632a5e24e2be92b4f447f7dfa15465ad8767472 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 12 Mar 2026 03:23:11 +0500 Subject: [PATCH 2/8] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md | 2 +- .../@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js | 2 +- .../blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js | 2 +- .../@stdlib/blas/ext/base/gcopy-within/test/test.main.js | 3 +++ .../@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js | 3 +++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md index 732d38cebd16..abbe588cdcb1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -134,7 +134,7 @@ console.log( x ); gcopyWithin( 10, 5, 0, 3, x, 1 ); console.log( x ); -// Copy every other element starting from the second element: +// Copy elements starting from source index 1 to target index 0: gcopyWithin( 5, 0, 1, 9, x, 1 ); console.log( x ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js index 5ae5d0dab7d1..0a07f53a4068 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js @@ -56,7 +56,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = gcopyWithin( len, 0, 0, len-1, x, 1 ); + y = gcopyWithin( len, 0, 0, len - 1, x, 1 ); if ( isnan( y[ i%y.length ] ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js index b0bc8df5755f..142a4241ec9c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js @@ -56,7 +56,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = gcopyWithin( len, 0, 0, len-1, x, 1, 0 ); + y = gcopyWithin( len, 0, 0, len - 1, x, 1, 0 ); if ( isnan( y[ i%y.length ] ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js index 6a440903b158..bda1d28cb238 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js @@ -56,7 +56,10 @@ tape( 'the function copies values within the provided strided array', function t expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js index c7e6b2df2db6..bfe43b29c8b7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js @@ -55,7 +55,10 @@ tape( 'the function copies values within the provided strided array', function t expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); From abf6771e445b74adac432743431966a439b1ceb0 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 22 Jul 2026 17:37:29 +0500 Subject: [PATCH 3/8] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/gcopy-within/README.md | 21 +- .../blas/ext/base/gcopy-within/docs/repl.txt | 18 +- .../ext/base/gcopy-within/examples/index.js | 4 - .../blas/ext/base/gcopy-within/lib/main.js | 6 +- .../blas/ext/base/gcopy-within/lib/ndarray.js | 51 +--- .../ext/base/gcopy-within/test/test.main.js | 226 ++++++++--------- .../base/gcopy-within/test/test.ndarray.js | 231 ++++++++++-------- 7 files changed, 285 insertions(+), 272 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md index abbe588cdcb1..e4c47f633028 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -46,7 +46,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **target**: target index. - **start**: source start index. -- **end**: source end index (exclusive). +- **end**: source end index. - **x**: input array-like object. - **strideX**: stride length. @@ -56,7 +56,7 @@ The `N` and stride parameters determine which elements in the strided array are var x = [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ]; gcopyWithin( 3, 0, 1, 6, x, 2 ); -// x => [ 3.0, 0.0, 5.0, 0.0, 7.0, 0.0, 7.0, 0.0 ] +// x => [ 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. @@ -71,8 +71,8 @@ var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element // Copy within the view... -gcopyWithin( 3, 0, 2, 5, x1, 1 ); -// x0 => [ 1.0, 4.0, 5.0, 6.0, 5.0, 6.0, 7.0, 8.0 ] +gcopyWithin( 6, 0, 3, 6, x1, 1 ); +// x0 => [ 1.0, 5.0, 6.0, 7.0, 5.0, 6.0, 7.0, 8.0 ] ``` #### gcopyWithin.ndarray( N, target, start, end, x, strideX, offsetX ) @@ -90,13 +90,13 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. -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: +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 third element: ```javascript -var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; -gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 1 ); -// x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] +gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2 ); +// x => [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 7.0, 8.0 ] ``` @@ -109,6 +109,7 @@ gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 1 ); - 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. - Both functions **mutate** the provided input strided array. @@ -133,10 +134,6 @@ console.log( x ); // Copy the first 3 elements to positions 5, 6, 7: gcopyWithin( 10, 5, 0, 3, x, 1 ); console.log( x ); - -// Copy elements starting from source index 1 to target index 0: -gcopyWithin( 5, 0, 1, 9, x, 1 ); -console.log( x ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt index b4afa956aab0..34597e322eb3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt @@ -12,6 +12,8 @@ If `target >= N`, the function returns the strided array unchanged. + If `start >= end`, the function returns the strided array unchanged. + Parameters ---------- N: integer @@ -24,7 +26,7 @@ Source start index. end: integer - Source end index (exclusive). + Source end index. x: ArrayLikeObject Input array. @@ -41,18 +43,18 @@ -------- // Standard Usage: > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - > {{alias}}( 3, 2, 1, 2, x, 1 ) - [ 1.0, 2.0, 2.0, 4.0, 5.0, 6.0 ] + > {{alias}}( 6, 3, 1, 4, x, 1 ) + [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] // Using `N` and stride parameters: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; > {{alias}}( 3, 0, 1, 6, x, 2 ) - [ 3.0, 2.0, 5.0, 4.0, 7.0, 6.0, 7.0, 8.0 ] + [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 2, 0, 2, 5, x1, 1 ) + > {{alias}}( 4, 0, 2, 4, x1, 1 ) [ 4.0, 5.0, 4.0, 5.0, 6.0 ] > x0 [ 1.0, 4.0, 5.0, 4.0, 5.0, 6.0 ] @@ -78,7 +80,7 @@ Source start index. end: integer - Source end index (exclusive). + Source end index. x: ArrayLikeObject Input array. @@ -103,8 +105,8 @@ // Using an index offset: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - > {{alias}}.ndarray( 4, 3, 0, 1, x, 1, 2 ) - [ 1.0, 2.0, 3.0, 4.0, 5.0, 3.0 ] + > {{alias}}.ndarray( 3, 1, 0, 2, x, 1, 2 ) + [ 1.0, 2.0, 3.0, 3.0, 4.0, 6.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js index 0aa922b1510d..6f811c01ec37 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js @@ -29,7 +29,3 @@ console.log( x ); // Copy the first 3 elements to positions 5, 6, 7: gcopyWithin( 10, 5, 0, 3, x, 1 ); console.log( x ); - -// Copy every other element starting from the second element: -gcopyWithin( 5, 0, 1, 9, x, 1 ); -console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js index 99ac580afe77..97a575c6cff7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js @@ -30,9 +30,9 @@ var ndarray = require( './ndarray.js' ); * Performs an in-place copy of elements within a strided array. * * @param {PositiveInteger} N - number of indexed elements -* @param {integer} target - target index -* @param {integer} start - source start index -* @param {integer} end - source end index +* @param {NonNegativeInteger} target - target index +* @param {NonNegativeInteger} start - source start index +* @param {NonNegativeInteger} end - source end index * @param {Collection} x - input array * @param {integer} strideX - stride length * @returns {Collection} input array diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js index 3d18294a3cd5..dfeb9c9400bf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js @@ -21,8 +21,6 @@ // MODULES // var min = require( '@stdlib/math/base/special/min' ); -var max = require( '@stdlib/math/base/special/max' ); -var abs = require( '@stdlib/math/base/special/abs' ); var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; @@ -32,9 +30,9 @@ var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; * Performs an in-place copy of elements within a strided array. * * @param {PositiveInteger} N - number of indexed elements -* @param {integer} target - target index -* @param {integer} start - source start index -* @param {integer} end - source end index +* @param {NonNegativeInteger} target - target index +* @param {NonNegativeInteger} start - source start index +* @param {NonNegativeInteger} end - source end index * @param {Collection} x - input array * @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index @@ -47,54 +45,31 @@ var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ function gcopyWithin( N, target, start, end, x, strideX, offsetX ) { - var flg; - var tei; - var sei; - var tsi; - var ssi; var tmp; + var ssi; + var tsi; var cl; - if ( N <= 0 ) { + if ( N <= 0 || strideX === 0 || target >= N ) { return x; } - if ( target >= N ) { - return x; - } - - flg = false; - - // Resolve copy length: - cl = min( abs( end - start ), N ); - + // Resolve the number of elements to copy: + cl = min( min( end, N ) - start, N - target ); if ( cl <= 0 ) { return x; } - - // Calculate source and target indices: + // Resolve the starting source and target indices... ssi = offsetX + ( start * strideX ); - sei = ssi + ( ( cl - 1 ) * strideX ); tsi = offsetX + ( target * strideX ); - tei = tsi + ( ( cl - 1 ) * strideX ); - // Check if source and target regions overlap: - if ( - !( max( ssi, sei ) < min( tsi, tei ) || - max( tsi, tei ) < min( ssi, sei ) ) - ) { - flg = true; - } - - if ( flg ) { - // Create a temporary copy of source elements: + // When the source and target index ranges overlap, copying directly could overwrite source elements before they are read, and, thus, we first copy the source elements to a temporary array: + if ( start < target + cl && target < start + cl ) { tmp = []; gcopy( cl, x, strideX, ssi, tmp, 1, 0 ); - - // Copy from temporary array to target position: gcopy( cl, tmp, 1, 0, x, strideX, tsi ); - } else { - gcopy( cl, x, strideX, ssi, x, strideX, tsi ); + return x; } + gcopy( cl, x, strideX, ssi, x, strideX, tsi ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js index bda1d28cb238..b08a22505edc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js @@ -23,7 +23,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var gcopyWithin = require( './../lib' ); +var gcopyWithin = require( './../lib/main.js' ); // TESTS // @@ -53,20 +53,17 @@ tape( 'the function copies values within the provided strided array', function t t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( x, expected, 'returns expected value' ); + actual = gcopyWithin( 6, 3, 0, 3, x, 1 ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 4, 5, 0, 3, x, 1 ); + actual = gcopyWithin( 5, 2, 0, 5, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -76,186 +73,208 @@ tape( 'the function copies values within the provided strided array', function t tape( 'the function copies values within the provided strided array (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; - actual = gcopyWithin( 6, 3, 1, 4, x, 1 ); + gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + + gcopyWithin( 5, 2, 0, 5, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function handles overlapping copy regions', function test( t ) { +tape( 'if provided `target` parameter is greater than or equal to the `N` parameter, the function returns the strided array unchanged', function test( t ) { var expected; var actual; var x; - x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 5, 2, 0, 3, x, 1 ); + actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( 4, 5, 0, 3, x, 1 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); }); -tape( 'the function handles overlapping copy regions (accessors)', function test( t ) { +tape( 'if provided `target` parameter is greater than or equal to the `N` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 5, 2, 0, 3, x, 1 ); + gcopyWithin( 6, 6, 0, 3, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcopyWithin( 6, 10, 0, 3, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing a stride parameter', function test( t ) { +tape( 'if provided `N` parameter is less than or equal to `0`, the function returns the strided array unchanged', function test( t ) { var expected; var actual; var x; - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 2, 0, 1, 4, x, 2 ); + actual = gcopyWithin( 0, 3, 1, 4, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); }); -tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { +tape( 'if provided `N` parameter is less than or equal to `0`, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - x = toAccessorArray( buf ); - expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 2, 0, 1, 4, x, 2 ); + gcopyWithin( 0, 3, 1, 4, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcopyWithin( -1, 3, 1, 4, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing negative strides', function test( t ) { +tape( 'if provided `start` parameter is greater than or equal to the `end` parameter, the function returns the strided array unchanged', function test( t ) { var expected; var actual; var x; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 3, 0, 1, 3, x, -1 ); + actual = gcopyWithin( 6, 0, 3, 1, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 4, 0, 2, 4, x, -1 ); + actual = gcopyWithin( 6, 0, 2, 2, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - t.end(); }); -tape( 'the function supports providing negative strides (accessors)', function test( t ) { +tape( 'if provided `start` parameter is greater than or equal to the `end` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - - actual = gcopyWithin( 3, 0, 1, 3, x, -1 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + gcopyWithin( 6, 0, 3, 1, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', function test( t ) { +tape( 'if provided `end` parameter is greater than the number of indexed elements, the function copies elements up to the last indexed element', function test( t ) { var expected; var actual; var x; - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; - actual = gcopyWithin( 0, 3, 1, 4, x, 1 ); + actual = gcopyWithin( 5, 0, 2, 10, x, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); - actual = gcopyWithin( -1, 3, 1, 4, x, 1 ); +tape( 'if provided `end` parameter is greater than the number of indexed elements, the function copies elements up to the last indexed element (accessors)', function test( t ) { + var expected; + var x; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( x, expected, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; + gcopyWithin( 5, 0, 2, 10, toAccessorArray( x ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0` (accessors)', function test( t ) { +tape( 'the function supports providing a stride parameter', function test( t ) { var expected; var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - actual = gcopyWithin( 0, 3, 1, 4, x, 1 ); + actual = gcopyWithin( 4, 0, 2, 4, x, 2 ); t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); - actual = gcopyWithin( -1, 3, 1, 4, x, 1 ); +tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { + var expected; + var x; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), 2 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N`', function test( t ) { +tape( 'the function supports providing negative strides', function test( t ) { var expected; var actual; var x; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + actual = gcopyWithin( 3, 0, 1, 3, x, -1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 4, 0, 2, 4, x, -1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -263,30 +282,26 @@ tape( 'the function returns the strided array unchanged if `target` is greater t t.end(); }); -tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N` (accessors)', function test( t ) { +tape( 'the function supports providing negative strides (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + gcopyWithin( 3, 0, 1, 3, toAccessorArray( x ), -1 ); + t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), -1 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `start` equals `end`', function test( t ) { +tape( 'the function supports a stride of zero', function test( t ) { var expected; var actual; var x; @@ -294,29 +309,22 @@ tape( 'the function returns the strided array unchanged if `start` equals `end`' x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 2, 2, x, 1 ); + actual = gcopyWithin( 6, 1, 0, 2, x, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - t.end(); }); -tape( 'the function returns the strided array unchanged if `start` equals `end` (accessors)', function test( t ) { +tape( 'the function supports a stride of zero (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 2, 2, x, 1 ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); - + gcopyWithin( 6, 1, 0, 2, toAccessorArray( x ), 0 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); @@ -333,16 +341,16 @@ tape( 'the function supports view offsets', function test( t ) { 4.0, // 2 5.0, // 3 6.0, // 4 - 7.0, + 7.0, // 5 8.0 ]); // Create offset view... x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element - gcopyWithin( 3, 0, 2, 5, x1, 1 ); + gcopyWithin( 6, 0, 3, 6, x1, 1 ); - expected = new Float64Array( [ 1.0, 4.0, 5.0, 6.0, 5.0, 6.0, 7.0, 8.0 ] ); + expected = new Float64Array( [ 1.0, 5.0, 6.0, 7.0, 5.0, 6.0, 7.0, 8.0 ] ); t.deepEqual( x0, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js index bfe43b29c8b7..cb7269d9784d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js @@ -52,20 +52,17 @@ tape( 'the function copies values within the provided strided array', function t t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( x, expected, 'returns expected value' ); + actual = gcopyWithin( 6, 3, 0, 3, x, 1, 0 ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 5, 2, 0, 3, x, 1, 0 ); + actual = gcopyWithin( 5, 2, 0, 5, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -75,186 +72,208 @@ tape( 'the function copies values within the provided strided array', function t tape( 'the function copies values within the provided strided array (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; - actual = gcopyWithin( 6, 3, 1, 4, x, 1, 0 ); + gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; + + gcopyWithin( 5, 2, 0, 5, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing an offset parameter', function test( t ) { +tape( 'if provided `target` parameter is greater than or equal to the `N` parameter, the function returns the strided array unchanged', function test( t ) { var expected; var actual; var x; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 2.0, 3.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 4, 3, 0, 2, x, 1, 1 ); + actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( 4, 5, 0, 3, x, 1, 0 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); }); -tape( 'the function supports providing an offset parameter (accessors)', function test( t ) { +tape( 'if provided `target` parameter is greater than or equal to the `N` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 3.0, 4.0, 2.0, 3.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + gcopyWithin( 6, 6, 0, 3, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 4, 3, 0, 2, x, 1, 1 ); + gcopyWithin( 6, 10, 0, 3, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing a stride parameter', function test( t ) { +tape( 'if provided `N` parameter is less than or equal to `0`, the function returns the strided array unchanged', function test( t ) { var expected; var actual; var x; - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0 ); - actual = gcopyWithin( 2, 0, 1, 4, x, 2, 0 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + t.end(); }); -tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { +tape( 'if provided `N` parameter is less than or equal to `0`, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - x = toAccessorArray( buf ); - expected = [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 2, 0, 1, 4, x, 2, 0 ); + gcopyWithin( 0, 3, 1, 4, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcopyWithin( -1, 3, 1, 4, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing negative strides', function test( t ) { +tape( 'if provided `start` parameter is greater than or equal to the `end` parameter, the function returns the strided array unchanged', function test( t ) { var expected; var actual; var x; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2 ); + actual = gcopyWithin( 6, 0, 3, 1, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 4, 0, 2, 4, x, -1, 3 ); + actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - t.end(); }); -tape( 'the function supports providing negative strides (accessors)', function test( t ) { +tape( 'if provided `start` parameter is greater than or equal to the `end` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - - actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + gcopyWithin( 6, 0, 3, 1, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', function test( t ) { +tape( 'if provided `end` parameter is greater than the number of indexed elements, the function copies elements up to the last indexed element', function test( t ) { var expected; var actual; var x; - x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; - actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0 ); + actual = gcopyWithin( 5, 0, 2, 10, x, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); - actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0 ); +tape( 'if provided `end` parameter is greater than the number of indexed elements, the function copies elements up to the last indexed element (accessors)', function test( t ) { + var expected; + var x; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( x, expected, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; + gcopyWithin( 5, 0, 2, 10, toAccessorArray( x ), 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0` (accessors)', function test( t ) { +tape( 'the function supports providing a stride parameter', function test( t ) { var expected; var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0 ); + actual = gcopyWithin( 4, 0, 2, 4, x, 2, 0 ); t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); - actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0 ); +tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { + var expected; + var x; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), 2, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N`', function test( t ) { +tape( 'the function supports providing negative strides', function test( t ) { var expected; var actual; var x; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; + + actual = gcopyWithin( 4, 0, 2, 4, x, -1, 3 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -262,30 +281,26 @@ tape( 'the function returns the strided array unchanged if `target` is greater t t.end(); }); -tape( 'the function returns the strided array unchanged if `target` is greater than or equal to `N` (accessors)', function test( t ) { +tape( 'the function supports providing negative strides (accessors)', function test( t ) { var expected; - var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + gcopyWithin( 3, 0, 1, 3, toAccessorArray( x ), -1, 2 ); + t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; - t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), -1, 3 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `start` equals `end`', function test( t ) { +tape( 'the function supports a stride of zero', function test( t ) { var expected; var actual; var x; @@ -293,28 +308,48 @@ tape( 'the function returns the strided array unchanged if `start` equals `end`' x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0 ); + actual = gcopyWithin( 6, 1, 0, 2, x, 0, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a stride of zero (accessors)', function test( t ) { + var expected; + var x; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + + gcopyWithin( 6, 1, 0, 2, toAccessorArray( x ), 0, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns the strided array unchanged if `start` equals `end` (accessors)', function test( t ) { +tape( 'the function supports providing an offset parameter', function test( t ) { var expected; var actual; - var buf; var x; - buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - x = toAccessorArray( buf ); - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0 ); + actual = gcopyWithin( 4, 2, 0, 2, x, 1, 1 ); t.strictEqual( actual, x, 'returns expected value' ); - t.deepEqual( buf, expected, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); +tape( 'the function supports providing an offset parameter (accessors)', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ]; + + gcopyWithin( 4, 2, 0, 2, toAccessorArray( x ), 1, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); From b9099a982c528887e828f74ca62b11b8fb3a424f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 30 Jul 2026 19:26:30 +0500 Subject: [PATCH 4/8] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/gcopy-within/README.md | 46 ++- .../base/gcopy-within/benchmark/benchmark.js | 18 +- .../benchmark/benchmark.ndarray.js | 18 +- .../blas/ext/base/gcopy-within/docs/repl.txt | 48 ++- .../base/gcopy-within/docs/types/index.d.ts | 56 +++- .../ext/base/gcopy-within/docs/types/test.ts | 292 ++++++++++++++---- .../ext/base/gcopy-within/examples/index.js | 5 +- .../blas/ext/base/gcopy-within/lib/index.js | 6 +- .../blas/ext/base/gcopy-within/lib/main.js | 20 +- .../blas/ext/base/gcopy-within/lib/ndarray.js | 24 +- .../ext/base/gcopy-within/test/test.main.js | 151 ++++++--- .../base/gcopy-within/test/test.ndarray.js | 211 ++++++++++--- 12 files changed, 692 insertions(+), 203 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md index e4c47f633028..1ccedff79d68 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# gcopy-within +# gcopyWithin > Perform an in-place copy of elements within a strided array. @@ -30,14 +30,15 @@ limitations under the License. var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); ``` -#### gcopyWithin( N, target, start, end, x, strideX ) +#### gcopyWithin( N, target, start, end, x, strideX, workspace, strideW ) Performs an in-place copy of elements within a strided array. ```javascript var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; -gcopyWithin( x.length, 3, 1, 4, x, 1 ); +gcopyWithin( x.length, 3, 1, 4, x, 1, w, 1 ); // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] ``` @@ -48,14 +49,17 @@ The function has the following parameters: - **start**: source start index. - **end**: source end index. - **x**: input array-like object. -- **strideX**: stride length. +- **strideX**: stride length for `x`. +- **workspace**: workspace array. Must have `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 x = [ 1.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0 ]; +var w = [ 0.0, 0.0, 0.0 ]; -gcopyWithin( 3, 0, 1, 6, x, 2 ); +gcopyWithin( 3, 0, 1, 6, x, 2, w, 1 ); // x => [ 3.0, 0.0, 5.0, 0.0, 5.0, 0.0, 7.0, 0.0 ] ``` @@ -70,32 +74,40 @@ 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... -gcopyWithin( 6, 0, 3, 6, x1, 1 ); +gcopyWithin( 6, 0, 3, 6, x1, 1, w, 1 ); // x0 => [ 1.0, 5.0, 6.0, 7.0, 5.0, 6.0, 7.0, 8.0 ] ``` -#### gcopyWithin.ndarray( N, target, start, end, x, strideX, offsetX ) + + +#### gcopyWithin.ndarray( N, target, start, end, x, strideX, offsetX, workspace, strideW, offsetW ) Performs an in-place copy of elements within a strided array using alternative indexing semantics. ```javascript var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; -gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); +gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0, w, 1, 0 ); // x => [ 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 parameter supports indexing semantics based on a starting index. For example, to copy elements starting from the third element: +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 x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0 ]; -gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2 ); +gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2, w, 1, 0 ); // x => [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 7.0, 8.0 ] ``` @@ -110,7 +122,10 @@ gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2 ); - 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. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dcopyWithin`][@stdlib/blas/ext/base/dcopy-within], [`scopyWithin`][@stdlib/blas/ext/base/scopy-within], etc.) are likely to be significantly more performant. @@ -124,6 +139,7 @@ gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2 ); ```javascript var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); var x = discreteUniform( 10, 0, 500, { @@ -131,8 +147,10 @@ var x = discreteUniform( 10, 0, 500, { }); console.log( x ); +var w = zeros( 10, 'generic' ); + // Copy the first 3 elements to positions 5, 6, 7: -gcopyWithin( 10, 5, 0, 3, x, 1 ); +gcopyWithin( 10, 5, 0, 3, x, 1, w, 1 ); console.log( x ); ``` @@ -154,6 +172,12 @@ console.log( x ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor + +[@stdlib/blas/ext/base/dcopy-within]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dcopy-within + +[@stdlib/blas/ext/base/scopy-within]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/scopy-within + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js index 0a07f53a4068..18b1c7a9826c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); @@ -29,6 +30,13 @@ var gcopyWithin = require( './../lib/main.js' ); var pkg = require( './../package.json' ).name; +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -39,9 +47,11 @@ var pkg = require( './../package.json' ).name; * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, { - 'dtype': 'generic' - }); + var x; + var w; + + x = uniform( len, -10.0, 10.0, options ); + w = zeros( len, options.dtype ); return benchmark; /** @@ -56,7 +66,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = gcopyWithin( len, 0, 0, len - 1, x, 1 ); + y = gcopyWithin( len, 0, 0, len - 1, x, 1, w, 1 ); if ( isnan( y[ i%y.length ] ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js index 142a4241ec9c..0c6cb98cd8bb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); @@ -29,6 +30,13 @@ var gcopyWithin = require( './../lib/ndarray.js' ); var pkg = require( './../package.json' ).name; +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -39,9 +47,11 @@ var pkg = require( './../package.json' ).name; * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, { - 'dtype': 'generic' - }); + var x; + var w; + + x = uniform( len, -10.0, 10.0, options ); + w = zeros( len, options.dtype ); return benchmark; /** @@ -56,7 +66,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = gcopyWithin( len, 0, 0, len - 1, x, 1, 0 ); + y = gcopyWithin( len, 0, 0, len - 1, x, 1, 0, w, 1, 0 ); if ( isnan( y[ i%y.length ] ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt index 34597e322eb3..0a99c7d73ea1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, target, start, end, x, strideX ) +{{alias}}( N, target, start, end, x, strideX, w, strideW ) Performs an in-place copy of elements within a strided array. The `N` and stride parameters determine which elements in the strided array @@ -14,6 +14,9 @@ If `start >= end`, the function returns the strided array unchanged. + If the `start` and `target` index ranges do not overlap, the `workspace` + array is unused and thus ignored. + Parameters ---------- N: integer @@ -32,7 +35,13 @@ Input array. strideX: integer - Stride length. + Stride length for `x`. + + w: ArrayLikeObject + Workspace array. Must have `N` indexed elements. + + strideW: integer + Stride length for `w`. Returns ------- @@ -43,30 +52,33 @@ -------- // Standard Usage: > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - > {{alias}}( 6, 3, 1, 4, x, 1 ) + > var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 6, 3, 1, 4, x, 1, w, 1 ) [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] // Using `N` and stride parameters: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - > {{alias}}( 3, 0, 1, 6, x, 2 ) + > w = [ 0.0, 0.0, 0.0 ]; + > {{alias}}( 3, 0, 1, 6, x, 2, w, 1 ) [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 4, 0, 2, 4, x1, 1 ) + > var w0 = new {{alias:@stdlib/array/float64}}( 4 ); + > {{alias}}( 4, 0, 2, 4, x1, 1, w0, 1 ) [ 4.0, 5.0, 4.0, 5.0, 6.0 ] > x0 [ 1.0, 4.0, 5.0, 4.0, 5.0, 6.0 ] -{{alias}}.ndarray( N, target, start, end, x, strideX, offsetX ) +{{alias}}.ndarray( N, target, start, end, x,strideX,offsetX, w,strideW,offsetW ) Performs an in-place copy of elements within a strided array using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the offset parameter supports indexing semantics based on a - starting index. + buffer, the offset parameters support indexing semantics based on starting + indices. Parameters ---------- @@ -86,10 +98,19 @@ Input array. strideX: integer - Stride length. + Stride length for `x`. offsetX: integer - Starting index. + Starting index for `x`. + + w: ArrayLikeObject + Workspace array. Must have `N` indexed elements. + + strideW: integer + Stride length for `w`. + + offsetW: integer + Starting index for `w`. Returns ------- @@ -100,14 +121,15 @@ -------- // Standard Usage: > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - > {{alias}}.ndarray( 4, 2, 0, 2, x, 1, 1 ) + > var w = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 4, 2, 0, 2, x, 1, 1, w, 1, 0 ) [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] // Using an index offset: > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - > {{alias}}.ndarray( 3, 1, 0, 2, x, 1, 2 ) + > w = [ 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, 1, 0, 2, x, 1, 2, w, 1, 0 ) [ 1.0, 2.0, 3.0, 3.0, 4.0, 6.0 ] See Also -------- - diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts index 3250bad5c7f1..7b43a953bbde 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts @@ -20,7 +20,12 @@ /// -import { Collection } from '@stdlib/types/array'; +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; /** * Interface describing `gcopyWithin`. @@ -29,64 +34,87 @@ interface Routine { /** * Performs an in-place copy of elements within a strided array. * + * ## Notes + * + * - If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored. + * * @param N - number of indexed elements * @param target - target index * @param start - source start index * @param end - source end index * @param x - input array - * @param strideX - stride length - * @returns input array + * @param strideX - stride length for `x` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @returns `x` * * @example * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * - * gcopyWithin( x.length, 3, 1, 4, x, 1 ); + * gcopyWithin( x.length, 3, 1, 4, x, 1, w, 1 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ - ( N: number, target: number, start: number, end: number, x: Collection, strideX: number ): Collection; + = InputArray>( N: number, target: number, start: number, end: number, x: U, strideX: number, workspace: InputArray, strideW: number ): U; /** * Performs an in-place copy of elements within a strided array using alternative indexing semantics. * + * ## Notes + * + * - If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored. + * * @param N - number of indexed elements * @param target - target index * @param start - source start index * @param end - source end index * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @param offsetW - starting index for `workspace` + * @returns `x` * * @example * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * - * gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); + * gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0, w, 1, 0 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ - ndarray( N: number, target: number, start: number, end: number, x: Collection, strideX: number, offsetX: number ): Collection; + ndarray = InputArray>( N: number, target: number, start: number, end: number, x: U, strideX: number, offsetX: number, workspace: InputArray, strideW: number, offsetW: number ): U; } /** * Performs an in-place copy of elements within a strided array. * +* ## Notes +* +* - If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored. +* * @param N - number of indexed elements * @param target - target index * @param start - source start index * @param end - source end index * @param x - input array -* @param strideX - stride length -* @returns input array +* @param strideX - stride length for `x` +* @param workspace - workspace array +* @param strideW - stride length for `workspace` +* @returns `x` * * @example * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * -* gcopyWithin( 6, 3, 1, 4, x, 1 ); +* gcopyWithin( 6, 3, 1, 4, x, 1, w, 1 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] * * @example * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * -* gcopyWithin.ndarray( 6, 3, 1, 4, x, 1, 0 ); +* gcopyWithin.ndarray( 6, 3, 1, 4, x, 1, 0, w, 1, 0 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ declare var gcopyWithin: Routine; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts index 688c0e717567..58862739cca7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts @@ -16,6 +16,7 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import gcopyWithin = require( './index' ); @@ -24,95 +25,131 @@ import gcopyWithin = require( './index' ); // The function returns a collection... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( x.length, 3, 1, 4, x, 1 ); // $ExpectType Collection + gcopyWithin( x.length, 3, 1, 4, x, 1, w, 1 ); // $ExpectType Float64Array + gcopyWithin( x.length, 3, 1, 4, new AccessorArray( x ), 1, w, 1 ); // $ExpectType AccessorArray } // The compiler throws an error if the function is provided a first argument which is not a number... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( '3', 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( true, 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( false, 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( null, 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( undefined, 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( [], 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( {}, 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( ( x: number ): number => x, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( '3', 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( true, 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( false, 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( null, 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( undefined, 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( [], 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( {}, 3, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( ( x: number ): number => x, 3, 1, 2, x, 1, w, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a number... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( x.length, '3', 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, true, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, false, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, null, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, undefined, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, [], 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, {}, 1, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, ( x: number ): number => x, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, '3', 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, true, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, false, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, null, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, undefined, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, [], 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, {}, 1, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, ( x: number ): number => x, 1, 2, x, 1, w, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a third argument which is not a number... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( x.length, 3, '1', 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, true, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, false, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, null, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, undefined, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, [], 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, {}, 2, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, ( x: number ): number => x, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, '1', 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, true, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, false, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, null, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, undefined, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, [], 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, {}, 2, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, ( x: number ): number => x, 2, x, 1, w, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a fourth argument which is not a number... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( x.length, 3, 1, '2', x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, true, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, false, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, null, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, undefined, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, [], x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, {}, x, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, ( x: number ): number => x, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, '2', x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, true, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, false, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, null, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, undefined, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, [], x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, {}, x, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, ( x: number ): number => x, x, 1, w, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a fifth argument which is not a collection... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( x.length, 3, 1, 2, 10, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, true, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, false, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, null, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, undefined, 1 ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, {}, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, 10, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, true, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, false, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, null, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, undefined, 1, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, {}, 1, w, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a sixth argument which is not a number... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin( x.length, 3, 1, 2, x, '4' ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, true ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, false ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, null ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, undefined ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, [] ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, {} ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, ( x: number ): number => x ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, '4', w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, true, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, false, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, null, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, undefined, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, [], w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, {}, w, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, ( x: number ): number => x, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, 1, 2, x, 1, 10, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, true, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, false, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, null, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, undefined, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin( x.length, 3, 1, 2, x, 1, w, '1' ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, true ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, false ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, null ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, undefined ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, [] ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, {} ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); gcopyWithin(); // $ExpectError gcopyWithin( x.length ); // $ExpectError @@ -120,45 +157,169 @@ import gcopyWithin = require( './index' ); gcopyWithin( x.length, 3, 1 ); // $ExpectError gcopyWithin( x.length, 3, 1, 2 ); // $ExpectError gcopyWithin( x.length, 3, 1, 2, x ); // $ExpectError - gcopyWithin( x.length, 3, 1, 2, x, 1, {} ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1 ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w ); // $ExpectError + gcopyWithin( x.length, 3, 1, 2, x, 1, w, 1, {} ); // $ExpectError } // Attached to main export is an `ndarray` method which returns a collection... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); // $ExpectType Collection + gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0, w, 1, 0 ); // $ExpectType Float64Array + gcopyWithin.ndarray( x.length, 3, 1, 4, new AccessorArray( x ), 1, 0, w, 1, 0 ); // $ExpectType AccessorArray } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( '2', 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( true, 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( false, 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( null, 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( undefined, 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( [], 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( {}, 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( ( x: number ): number => x, 3, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, '3', 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, true, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, false, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, null, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, undefined, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, [], 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, {}, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, ( x: number ): number => x, 1, 2, x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, '1', 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, true, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, false, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, null, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, undefined, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, [], 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, {}, 2, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, ( x: number ): number => x, 2, x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin.ndarray( '2', 3, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( true, 3, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( false, 3, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( null, 3, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( undefined, 3, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( [], 2, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( {}, 2, 1, 2, x, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( ( x: number ): number => x, 2, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, '2', x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, true, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, false, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, null, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, undefined, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, [], x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, {}, x, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, ( x: number ): number => x, x, 1, 0, w, 1, 0 ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 2, 10, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, true, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, false, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, null, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, undefined, 1, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, {}, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 2, x, '4', 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, true, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, false, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, null, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, undefined, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, [], 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, {}, 0, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, '0', w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, true, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, false, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, null, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, undefined, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, [], w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, {}, w, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, 10, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, true, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, false, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, null, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, undefined, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, '1', 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, true, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, false, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, null, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, undefined, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, [], 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, {}, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); - gcopyWithin.ndarray( x.length, 3, 1, 2, 10, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( x.length, 3, 1, 2, true, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( x.length, 3, 1, 2, false, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( x.length, 3, 1, 2, null, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( x.length, 3, 1, 2, undefined, 1, 0 ); // $ExpectError - gcopyWithin.ndarray( x.length, 3, 1, 2, {}, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, '0' ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, true ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, false ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, null ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, undefined ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, [] ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, {} ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided insufficient arguments... { const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); gcopyWithin.ndarray(); // $ExpectError gcopyWithin.ndarray( x.length ); // $ExpectError @@ -167,5 +328,8 @@ import gcopyWithin = require( './index' ); gcopyWithin.ndarray( x.length, 3, 1, 2 ); // $ExpectError gcopyWithin.ndarray( x.length, 3, 1, 2, x ); // $ExpectError gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1 ); // $ExpectError - gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, {} ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1 ); // $ExpectError + gcopyWithin.ndarray( x.length, 3, 1, 2, x, 1, 0, w, 1, 0, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js index 6f811c01ec37..ac79ebe165c3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js @@ -19,6 +19,7 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); var gcopyWithin = require( './../lib' ); var x = discreteUniform( 10, 0, 500, { @@ -26,6 +27,8 @@ var x = discreteUniform( 10, 0, 500, { }); console.log( x ); +var w = zeros( 10, 'generic' ); + // Copy the first 3 elements to positions 5, 6, 7: -gcopyWithin( 10, 5, 0, 3, x, 1 ); +gcopyWithin( 10, 5, 0, 3, x, 1, w, 1 ); console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js index 5a4ac36f1e08..6d9cb9ac36aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js @@ -27,16 +27,18 @@ * var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); * * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * -* gcopyWithin( x.length, 3, 1, 4, x, 1 ); +* gcopyWithin( x.length, 3, 1, 4, x, 1, w, 1 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] * * @example * var gcopyWithin = require( '@stdlib/blas/ext/base/gcopy-within' ); * * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * -* gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0 ); +* gcopyWithin.ndarray( x.length, 3, 1, 4, x, 1, 0, w, 1, 0 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js index 97a575c6cff7..b93371c099ce 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js @@ -29,22 +29,34 @@ var ndarray = require( './ndarray.js' ); /** * Performs an in-place copy of elements within a strided array. * +* ## Notes +* +* - If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored. +* * @param {PositiveInteger} N - number of indexed elements * @param {NonNegativeInteger} target - target index * @param {NonNegativeInteger} start - source start index * @param {NonNegativeInteger} end - source end index * @param {Collection} x - input array -* @param {integer} strideX - stride length +* @param {integer} strideX - stride length for `x` +* @param {Collection} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` * @returns {Collection} input array * * @example * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * -* gcopyWithin( x.length, 3, 1, 4, x, 1 ); +* gcopyWithin( x.length, 3, 1, 4, x, 1, w, 1 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ -function gcopyWithin( N, target, start, end, x, strideX ) { - return ndarray( N, target, start, end, x, strideX, stride2offset( N, strideX ) ); // eslint-disable-line max-len +function gcopyWithin( N, target, start, end, x, strideX, workspace, strideW ) { + var ox; + var ow; + + ox = stride2offset( N, strideX ); + ow = stride2offset( N, strideW ); + return ndarray( N, target, start, end, x, strideX, ox, workspace, strideW, ow ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js index dfeb9c9400bf..0546db705638 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js @@ -29,23 +29,30 @@ var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; /** * Performs an in-place copy of elements within a strided array. * +* ## Notes +* +* - If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored. +* * @param {PositiveInteger} N - number of indexed elements * @param {NonNegativeInteger} target - target index * @param {NonNegativeInteger} start - source start index * @param {NonNegativeInteger} end - source end index * @param {Collection} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {NonNegativeInteger} offsetW - starting index for `workspace` * @returns {Collection} input array * * @example * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; * -* gcopyWithin( x.length, 3, 1, 4, x, 1, 0 ); +* gcopyWithin( x.length, 3, 1, 4, x, 1, 0, w, 1, 0 ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ -function gcopyWithin( N, target, start, end, x, strideX, offsetX ) { - var tmp; +function gcopyWithin( N, target, start, end, x, strideX, offsetX, workspace, strideW, offsetW ) { // eslint-disable-line max-len var ssi; var tsi; var cl; @@ -62,11 +69,10 @@ function gcopyWithin( N, target, start, end, x, strideX, offsetX ) { ssi = offsetX + ( start * strideX ); tsi = offsetX + ( target * strideX ); - // When the source and target index ranges overlap, copying directly could overwrite source elements before they are read, and, thus, we first copy the source elements to a temporary array: + // When the source and target index ranges overlap, copying directly could overwrite source elements before they are read, and, thus, we first copy the source elements to a workspace array: if ( start < target + cl && target < start + cl ) { - tmp = []; - gcopy( cl, x, strideX, ssi, tmp, 1, 0 ); - gcopy( cl, tmp, 1, 0, x, strideX, tsi ); + gcopy( cl, x, strideX, ssi, workspace, strideW, offsetW ); + gcopy( cl, workspace, strideW, offsetW, x, strideX, tsi ); return x; } gcopy( cl, x, strideX, ssi, x, strideX, tsi ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js index b08a22505edc..6d7928e2445c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js @@ -34,8 +34,8 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 6', function test( t ) { - t.strictEqual( gcopyWithin.length, 6, 'returns expected value' ); +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gcopyWithin.length, 8, 'returns expected value' ); t.end(); }); @@ -43,27 +43,31 @@ tape( 'the function copies values within the provided strided array', function t var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; - actual = gcopyWithin( 6, 3, 1, 4, x, 1 ); + actual = gcopyWithin( 6, 3, 1, 4, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 6, 3, 0, 3, x, 1 ); + actual = gcopyWithin( 6, 3, 0, 3, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 5, 2, 0, 5, x, 1 ); + actual = gcopyWithin( 5, 2, 0, 5, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -74,17 +78,20 @@ tape( 'the function copies values within the provided strided array', function t tape( 'the function copies values within the provided strided array (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; - gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1 ); + gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; - gcopyWithin( 5, 2, 0, 5, toAccessorArray( x ), 1 ); + gcopyWithin( 5, 2, 0, 5, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -94,19 +101,21 @@ tape( 'if provided `target` parameter is greater than or equal to the `N` parame var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 6, 0, 3, x, 1 ); + actual = gcopyWithin( 6, 6, 0, 3, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1 ); + actual = gcopyWithin( 6, 10, 0, 3, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 4, 5, 0, 3, x, 1 ); + actual = gcopyWithin( 4, 5, 0, 3, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -116,14 +125,16 @@ tape( 'if provided `target` parameter is greater than or equal to the `N` parame tape( 'if provided `target` parameter is greater than or equal to the `N` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 6, 6, 0, 3, toAccessorArray( x ), 1 ); + gcopyWithin( 6, 6, 0, 3, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); - gcopyWithin( 6, 10, 0, 3, toAccessorArray( x ), 1 ); + gcopyWithin( 6, 10, 0, 3, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -133,16 +144,18 @@ tape( 'if provided `N` parameter is less than or equal to `0`, the function retu var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 0, 3, 1, 4, x, 1 ); + actual = gcopyWithin( 0, 3, 1, 4, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( -1, 3, 1, 4, x, 1 ); + actual = gcopyWithin( -1, 3, 1, 4, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -153,14 +166,16 @@ tape( 'if provided `N` parameter is less than or equal to `0`, the function retu tape( 'if provided `N` parameter is less than or equal to `0`, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 0, 3, 1, 4, toAccessorArray( x ), 1 ); + gcopyWithin( 0, 3, 1, 4, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); - gcopyWithin( -1, 3, 1, 4, toAccessorArray( x ), 1 ); + gcopyWithin( -1, 3, 1, 4, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -170,19 +185,22 @@ tape( 'if provided `start` parameter is greater than or equal to the `end` param var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 3, 1, x, 1 ); + actual = gcopyWithin( 6, 0, 3, 1, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 2, 2, x, 1 ); + actual = gcopyWithin( 6, 0, 2, 2, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -192,14 +210,16 @@ tape( 'if provided `start` parameter is greater than or equal to the `end` param tape( 'if provided `start` parameter is greater than or equal to the `end` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 6, 0, 3, 1, toAccessorArray( x ), 1 ); + gcopyWithin( 6, 0, 3, 1, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); - gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1 ); + gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); @@ -208,11 +228,13 @@ tape( 'if provided `end` parameter is greater than the number of indexed element var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; - actual = gcopyWithin( 5, 0, 2, 10, x, 1 ); + actual = gcopyWithin( 5, 0, 2, 10, x, 1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -222,59 +244,68 @@ tape( 'if provided `end` parameter is greater than the number of indexed element tape( 'if provided `end` parameter is greater than the number of indexed elements, the function copies elements up to the last indexed element (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; - gcopyWithin( 5, 0, 2, 10, toAccessorArray( x ), 1 ); + gcopyWithin( 5, 0, 2, 10, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing a stride parameter', function test( t ) { +tape( 'the function supports providing an `x` stride parameter', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - actual = gcopyWithin( 4, 0, 2, 4, x, 2 ); + actual = gcopyWithin( 4, 0, 2, 4, x, 2, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { +tape( 'the function supports providing an `x` stride parameter (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), 2 ); + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), 2, toAccessorArray( w ), 1 ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing negative strides', function test( t ) { +tape( 'the function supports providing an `x` negative stride parameter', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0 ]; expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 3, 0, 1, 3, x, -1 ); + actual = gcopyWithin( 3, 0, 1, 3, x, -1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; - actual = gcopyWithin( 4, 0, 2, 4, x, -1 ); + actual = gcopyWithin( 4, 0, 2, 4, x, -1, w, 1 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -282,48 +313,86 @@ tape( 'the function supports providing negative strides', function test( t ) { t.end(); }); -tape( 'the function supports providing negative strides (accessors)', function test( t ) { +tape( 'the function supports providing an `x` negative stride parameter (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0 ]; expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 3, 0, 1, 3, toAccessorArray( x ), -1 ); + gcopyWithin( 3, 0, 1, 3, toAccessorArray( x ), -1, toAccessorArray( w ), 1 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; - gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), -1 ); + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), -1, toAccessorArray( w ), 1 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports a stride of zero', function test( t ) { +tape( 'the function supports providing a `workspace` stride parameter', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 1, 0, 2, x, 0 ); + actual = gcopyWithin( 3, 1, 0, 2, x, 1, w, 2 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports a stride of zero (accessors)', function test( t ) { +tape( 'the function supports providing a `workspace` stride parameter (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + gcopyWithin( 3, 1, 0, 2, toAccessorArray( x ), 1, toAccessorArray( w ), 2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` negative stride parameter', function test( t ) { + var expected; + var actual; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + actual = gcopyWithin( 6, 3, 1, 4, x, 1, w, -1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); - gcopyWithin( 6, 1, 0, 2, toAccessorArray( x ), 0 ); +tape( 'the function supports providing a `workspace` negative stride parameter (accessors)', function test( t ) { + var expected; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1, toAccessorArray( w ), -1 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); @@ -332,6 +401,7 @@ tape( 'the function supports view offsets', function test( t ) { var expected; var x0; var x1; + var w; // Initial array... x0 = new Float64Array([ @@ -348,7 +418,10 @@ tape( 'the function supports view offsets', function test( t ) { // Create offset view... x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element - gcopyWithin( 6, 0, 3, 6, x1, 1 ); + // Create a workspace array... + w = new Float64Array( 6 ); + + gcopyWithin( 6, 0, 3, 6, x1, 1, w, 1 ); expected = new Float64Array( [ 1.0, 5.0, 6.0, 7.0, 5.0, 6.0, 7.0, 8.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js index cb7269d9784d..b6f85af5fd50 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js @@ -33,8 +33,8 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 7', function test( t ) { - t.strictEqual( gcopyWithin.length, 7, 'returns expected value' ); +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gcopyWithin.length, 10, 'returns expected value' ); t.end(); }); @@ -42,27 +42,31 @@ tape( 'the function copies values within the provided strided array', function t var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; - actual = gcopyWithin( 6, 3, 1, 4, x, 1, 0 ); + actual = gcopyWithin( 6, 3, 1, 4, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 6, 3, 0, 3, x, 1, 0 ); + actual = gcopyWithin( 6, 3, 0, 3, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; - actual = gcopyWithin( 5, 2, 0, 5, x, 1, 0 ); + actual = gcopyWithin( 5, 2, 0, 5, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -73,17 +77,20 @@ tape( 'the function copies values within the provided strided array', function t tape( 'the function copies values within the provided strided array (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; - gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 3.0 ]; - gcopyWithin( 5, 2, 0, 5, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 5, 2, 0, 5, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -93,19 +100,21 @@ tape( 'if provided `target` parameter is greater than or equal to the `N` parame var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0 ); + actual = gcopyWithin( 6, 6, 0, 3, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0 ); + actual = gcopyWithin( 6, 10, 0, 3, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( 4, 5, 0, 3, x, 1, 0 ); + actual = gcopyWithin( 4, 5, 0, 3, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -115,14 +124,16 @@ tape( 'if provided `target` parameter is greater than or equal to the `N` parame tape( 'if provided `target` parameter is greater than or equal to the `N` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 6, 6, 0, 3, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 6, 6, 0, 3, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); - gcopyWithin( 6, 10, 0, 3, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 6, 10, 0, 3, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -132,16 +143,18 @@ tape( 'if provided `N` parameter is less than or equal to `0`, the function retu var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0 ); + actual = gcopyWithin( 0, 3, 1, 4, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); - actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0 ); + actual = gcopyWithin( -1, 3, 1, 4, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -152,14 +165,16 @@ tape( 'if provided `N` parameter is less than or equal to `0`, the function retu tape( 'if provided `N` parameter is less than or equal to `0`, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 0, 3, 1, 4, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 0, 3, 1, 4, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); - gcopyWithin( -1, 3, 1, 4, toAccessorArray( x ), 1, 0 ); + gcopyWithin( -1, 3, 1, 4, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -169,19 +184,22 @@ tape( 'if provided `start` parameter is greater than or equal to the `end` param var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 3, 1, x, 1, 0 ); + actual = gcopyWithin( 6, 0, 3, 1, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0 ); + actual = gcopyWithin( 6, 0, 2, 2, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -191,14 +209,16 @@ tape( 'if provided `start` parameter is greater than or equal to the `end` param tape( 'if provided `start` parameter is greater than or equal to the `end` parameter, the function returns the strided array unchanged (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 6, 0, 3, 1, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 6, 0, 3, 1, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); - gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); @@ -207,11 +227,13 @@ tape( 'if provided `end` parameter is greater than the number of indexed element var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; - actual = gcopyWithin( 5, 0, 2, 10, x, 1, 0 ); + actual = gcopyWithin( 5, 0, 2, 10, x, 1, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -221,59 +243,68 @@ tape( 'if provided `end` parameter is greater than the number of indexed element tape( 'if provided `end` parameter is greater than the number of indexed elements, the function copies elements up to the last indexed element (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 3.0, 4.0, 5.0, 4.0, 5.0 ]; - gcopyWithin( 5, 0, 2, 10, toAccessorArray( x ), 1, 0 ); + gcopyWithin( 5, 0, 2, 10, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing a stride parameter', function test( t ) { +tape( 'the function supports providing an `x` stride parameter', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - actual = gcopyWithin( 4, 0, 2, 4, x, 2, 0 ); + actual = gcopyWithin( 4, 0, 2, 4, x, 2, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing a stride parameter (accessors)', function test( t ) { +tape( 'the function supports providing an `x` stride parameter (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), 2, 0 ); + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), 2, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing negative strides', function test( t ) { +tape( 'the function supports providing an `x` negative stride parameter', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0 ]; expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2 ); + actual = gcopyWithin( 3, 0, 1, 3, x, -1, 2, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; - actual = gcopyWithin( 4, 0, 2, 4, x, -1, 3 ); + actual = gcopyWithin( 4, 0, 2, 4, x, -1, 3, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -281,20 +312,23 @@ tape( 'the function supports providing negative strides', function test( t ) { t.end(); }); -tape( 'the function supports providing negative strides (accessors)', function test( t ) { +tape( 'the function supports providing an `x` negative stride parameter (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0 ]; expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 3, 0, 1, 3, toAccessorArray( x ), -1, 2 ); + gcopyWithin( 3, 0, 1, 3, toAccessorArray( x ), -1, 2, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ]; - gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), -1, 3 ); + gcopyWithin( 4, 0, 2, 4, toAccessorArray( x ), -1, 3, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); @@ -304,11 +338,13 @@ tape( 'the function supports a stride of zero', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - actual = gcopyWithin( 6, 1, 0, 2, x, 0, 0 ); + actual = gcopyWithin( 6, 1, 0, 2, x, 0, 0, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); @@ -318,38 +354,137 @@ tape( 'the function supports a stride of zero', function test( t ) { tape( 'the function supports a stride of zero (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - gcopyWithin( 6, 1, 0, 2, toAccessorArray( x ), 0, 0 ); + gcopyWithin( 6, 1, 0, 2, toAccessorArray( x ), 0, 0, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing an offset parameter', function test( t ) { +tape( 'the function supports providing an `x` offset parameter', function test( t ) { var expected; var actual; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ]; - actual = gcopyWithin( 4, 2, 0, 2, x, 1, 1 ); + actual = gcopyWithin( 4, 2, 0, 2, x, 1, 1, w, 1, 0 ); t.strictEqual( actual, x, 'returns expected value' ); t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); -tape( 'the function supports providing an offset parameter (accessors)', function test( t ) { +tape( 'the function supports providing an `x` offset parameter (accessors)', function test( t ) { var expected; var x; + var w; x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ]; - gcopyWithin( 4, 2, 0, 2, toAccessorArray( x ), 1, 1 ); + gcopyWithin( 4, 2, 0, 2, toAccessorArray( x ), 1, 1, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` stride parameter', function test( t ) { + var expected; + var actual; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 3, 1, 0, 2, x, 1, 0, w, 2, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` stride parameter (accessors)', function test( t ) { + var expected; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + gcopyWithin( 3, 1, 0, 2, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 2, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` negative stride parameter', function test( t ) { + var expected; + var actual; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + actual = gcopyWithin( 6, 3, 1, 4, x, 1, 0, w, -1, 5 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` negative stride parameter (accessors)', function test( t ) { + var expected; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ]; + + gcopyWithin( 6, 3, 1, 4, toAccessorArray( x ), 1, 0, toAccessorArray( w ), -1, 5 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` offset parameter', function test( t ) { + var expected; + var actual; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + actual = gcopyWithin( 3, 1, 0, 2, x, 1, 0, w, 1, 2 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a `workspace` offset parameter (accessors)', function test( t ) { + var expected; + var x; + var w; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ]; + + gcopyWithin( 3, 1, 0, 2, toAccessorArray( x ), 1, 0, toAccessorArray( w ), 1, 2 ); // eslint-disable-line max-len t.deepEqual( x, expected, 'returns expected value' ); t.end(); }); From 03a28cf0a807fa0e5bdba9eadc5ba4588a1badae Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 1 Aug 2026 17:46:30 -0700 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gcopy-within/README.md | 4 ++-- .../@stdlib/blas/ext/base/gcopy-within/docs/repl.txt | 8 ++++---- .../blas/ext/base/gcopy-within/docs/types/index.d.ts | 12 ++++++------ .../@stdlib/blas/ext/base/gcopy-within/lib/main.js | 11 ++++------- .../blas/ext/base/gcopy-within/lib/ndarray.js | 6 +++--- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md index 1ccedff79d68..5acb345cd08f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -46,8 +46,8 @@ The function has the following parameters: - **N**: number of indexed elements. - **target**: target index. -- **start**: source start index. -- **end**: source end index. +- **start**: source start index (inclusive). +- **end**: source end index (exclusive). - **x**: input array-like object. - **strideX**: stride length for `x`. - **workspace**: workspace array. Must have `N` indexed elements. diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt index 0a99c7d73ea1..755d0a587f20 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt @@ -26,10 +26,10 @@ Target index. start: integer - Source start index. + Source start index (inclusive). end: integer - Source end index. + Source end index (exclusive). x: ArrayLikeObject Input array. @@ -89,10 +89,10 @@ Target index. start: integer - Source start index. + Source start index (inclusive). end: integer - Source end index. + Source end index (exclusive). x: ArrayLikeObject Input array. diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts index 7b43a953bbde..7ec3bdee3282 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts @@ -40,8 +40,8 @@ interface Routine { * * @param N - number of indexed elements * @param target - target index - * @param start - source start index - * @param end - source end index + * @param start - source start index (inclusive) + * @param end - source end index (exclusive) * @param x - input array * @param strideX - stride length for `x` * @param workspace - workspace array @@ -66,8 +66,8 @@ interface Routine { * * @param N - number of indexed elements * @param target - target index - * @param start - source start index - * @param end - source end index + * @param start - source start index (inclusive) + * @param end - source end index (exclusive) * @param x - input array * @param strideX - stride length for `x` * @param offsetX - starting index for `x` @@ -95,8 +95,8 @@ interface Routine { * * @param N - number of indexed elements * @param target - target index -* @param start - source start index -* @param end - source end index +* @param start - source start index (inclusive) +* @param end - source end index (exclusive) * @param x - input array * @param strideX - stride length for `x` * @param workspace - workspace array diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js index b93371c099ce..44879c8b73fa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js @@ -35,8 +35,8 @@ var ndarray = require( './ndarray.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {NonNegativeInteger} target - target index -* @param {NonNegativeInteger} start - source start index -* @param {NonNegativeInteger} end - source end index +* @param {NonNegativeInteger} start - source start index (inclusive) +* @param {NonNegativeInteger} end - source end index (exclusive) * @param {Collection} x - input array * @param {integer} strideX - stride length for `x` * @param {Collection} workspace - workspace array @@ -51,11 +51,8 @@ var ndarray = require( './ndarray.js' ); * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] */ function gcopyWithin( N, target, start, end, x, strideX, workspace, strideW ) { - var ox; - var ow; - - ox = stride2offset( N, strideX ); - ow = stride2offset( N, strideW ); + var ox = stride2offset( N, strideX ); + var ow = stride2offset( N, strideW ); return ndarray( N, target, start, end, x, strideX, ox, workspace, strideW, ow ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js index 0546db705638..2a688bf4cd0d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var min = require( '@stdlib/math/base/special/min' ); +var min = require( '@stdlib/math/base/special/fast/min' ); var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; @@ -35,8 +35,8 @@ var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; * * @param {PositiveInteger} N - number of indexed elements * @param {NonNegativeInteger} target - target index -* @param {NonNegativeInteger} start - source start index -* @param {NonNegativeInteger} end - source end index +* @param {NonNegativeInteger} start - source start index (inclusive) +* @param {NonNegativeInteger} end - source end index (exclusive) * @param {Collection} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` From 9680bddd79b4ff48ef41b46b939f42aecabe1cdc Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 1 Aug 2026 17:54:22 -0700 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js index 2a688bf4cd0d..bd2c06f7f777 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js @@ -70,7 +70,7 @@ function gcopyWithin( N, target, start, end, x, strideX, offsetX, workspace, str tsi = offsetX + ( target * strideX ); // When the source and target index ranges overlap, copying directly could overwrite source elements before they are read, and, thus, we first copy the source elements to a workspace array: - if ( start < target + cl && target < start + cl ) { + if ( start < target+cl && target < start+cl ) { gcopy( cl, x, strideX, ssi, workspace, strideW, offsetW ); gcopy( cl, workspace, strideW, offsetW, x, strideX, tsi ); return x; From 4100b00f7b620f127cc6f2a5b685443938a0557a Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 1 Aug 2026 17:58:25 -0700 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md | 3 ++- .../@stdlib/blas/ext/base/gcopy-within/docs/repl.txt | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md index 5acb345cd08f..a58b263edf57 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -50,7 +50,7 @@ The function has the following parameters: - **end**: source end index (exclusive). - **x**: input array-like object. - **strideX**: stride length for `x`. -- **workspace**: workspace array. Must have `N` indexed elements. +- **workspace**: workspace array. 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: @@ -122,6 +122,7 @@ gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2, w, 1, 0 ); - 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 `strideX == 0`, 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. - Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt index 755d0a587f20..0f8dd3a3d203 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt @@ -38,7 +38,7 @@ Stride length for `x`. w: ArrayLikeObject - Workspace array. Must have `N` indexed elements. + Workspace array. Must have at least `N` indexed elements. strideW: integer Stride length for `w`. @@ -104,7 +104,7 @@ Starting index for `x`. w: ArrayLikeObject - Workspace array. Must have `N` indexed elements. + Workspace array. Must have at least `N` indexed elements. strideW: integer Stride length for `w`. From b1e6e55e1281a71c5088487748ff3c6835507b6f Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 1 Aug 2026 18:08:47 -0700 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md index a58b263edf57..461e88b3c0e7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -122,7 +122,6 @@ gcopyWithin.ndarray( 4, 2, 0, 2, x, 1, 2, w, 1, 0 ); - 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 `strideX == 0`, 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. - Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).