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..461e88b3c0e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/README.md @@ -0,0 +1,187 @@ + + +# gcopyWithin + +> 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, 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, w, 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 (inclusive). +- **end**: source end index (exclusive). +- **x**: input array-like object. +- **strideX**: stride length for `x`. +- **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: + +```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, w, 1 ); +// 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. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Create a workspace array... +var w = new Float64Array( 6 ); + +// Copy within the view... +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, 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, 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 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, w, 1, 0 ); +// x => [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 7.0, 8.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the strided array unchanged. +- If `target >= N`, both functions return the strided array unchanged. +- If `start >= end`, both functions return the strided array unchanged. +- If the `start` and `target` index ranges do not overlap, the `workspace` array is unused and thus ignored. +- Both functions **mutate** the provided input strided array. +- 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. + +
+ + + +
+ +## Examples + + + +```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, { + 'dtype': 'generic' +}); +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, w, 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..18b1c7a9826c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @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 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' ); +var gcopyWithin = require( './../lib/main.js' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var w; + + x = uniform( len, -10.0, 10.0, options ); + w = zeros( len, options.dtype ); + 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, w, 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..0c6cb98cd8bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/benchmark/benchmark.ndarray.js @@ -0,0 +1,108 @@ +/** +* @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 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' ); +var gcopyWithin = require( './../lib/ndarray.js' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var w; + + x = uniform( len, -10.0, 10.0, options ); + w = zeros( len, options.dtype ); + 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, w, 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..0f8dd3a3d203 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/repl.txt @@ -0,0 +1,135 @@ + +{{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 + 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. + + 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 + Number of indexed elements. + + target: integer + Target index. + + start: integer + Source start index (inclusive). + + end: integer + Source end index (exclusive). + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + w: ArrayLikeObject + Workspace array. Must have at least `N` indexed elements. + + strideW: integer + Stride length for `w`. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > 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 ]; + > {{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 ]; + > 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 ); + > 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, 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 parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + target: integer + Target index. + + start: integer + Source start index (inclusive). + + end: integer + Source end index (exclusive). + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + w: ArrayLikeObject + Workspace array. Must have at least `N` indexed elements. + + strideW: integer + Stride length for `w`. + + offsetW: integer + Starting index for `w`. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > 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 ]; + > 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 new file mode 100644 index 000000000000..7ec3bdee3282 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/index.d.ts @@ -0,0 +1,125 @@ +/* +* @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, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gcopyWithin`. +*/ +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 (inclusive) + * @param end - source end index (exclusive) + * @param x - 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, w, 1 ); + * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] + */ + = 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 (inclusive) + * @param end - source end index (exclusive) + * @param x - 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, w, 1, 0 ); + * // x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] + */ + 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 (inclusive) +* @param end - source end index (exclusive) +* @param x - 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, 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, w, 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..58862739cca7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/docs/types/test.ts @@ -0,0 +1,335 @@ +/* +* @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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import gcopyWithin = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 10 ); + const w = new Float64Array( 10 ); + + 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, 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, 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, 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, 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, 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', 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 + 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 + 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, 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( 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, 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 + 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 + 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 new file mode 100644 index 000000000000..ac79ebe165c3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var gcopyWithin = require( './../lib' ); + +var x = discreteUniform( 10, 0, 500, { + 'dtype': 'generic' +}); +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, 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 new file mode 100644 index 000000000000..6d9cb9ac36aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/index.js @@ -0,0 +1,61 @@ +/** +* @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 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* 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, w, 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..44879c8b73fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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. +* +* ## 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 (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 +* @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, w, 1 ); +* // 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 = 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 +} + + +// 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..bd2c06f7f777 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/lib/ndarray.js @@ -0,0 +1,85 @@ +/** +* @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/fast/min' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; + + +// MAIN // + +/** +* 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 (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` +* @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, 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, workspace, strideW, offsetW ) { // eslint-disable-line max-len + var ssi; + var tsi; + var cl; + + if ( N <= 0 || strideX === 0 || target >= N ) { + return x; + } + // Resolve the number of elements to copy: + cl = min( min( end, N ) - start, N - target ); + if ( cl <= 0 ) { + return x; + } + // Resolve the starting source and target indices... + 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 workspace array: + 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; + } + 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..6d7928e2445c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.main.js @@ -0,0 +1,430 @@ +/** +* @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/main.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 8', function test( t ) { + t.strictEqual( gcopyWithin.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided strided array', 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' ); + + 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, 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, w, 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 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 ); + 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, toAccessorArray( w ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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; + 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, w, 1 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + 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, w, 1 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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, toAccessorArray( w ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + 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(); +}); + +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; + 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, w, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = gcopyWithin( -1, 3, 1, 4, x, 1, w, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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, toAccessorArray( w ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + 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(); +}); + +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; + 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, 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, w, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, toAccessorArray( w ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcopyWithin( 6, 0, 2, 2, toAccessorArray( x ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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; + 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, w, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, toAccessorArray( w ), 1 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, w, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, toAccessorArray( w ), 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, 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, w, 1 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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, 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, toAccessorArray( w ), 1 ); // 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, w, 2 ); + + 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, 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(); +}); + +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(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var x1; + var w; + + // Initial array... + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, // 3 + 6.0, // 4 + 7.0, // 5 + 8.0 + ]); + + // Create offset view... + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + // 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 ] ); + + 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..b6f85af5fd50 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcopy-within/test/test.ndarray.js @@ -0,0 +1,490 @@ +/** +* @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 10', function test( t ) { + t.strictEqual( gcopyWithin.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided strided array', 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, 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, 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, w, 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 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, 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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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; + 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, 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, 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, w, 1, 0 ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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, 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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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; + 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, 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, w, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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, 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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +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; + 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, 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, w, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, 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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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; + 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, w, 1, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, 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 `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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, 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, 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 `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, 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, toAccessorArray( w ), 1, 0 ); // 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 ) { + 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, w, 1, 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; + 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, toAccessorArray( w ), 1, 0 ); // eslint-disable-line max-len + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +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, 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 `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, 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(); +});