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(); +});