From 1a8735ac42e6c467ffd6a870c0cba774d7c7e84a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 7 Aug 2026 12:16:46 +0500 Subject: [PATCH] feat: add blas/ext/base/ndarray/scopy-within --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ext/base/ndarray/scopy-within/README.md | 146 +++++++++ .../scopy-within/benchmark/benchmark.js | 120 +++++++ .../base/ndarray/scopy-within/docs/repl.txt | 41 +++ .../scopy-within/docs/types/index.d.ts | 69 ++++ .../ndarray/scopy-within/docs/types/test.ts | 82 +++++ .../ndarray/scopy-within/examples/index.js | 47 +++ .../base/ndarray/scopy-within/lib/index.js | 58 ++++ .../ext/base/ndarray/scopy-within/lib/main.js | 99 ++++++ .../base/ndarray/scopy-within/package.json | 70 ++++ .../base/ndarray/scopy-within/test/test.js | 301 ++++++++++++++++++ 10 files changed, 1033 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/README.md new file mode 100644 index 000000000000..eafd4520348f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/README.md @@ -0,0 +1,146 @@ + + +# scopyWithin + +> Perform an in-place copy of elements within a one-dimensional single-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var scopyWithin = require( '@stdlib/blas/ext/base/ndarray/scopy-within' ); +``` + +#### scopyWithin( arrays ) + +Performs an in-place copy of elements within a one-dimensional single-precision floating-point ndarray. + +```javascript +var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = new Float32Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var target = scalar2ndarray( 3, { + 'dtype': 'generic' +}); +var start = scalar2ndarray( 1, { + 'dtype': 'generic' +}); +var end = scalar2ndarray( 4, { + 'dtype': 'generic' +}); + +var w = zeros( [ 6 ], { + 'dtype': 'float32' +}); + +var out = scopyWithin( [ x, target, start, end, w ] ); +// returns [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray specifying a target index. + - a zero-dimensional ndarray specifying a source start index (inclusive). + - a zero-dimensional ndarray specifying a source end index (exclusive). + - a one-dimensional workspace ndarray. + +
+ + + +
+ +## Notes + +- The input ndarray is copied **in-place** (i.e., the input ndarray is **mutated**). +- If the `start` and `target` index ranges do not overlap, the `workspace` ndarray is unused and thus ignored. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scopyWithin = require( '@stdlib/blas/ext/base/ndarray/scopy-within' ); + +var x = discreteUniform( [ 10 ], -100, 100, { + 'dtype': 'float32' +}); +console.log( ndarray2array( x ) ); + +var target = scalar2ndarray( 5, { + 'dtype': 'generic' +}); +var start = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +var end = scalar2ndarray( 3, { + 'dtype': 'generic' +}); + +var w = zeros( [ 10 ], { + 'dtype': 'float32' +}); + +scopyWithin( [ x, target, start, end, w ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/benchmark/benchmark.js new file mode 100644 index 000000000000..f285080afbff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/benchmark/benchmark.js @@ -0,0 +1,120 @@ +/** +* @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/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var scopyWithin = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var target; + var start; + var opts; + var end; + var x; + var w; + + opts = { + 'dtype': 'generic' + }; + x = uniform( [ len ], 0.0, 100.0, options ); + w = zeros( [ len ], options ); + target = scalar2ndarray( 0, opts ); + start = scalar2ndarray( 0, opts ); + end = scalar2ndarray( len, opts ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = scopyWithin( [ x, target, start, end, w ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnanf( x.get( i%len ) ) ) { + 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/ndarray/scopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/repl.txt new file mode 100644 index 000000000000..98a3d2812bc9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/repl.txt @@ -0,0 +1,41 @@ + +{{alias}}( arrays ) + Performs an in-place copy of elements within a one-dimensional single- + precision floating-point ndarray. + + The input ndarray is copied *in-place* (i.e., the input ndarray is + *mutated*). + + If the `start` and `target` index ranges do not overlap, the `workspace` + ndarray is unused and thus ignored. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray specifying a target index. + - a zero-dimensional ndarray specifying a source start index + (inclusive). + - a zero-dimensional ndarray specifying a source end index + (exclusive). + - a one-dimensional workspace ndarray. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var t = {{alias:@stdlib/ndarray/from-scalar}}( 3, { 'dtype': 'generic' } ); + > var s = {{alias:@stdlib/ndarray/from-scalar}}( 1, { 'dtype': 'generic' } ); + > var e = {{alias:@stdlib/ndarray/from-scalar}}( 4, { 'dtype': 'generic' } ); + > var w = {{alias:@stdlib/ndarray/zeros}}( [ 6 ], { 'dtype': 'float32' } ); + > {{alias}}( [ x, t, s, e, w ] ) + [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/index.d.ts new file mode 100644 index 000000000000..d8d925d57499 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/index.d.ts @@ -0,0 +1,69 @@ +/* +* @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 { typedndarray, float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Performs an in-place copy of elements within a one-dimensional single-precision floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying a target index. +* - a zero-dimensional ndarray specifying a source start index (inclusive). +* - a zero-dimensional ndarray specifying a source end index (exclusive). +* - a one-dimensional workspace ndarray. +* +* @param arrays - array-like object containing ndarrays +* @returns input ndarray +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var target = scalar2ndarray( 3, { +* 'dtype': 'generic' +* }); +* var start = scalar2ndarray( 1, { +* 'dtype': 'generic' +* }); +* var end = scalar2ndarray( 4, { +* 'dtype': 'generic' +* }); +* +* var w = zeros( [ 6 ], { +* 'dtype': 'float32' +* }); +* +* var out = scopyWithin( [ x, target, start, end, w ] ); +* // returns [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ +declare function scopyWithin( arrays: [ float32ndarray, typedndarray, typedndarray, typedndarray, float32ndarray ] ): float32ndarray; + + +// EXPORTS // + +export = scopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/test.ts new file mode 100644 index 000000000000..5e7fcafc79d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/docs/types/test.ts @@ -0,0 +1,82 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import scopyWithin = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const target = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + const start = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + const end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + const w = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + scopyWithin( [ x, target, start, end, w ] ); // $ExpectType float32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + scopyWithin( '10' ); // $ExpectError + scopyWithin( 10 ); // $ExpectError + scopyWithin( true ); // $ExpectError + scopyWithin( false ); // $ExpectError + scopyWithin( null ); // $ExpectError + scopyWithin( undefined ); // $ExpectError + scopyWithin( [] ); // $ExpectError + scopyWithin( {} ); // $ExpectError + scopyWithin( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const target = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + const start = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + const end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + const w = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + scopyWithin(); // $ExpectError + scopyWithin( [ x, target, start, end, w ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/examples/index.js new file mode 100644 index 000000000000..012610f3d260 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/examples/index.js @@ -0,0 +1,47 @@ +/** +* @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/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scopyWithin = require( './../lib' ); + +var x = discreteUniform( [ 10 ], -100, 100, { + 'dtype': 'float32' +}); +console.log( ndarray2array( x ) ); + +var target = scalar2ndarray( 5, { + 'dtype': 'generic' +}); +var start = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +var end = scalar2ndarray( 3, { + 'dtype': 'generic' +}); + +var w = zeros( [ 10 ], { + 'dtype': 'float32' +}); + +scopyWithin( [ x, target, start, end, w ] ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/index.js new file mode 100644 index 000000000000..883bd19537be --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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 one-dimensional single-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/scopy-within +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scopyWithin = require( '@stdlib/blas/ext/base/ndarray/scopy-within' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var target = scalar2ndarray( 3, { +* 'dtype': 'generic' +* }); +* var start = scalar2ndarray( 1, { +* 'dtype': 'generic' +* }); +* var end = scalar2ndarray( 4, { +* 'dtype': 'generic' +* }); +* +* var w = zeros( [ 6 ], { +* 'dtype': 'float32' +* }); +* +* var out = scopyWithin( [ x, target, start, end, w ] ); +* // returns [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/main.js new file mode 100644 index 000000000000..ece268972fdf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/lib/main.js @@ -0,0 +1,99 @@ +/** +* @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 ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/scopy-within' ).ndarray; + + +// MAIN // + +/** +* Performs an in-place copy of elements within a one-dimensional single-precision floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying a target index. +* - a zero-dimensional ndarray specifying a source start index (inclusive). +* - a zero-dimensional ndarray specifying a source end index (exclusive). +* - a one-dimensional workspace ndarray. +* +* - If the `start` and `target` index ranges do not overlap, the `workspace` ndarray is unused and thus ignored. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} input ndarray +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = new Float32Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var target = scalar2ndarray( 3, { +* 'dtype': 'generic' +* }); +* var start = scalar2ndarray( 1, { +* 'dtype': 'generic' +* }); +* var end = scalar2ndarray( 4, { +* 'dtype': 'generic' +* }); +* +* var w = zeros( [ 6 ], { +* 'dtype': 'float32' +* }); +* +* var out = scopyWithin( [ x, target, start, end, w ] ); +* // returns [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] +*/ +function scopyWithin( arrays ) { + var ws; + var wo; + var wd; + var xs; + var xo; + var xd; + var x; + var w; + + x = arrays[ 0 ]; + w = arrays[ 4 ]; + xd = getData( x ); + xs = getStride( x, 0 ); + xo = getOffset( x ); + wd = getData( w ); + ws = getStride( w, 0 ); + wo = getOffset( w ); + strided( numelDimension( x, 0 ), ndarraylike2scalar( arrays[ 1 ] ), ndarraylike2scalar( arrays[ 2 ] ), ndarraylike2scalar( arrays[ 3 ] ), xd, xs, xo, wd, ws, wo ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = scopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/package.json new file mode 100644 index 000000000000..e24b18d5f318 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/scopy-within", + "version": "0.0.0", + "description": "Perform an in-place copy of elements within a one-dimensional single-precision floating-point ndarray.", + "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", + "float32", + "float", + "float32array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/test/test.js new file mode 100644 index 000000000000..2ebcffb78307 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/scopy-within/test/test.js @@ -0,0 +1,301 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scopyWithin = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float32Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a zero-dimensional ndarray. +* +* @private +* @param {number} v - scalar value +* @returns {ndarray} zero-dimensional ndarray +*/ +function scalar( v ) { + return scalar2ndarray( v, { + 'dtype': 'generic' + }); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( scopyWithin.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function copies elements within a one-dimensional ndarray', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 6 ); + + x = vector( xbuf, 6, 1, 0 ); + w = vector( wbuf, 6, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 3 ), scalar( 1 ), scalar( 4 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] ), 'returns expected value' ); + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 6 ); + + x = vector( xbuf, 6, 1, 0 ); + w = vector( wbuf, 6, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 3 ), scalar( 0 ), scalar( 3 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 1.0, 2.0, 3.0 ] ), 'returns expected value' ); + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + wbuf = new Float32Array( 5 ); + + x = vector( xbuf, 5, 1, 0 ); + w = vector( wbuf, 5, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 2 ), scalar( 0 ), scalar( 5 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 1.0, 2.0, 3.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `target` index is greater than or equal to the number of elements, the function returns the input ndarray unchanged', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 6 ); + + x = vector( xbuf, 6, 1, 0 ); + w = vector( wbuf, 6, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 6 ), scalar( 0 ), scalar( 3 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 'returns expected value' ); + + actual = scopyWithin( [ x, scalar( 10 ), scalar( 0 ), scalar( 3 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if the input ndarray is empty, the function returns the input ndarray unchanged', function test( t ) { + var actual; + var x; + var w; + + x = vector( new Float32Array( [] ), 0, 1, 0 ); + w = vector( new Float32Array( [] ), 0, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 0 ), scalar( 0 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `start` index is greater than or equal to the `end` index, the function returns the input ndarray unchanged', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 6 ); + + x = vector( xbuf, 6, 1, 0 ); + w = vector( wbuf, 6, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 3 ), scalar( 1 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 'returns expected value' ); + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 6 ); + + x = vector( xbuf, 6, 1, 0 ); + w = vector( wbuf, 6, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 2 ), scalar( 2 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `end` index is greater than the number of elements, the function copies elements up to the last indexed element', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + wbuf = new Float32Array( 5 ); + + x = vector( xbuf, 5, 1, 0 ); + w = vector( wbuf, 5, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 2 ), scalar( 10 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 3.0, 4.0, 5.0, 4.0, 5.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + wbuf = new Float32Array( 4 ); + + x = vector( xbuf, 4, 2, 0 ); + w = vector( wbuf, 4, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 2 ), scalar( 4 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 5.0, 2.0, 7.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 3 ); + + x = vector( xbuf, 3, -1, 2 ); + w = vector( wbuf, 3, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 1 ), scalar( 3 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 1.0, 2.0, 4.0, 5.0, 6.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 4 ); + + x = vector( xbuf, 4, 1, 1 ); + w = vector( wbuf, 4, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 2 ), scalar( 0 ), scalar( 2 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a zero stride', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + wbuf = new Float32Array( 6 ); + + x = vector( xbuf, 6, 0, 0 ); + w = vector( wbuf, 6, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 1 ), scalar( 0 ), scalar( 2 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride and non-zero offset', function test( t ) { + var actual; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + wbuf = new Float32Array( 4 ); + + x = vector( xbuf, 4, -1, 3 ); + w = vector( wbuf, 4, 1, 0 ); + + actual = scopyWithin( [ x, scalar( 0 ), scalar( 2 ), scalar( 4 ), w ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( getData( actual ), new Float32Array( [ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 7.0, 8.0 ] ), 'returns expected value' ); + + t.end(); +});