From 0c4f9aeecde044444a98bcdb4dd9612a78980b93 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 13 Oct 2025 23:56:19 +0500 Subject: [PATCH 1/2] feat: add blas/ext/base/dcopy-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 status: passed - 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/dcopy-within/README.md | 302 ++++++++++++++++++ .../base/dcopy-within/benchmark/benchmark.js | 102 ++++++ .../benchmark/benchmark.native.js | 107 +++++++ .../benchmark/benchmark.ndarray.js | 102 ++++++ .../benchmark/benchmark.ndarray.native.js | 107 +++++++ .../base/dcopy-within/benchmark/c/Makefile | 146 +++++++++ .../benchmark/c/benchmark.length.c | 198 ++++++++++++ .../blas/ext/base/dcopy-within/binding.gyp | 170 ++++++++++ .../blas/ext/base/dcopy-within/docs/repl.txt | 110 +++++++ .../base/dcopy-within/docs/types/index.d.ts | 101 ++++++ .../ext/base/dcopy-within/docs/types/test.ts | 159 +++++++++ .../ext/base/dcopy-within/examples/c/Makefile | 146 +++++++++ .../base/dcopy-within/examples/c/example.c | 39 +++ .../ext/base/dcopy-within/examples/index.js | 35 ++ .../blas/ext/base/dcopy-within/include.gypi | 53 +++ .../stdlib/blas/ext/base/dcopy_within.h | 46 +++ .../ext/base/dcopy-within/lib/dcopy_within.js | 58 ++++ .../dcopy-within/lib/dcopy_within.native.js | 56 ++++ .../blas/ext/base/dcopy-within/lib/index.js | 68 ++++ .../blas/ext/base/dcopy-within/lib/main.js | 35 ++ .../blas/ext/base/dcopy-within/lib/native.js | 35 ++ .../blas/ext/base/dcopy-within/lib/ndarray.js | 95 ++++++ .../base/dcopy-within/lib/ndarray.native.js | 57 ++++ .../blas/ext/base/dcopy-within/manifest.json | 102 ++++++ .../blas/ext/base/dcopy-within/package.json | 74 +++++ .../blas/ext/base/dcopy-within/src/Makefile | 70 ++++ .../blas/ext/base/dcopy-within/src/addon.c | 66 ++++ .../blas/ext/base/dcopy-within/src/main.c | 103 ++++++ .../dcopy-within/test/test.dcopy_within.js | 139 ++++++++ .../test/test.dcopy_within.native.js | 151 +++++++++ .../blas/ext/base/dcopy-within/test/test.js | 82 +++++ .../base/dcopy-within/test/test.ndarray.js | 154 +++++++++ .../dcopy-within/test/test.ndarray.native.js | 165 ++++++++++ 33 files changed, 3433 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/include/stdlib/blas/ext/base/dcopy_within.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/dcopy_within.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/dcopy_within.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/README.md b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/README.md new file mode 100644 index 000000000000..501f2b8b8afa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/README.md @@ -0,0 +1,302 @@ + + +# dcopy-within + +> Perform an in-place copy of elements within a double-precision floating-point array. + +
+ +## Usage + +```javascript +var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' ); +``` + +#### dcopyWithin( N, target, x, strideX, start, end ) + +Performs an in-place copy of elements within a double-precision floating-point array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +dcopyWithin( 3, 2, x, 1, 1, 2 ); +// x => [ 1.0, 2.0, 2.0, 4.0, 5.0, 6.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **target**: target index. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: stride length. +- **start**: source start index. +- **end**: source end index. + +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 Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + +dcopyWithin( 3, 0, x, 2, 1, 6 ); +// x => [ 3.0, 2.0, 5.0, 4.0, 7.0, 6.0, 7.0, 8.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 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Copy within the view... +dcopyWithin( 2, 0, x1, 1, 2, 5 ); +// x0 => [ 1.0, 4.0, 5.0, 4.0, 5.0, 6.0 ] +``` + +#### dcopyWithin.ndarray( N, target, x, strideX, offsetX, start, end ) + +Performs an in-place copy of elements within a double-precision floating-point array using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +dcopyWithin.ndarray( 2, 2, x, 1, 1, 0, 5 ); +// x => [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to copy elements starting from the second element: + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +dcopyWithin.ndarray( 2, 2, x, 1, 2, 0, 2 ); +// x => [ 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the strided array unchanged. +- Both functions **mutate** the provided input strided array. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' ); + +var x = discreteUniform( 10, 0, 500, { + 'dtype': 'float64' +}); +console.log( x ); + +// Copy the first 3 elements to positions 5, 6, 7: +dcopyWithin( 3, 5, x, 1, 0, 3 ); +console.log( x ); + +// Copy every other element starting from the second element: +dcopyWithin( 5, 0, x, 1, 1, 9 ); +console.log( x ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dcopy_within.h" +``` + +#### stdlib_strided_dcopy_within( N, target, \*x, strideX, start, end ) + +Performs an in-place copy of elements within a double-precision floating-point array. + +```c +const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; + +stdlib_strided_dcopy_within( 3, 3, x, 1, 1, 4 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **target**: `[in] CBLAS_INT` target index. +- **x**: `[inout] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. +- **start**: `[in] CBLAS_INT` source start index. +- **end**: `[in] CBLAS_INT` source end index. + +```c +void stdlib_strided_dcopy_within( const CBLAS_INT N, const CBLAS_INT target, double *x, const CBLAS_INT strideX, const CBLAS_INT start, const CBLAS_INT end ); +``` + + + +### stdlib_strided_dcopy_within_ndarray( N, target, \*x, strideX, offsetX, start, end ) + + + +Performs an in-place copy of elements within a double-precision floating-point array using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; + +stdlib_strided_dcopy_within_ndarray( 2, 2, x, 1, 1, 0, 2 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **target**: `[in] CBLAS_INT` target index. +- **x**: `[inout] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. +- **offsetX**: `[in] CBLAS_INT` starting index. +- **start**: `[in] CBLAS_INT` source start index. +- **end**: `[in] CBLAS_INT` source end index. + +```c +void stdlib_strided_dcopy_within_ndarray( const CBLAS_INT N, const CBLAS_INT target, double *x, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT start, const CBLAS_INT end ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dcopy_within.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // Specify the number of elements to copy: + const int N = 3; + + // Specify a stride: + const int strideX = 1; + + // Copy elements starting from index 1 to index 4: + stdlib_strided_dcopy_within( N, 4, x, strideX, 1, 4 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.js new file mode 100644 index 000000000000..ef85a070adce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var dcopyWithin = require( './../lib/dcopy_within.js' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + 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 = dcopyWithin( len, 0, x, 1, 0, len-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( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.native.js new file mode 100644 index 000000000000..d03e014f45fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.native.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dcopyWithin = tryRequire( resolve( __dirname, './../lib/dcopy_within.native.js' ) ); +var opts = { + 'skip': ( dcopyWithin instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + 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 = dcopyWithin( len, 0, x, 1, 0, len-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( pkg+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..b87a2c6452dc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var dcopyWithin = require( './../lib/ndarray.js' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + 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 = dcopyWithin( len, 0, x, 1, 0, 0, len-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( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..3ab56ded3fcc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dcopyWithin = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dcopyWithin instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + 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 = dcopyWithin( len, 0, x, 1, 0, 0, len-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( pkg+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/Makefile new file mode 100644 index 000000000000..cce2c865d7ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..1df29194406d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/benchmark/c/benchmark.length.c @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/blas/ext/base/dcopy_within.h" +#include "stdlib/blas/base/shared.h" +#include +#include +#include +#include +#include + +#define NAME "dcopy_within" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmark results. +* +* @param prefix comment prefix +* @param elapsed elapsed time in seconds +*/ +static void print_results( const char* prefix, double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( "# %s\n", prefix ); + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random double on the interval [-100,100). +* +* @return random double +*/ +static double rand_double( void ) { + int r = rand(); + return -100.0 + (r/(double)RAND_MAX)*200.0; +} + +/** +* Run a benchmark which tests `stdlib_strided_dcopy_within`. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + double x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + API_SUFFIX(stdlib_strided_dcopy_within)( len, 0, x, 1, 0, len-1 ); + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Run a benchmark which tests `stdlib_strided_dcopy_within_ndarray`. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + API_SUFFIX(stdlib_strided_dcopy_within_ndarray)( len, 0, x, 1, 0, 0, len-1 ); + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + + // Run benchmarks: + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + if ( iter < 1 ) { + iter = 1; + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( "dcopy_within:len", elapsed ); + printf( "ok %d benchmark finished\n", count ); + + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( "dcopy_within_ndarray:len", elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); + + return 0; +} + diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/repl.txt new file mode 100644 index 000000000000..8d80ab800c68 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/repl.txt @@ -0,0 +1,110 @@ + +{{alias}}( N, target, x, strideX, start, end ) + Performs an in-place copy of elements within a double-precision + floating-point 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. + + Parameters + ---------- + N: integer + Number of indexed elements. + + target: integer + Target index. + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + start: integer + Source start index. + + end: integer + Source end index. + + Returns + ------- + x: Float64Array + Input array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > {{alias}}( 3, 2, x, 1, 1, 2 ) + [ 1.0, 2.0, 2.0, 4.0, 5.0, 6.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + > {{alias}}( 3, 0, x, 2, 1, 6 ) + [ 3.0, 2.0, 5.0, 4.0, 7.0, 6.0, 7.0, 8.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 2, 0, x1, 1, 2, 5 ) + [ 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, x, strideX, offsetX, start, end ) + Performs an in-place copy of elements within a double-precision + floating-point strided array using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + target: integer + Target index. + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + start: integer + Source start index. + + end: integer + Source end index. + + Returns + ------- + x: Float64Array + Input array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > {{alias}}.ndarray( 2, 2, x, 1, 1, 0, 5 ) + [ 1.0, 2.0, 3.0, 2.0, 3.0, 6.0 ] + + // Using an index offset: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > {{alias}}.ndarray( 2, 3, x, 1, 2, 0, 5 ) + [ 1.0, 2.0, 3.0, 4.0, 5.0, 3.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/index.d.ts new file mode 100644 index 000000000000..ec14982fdb74 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/index.d.ts @@ -0,0 +1,101 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/** +* Interface describing `dcopyWithin`. +*/ +interface Routine { + /** + * Performs an in-place copy of elements within a double-precision floating-point array. + * + * @param N - number of indexed elements to copy + * @param target - target index + * @param x - input array + * @param strideX - stride length + * @param start - source start index + * @param end - source end index + * @returns input array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * dcopyWithin( 2, 2, x, 1, 1, 3 ); + * // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] + */ + ( N: number, target: number, x: Float64Array, strideX: number, start: number, end: number ): Float64Array; + + /** + * Performs an in-place copy of elements within a double-precision floating-point array using alternative indexing semantics. + * + * @param N - number of indexed elements to copy + * @param target - target index + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @param start - source start index + * @param end - source end index + * @returns input array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * dcopyWithin.ndarray( 2, 2, x, 1, 0, 1, 3 ); + * // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] + */ + ndarray( N: number, target: number, x: Float64Array, strideX: number, offsetX: number, start: number, end: number ): Float64Array; +} + +/** +* Performs an in-place copy of elements within a double-precision floating-point array. +* +* @param N - number of indexed elements to copy +* @param target - target index +* @param x - input array +* @param strideX - stride length +* @param start - source start index +* @param end - source end index +* @returns input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin( 2, 2, x, 1, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin.ndarray( 2, 2, x, 1, 0, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +*/ +declare var dcopyWithin: Routine; + + +// EXPORTS // + +export = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/test.ts new file mode 100644 index 000000000000..87097baa76d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/docs/types/test.ts @@ -0,0 +1,159 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dcopyWithin = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin( 3, 3, x, 1, 1, 2 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin( '3', 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( true, 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( false, 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( null, 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( undefined, 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( [], 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( {}, 3, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( ( x: number ): number => x, 3, x, 1, 1, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin( 3, '3', x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, true, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, false, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, null, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, undefined, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, [], x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, {}, x, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, ( x: number ): number => x, x, 1, 1, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + dcopyWithin( 3, 3, '3', 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, 3, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, true, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, false, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, null, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, undefined, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, [], 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, {}, 1, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, ( x: number ): number => x, 1, 1, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin( 3, 3, x, '1', 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, true, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, false, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, null, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, undefined, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, [], 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, {}, 1, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, ( x: number ): number => x, 1, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin( 3, 3, x, 1, '1', 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, true, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, false, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, null, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, undefined, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, [], 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, {}, 2 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin( 3, 3, x, 1, 1, '4' ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, true ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, false ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, null ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, [] ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, {} ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin(); // $ExpectError + dcopyWithin( 3 ); // $ExpectError + dcopyWithin( 3, 3 ); // $ExpectError + dcopyWithin( 3, 3, x ); // $ExpectError + dcopyWithin( 3, 3, x, 1 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1 ); // $ExpectError + dcopyWithin( 3, 3, x, 1, 1, 2, {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin.ndarray( 3, 3, x, 1, 1, 1, 2 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin.ndarray( '2', 3, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( true, 3, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( false, 3, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( null, 3, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( undefined, 3, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( [], 2, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( {}, 2, x, 1, 1, 1, 2 ); // $ExpectError + dcopyWithin.ndarray( ( x: number ): number => x, 2, x, 1, 1, 1, 2 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided insufficient arguments... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + dcopyWithin.ndarray(); // $ExpectError + dcopyWithin.ndarray( 2 ); // $ExpectError + dcopyWithin.ndarray( 2, 2 ); // $ExpectError + dcopyWithin.ndarray( 2, 2, x ); // $ExpectError + dcopyWithin.ndarray( 2, 2, x, 1 ); // $ExpectError + dcopyWithin.ndarray( 2, 2, x, 1, 1 ); // $ExpectError + dcopyWithin.ndarray( 2, 2, x, 1, 1, 1 ); // $ExpectError + dcopyWithin.ndarray( 2, 2, x, 1, 1, 1, 2, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile new file mode 100644 index 000000000000..ff5293d3059f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/example.c new file mode 100644 index 000000000000..0988f49653fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/example.c @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/blas/ext/base/dcopy_within.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // Specify the number of elements to copy: + const int N = 3; + + // Specify a stride: + const int strideX = 1; + + // Copy elements starting from index 1 to index 4: + stdlib_strided_dcopy_within( N, 4, x, strideX, 1, 4 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/index.js new file mode 100644 index 000000000000..b6b3e5b2e69d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dcopyWithin = require( './../lib' ); + +var x = discreteUniform( 10, 0, 500, { + 'dtype': 'float64' +}); +console.log( x ); + +// Copy the first 3 elements to positions 5, 6, 7: +dcopyWithin( 3, 5, x, 1, 0, 3 ); +console.log( x ); + +// Copy every other element starting from the second element: +dcopyWithin( 5, 0, x, 1, 1, 9 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +*/ +function dcopyWithin( N, target, x, strideX, start, end ) { + if ( N <= 0 ) { + return x; + } + return ndarray( N, target, x, strideX, stride2offset( N, strideX ), start, end ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/dcopy_within.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/dcopy_within.native.js new file mode 100644 index 000000000000..9649571b6f0e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/dcopy_within.native.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Performs an in-place copy of elements within a double-precision floating-point array. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} target - target index +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {integer} start - source start index +* @param {integer} end - source end index +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin( 2, 2, x, 1, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +*/ +function dcopyWithin( N, target, x, strideX, start, end ) { + addon( N, target, x, strideX, start, end ); + return x; +} + + +// EXPORTS // + +module.exports = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/index.js new file mode 100644 index 000000000000..dec0f111e234 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 double-precision floating-point array. +* +* @module @stdlib/blas/ext/base/dcopy-within +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin( 2, 2, x, 1, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dcopyWithin = require( '@stdlib/blas/ext/base/dcopy-within' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin.ndarray( 2, 2, x, 1, 0, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dcopyWithin; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dcopyWithin = main; +} else { + dcopyWithin = tmp; +} + + +// EXPORTS // + +module.exports = dcopyWithin; + +// exports: { "ndarray": "dcopyWithin.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/main.js new file mode 100644 index 000000000000..4207d1135fd0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dcopyWithin = require( './dcopy_within.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dcopyWithin, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/native.js new file mode 100644 index 000000000000..f6ea7782df7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/native.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dcopyWithin = require( './dcopy_within.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dcopyWithin, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.js new file mode 100644 index 000000000000..cfd163b429f9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var min = require( '@stdlib/math/base/special/min' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var Float64Array = require( '@stdlib/array/float64' ); + + +// MAIN // + +/** +* Performs an in-place copy of elements within a double-precision floating-point array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} target - target index +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {integer} start - source start index +* @param {integer} end - source end index +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin( 2, 2, x, 1, 0, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +*/ +function dcopyWithin( N, target, x, strideX, offsetX, start, end ) { + var targetIdx; + var tmp; + var cl; + var o; + var i; + + if ( N <= 0 ) { + return x; + } + + // Resolve copy length: + cl = min( abs( end - start ), N ); + + // Create a temporary copy of source elements: + tmp = new Float64Array( cl ); + if ( strideX > 0 ) { + o = offsetX + ( start * strideX ); + } else { + o = start; + } + // Copy source elements to temporary array: + for ( i = 0; i < cl; i++ ) { + tmp[ i ] = x[ o ]; + o += strideX; + } + + // Resolve the target index: + if ( strideX > 0 ) { + targetIdx = offsetX + ( target * strideX ); + } else { + targetIdx = target; + } + + // Allocate elements to target position: + for ( i = 0; i < cl; i++ ) { + x[ targetIdx ] = tmp[ i ]; + targetIdx += strideX; + } + return x; +} + + +// EXPORTS // + +module.exports = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.native.js new file mode 100644 index 000000000000..c24c38f49f1d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/lib/ndarray.native.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Performs an in-place copy of elements within a double-precision floating-point array. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} target - target index +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {integer} start - source start index +* @param {integer} end - source end index +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* dcopyWithin( 2, 2, x, 1, 0, 1, 3 ); +* // x => [ 1.0, 2.0, 2.0, 3.0, 5.0, 6.0 ] +*/ +function dcopyWithin( N, target, x, strideX, offsetX, start, end ) { + addon.ndarray( N, target, x, strideX, offsetX, start, end ); + return x; +} + + +// EXPORTS // + +module.exports = dcopyWithin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/manifest.json new file mode 100644 index 000000000000..ae3425297fdd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/manifest.json @@ -0,0 +1,102 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/special/abs", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/special/abs" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/special/abs" + ] + }, + { + "task": "build", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/special/abs" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/package.json b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/package.json new file mode 100644 index 000000000000..76ffc0003087 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/ext/base/dcopy-within", + "version": "0.0.0", + "description": "Perform an in-place copy of elements within a double-precision floating-point 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", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "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", + "float64", + "double", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/addon.c new file mode 100644 index 000000000000..ab89b7953339 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/addon.c @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/blas/ext/base/dcopy_within.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, target, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, start, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, end, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, x, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dcopy_within)( N, target, x, strideX, start, end ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, target, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, start, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, end, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, x, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dcopy_within_ndarray)( N, target, x, strideX, offsetX, start, end ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/main.c new file mode 100644 index 000000000000..b565bd90e167 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/src/main.c @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/blas/ext/base/dcopy_within.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/math/base/special/abs.h" +#include + +/** +* Performs an in-place copy of elements within a double-precision floating-point array. +* +* @param N number of indexed elements +* @param target target index +* @param x input array +* @param strideX stride length +* @param start source start index +* @param end source end index +*/ +void API_SUFFIX(stdlib_strided_dcopy_within)( const CBLAS_INT N, const CBLAS_INT target, double *x, const CBLAS_INT strideX, const CBLAS_INT start, const CBLAS_INT end ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(stdlib_strided_dcopy_within_ndarray)( N, target, x, strideX, ox, start, end ); +} + +/** +* Performs an in-place copy of elements within a double-precision floating-point array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param target target index +* @param x input array +* @param strideX stride length +* @param offsetX starting index +* @param start source start index +* @param end source end index +*/ +void API_SUFFIX(stdlib_strided_dcopy_within_ndarray)( const CBLAS_INT N, const CBLAS_INT target, double *x, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT start, const CBLAS_INT end ) { + CBLAS_INT targetIdx; + double *tmp; + CBLAS_INT cl; + CBLAS_INT o; + CBLAS_INT i; + + if ( N <= 0 ) { + return; + } + + // Resolve copy length: + if ( stdlib_base_abs( end - start ) < N ) { + cl = stdlib_base_abs( end - start ); + } else { + cl = N; + } + + // Allocate temporary array and extract source elements: + tmp = (double *)malloc( cl * sizeof(double) ); + if ( tmp == NULL ) { + return; + } + + // Calculate source offset based on stride direction: + if ( strideX > 0 ) { + o = offsetX + ( start * strideX ); + } else { + o = start; + } + + // Copy source elements to temporary array: + for ( i = 0; i < cl; i++ ) { + tmp[ i ] = x[ o ]; + o += strideX; + } + + // Resolve the target index: + if ( strideX > 0 ) { + targetIdx = offsetX + ( target * strideX ); + } else { + targetIdx = target; + } + + // Allocate elements to target position: + for ( i = 0; i < cl; i++ ) { + x[ targetIdx ] = tmp[ i ]; + targetIdx += strideX; + } + + // Clean up memory: + free( tmp ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.js new file mode 100644 index 000000000000..da54090ed181 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dcopyWithin = require( './../lib/dcopy_within.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( dcopyWithin.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided double-precision floating-point strided array', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] ); + + actual = dcopyWithin( 3, 3, x, 1, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 6, 6, x, 1, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 1.0 ] ); + + actual = dcopyWithin( 4, 5, x, 1, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 1.0, 2.0, 3.0 ] ); + + actual = dcopyWithin( 3, 2, x, 1, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a stride parameter', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + expected = new Float64Array( [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + actual = dcopyWithin( 2, 0, x, 2, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing negative strides', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 5.0, 6.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 3, 2, x, -1, 5, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 2, 3, x, -1, 5, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 0, 3, x, 1, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = dcopyWithin( -1, 3, x, 1, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.native.js new file mode 100644 index 000000000000..1f42bb3f0652 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.dcopy_within.native.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isBrowser = require( '@stdlib/assert/is-browser' ); +var isError = require( '@stdlib/assert/is-error' ); +var Float64Array = require( '@stdlib/array/float64' ); + + +// VARIABLES // + +var dcopyWithin = tryRequire( resolve( __dirname, './../lib/dcopy_within.native.js' ) ); +var opts = { + 'skip': ( isBrowser || isError( dcopyWithin ) ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', opts, function test( t ) { + t.strictEqual( dcopyWithin.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles overlapping copy regions', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 1.0, 2.0, 3.0 ] ); + + actual = dcopyWithin( 3, 2, x, 1, 0, 3 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided double-precision floating-point strided array', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] ); + + actual = dcopyWithin( 3, 3, x, 1, 1, 4 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + + // Test case where target >= N (should return unchanged): + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 6, 6, x, 1, 0, 3 ); + t.strictEqual( actual, x, 'returns input array when target >= N' ); + t.deepEqual( x, expected, 'returns expected value when target >= N' ); + + actual = dcopyWithin( 6, 10, x, 1, 0, 3 ); + t.strictEqual( actual, x, 'returns input array when target > N' ); + t.deepEqual( x, expected, 'returns expected value when target > N' ); + + t.end(); +}); + +tape( 'the function supports providing a stride parameter', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + expected = new Float64Array( [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + actual = dcopyWithin( 2, 0, x, 2, 1, 4 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing negative strides', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 5.0, 6.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 3, 2, x, -1, 5, 3 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 2, 3, x, -1, 5, 0 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 0, 3, x, 1, 1, 4 ); + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = dcopyWithin( -1, 3, x, 1, 1, 4 ); + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.js new file mode 100644 index 000000000000..7ad0d8c87111 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 proxyquire = require( 'proxyquire' ); +var isBrowser = require( '@stdlib/assert/is-browser' ); +var dcopyWithin = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dcopyWithin, '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 dcopyWithin.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dcopyWithin = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dcopyWithin, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', function test( t ) { + var dcopyWithin; + var main; + + main = require( './../lib/main.js' ); + + dcopyWithin = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dcopyWithin, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot resolve module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.js new file mode 100644 index 000000000000..6b4dd6b5f636 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dcopyWithin = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( dcopyWithin.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided double-precision floating-point strided array', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] ); + + actual = dcopyWithin( 3, 3, x, 1, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 6, 6, x, 1, 0, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 1.0 ] ); + + actual = dcopyWithin( 4, 5, x, 1, 0, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 1.0, 2.0, 3.0 ] ); + + actual = dcopyWithin( 3, 2, x, 1, 0, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an offset parameter', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 2.0, 3.0 ] ); + + actual = dcopyWithin( 2, 3, x, 1, 1, 0, 2 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a stride parameter', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + expected = new Float64Array( [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + actual = dcopyWithin( 2, 0, x, 2, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing negative strides', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 5.0, 6.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 3, 2, x, -1, 0, 5, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 2, 3, x, -1, 0, 5, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 0, 3, x, 1, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = dcopyWithin( -1, 3, x, 1, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.native.js new file mode 100644 index 000000000000..f5f902784a76 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/test/test.ndarray.native.js @@ -0,0 +1,165 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isBrowser = require( '@stdlib/assert/is-browser' ); +var isError = require( '@stdlib/assert/is-error' ); +var Float64Array = require( '@stdlib/array/float64' ); + + +// VARIABLES // + +var dcopyWithin = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( isBrowser || isError( dcopyWithin ) ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dcopyWithin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', opts, function test( t ) { + t.strictEqual( dcopyWithin.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies values within the provided double-precision floating-point strided array', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 3.0, 4.0 ] ); + + actual = dcopyWithin( 3, 3, x, 1, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 6, 6, x, 1, 0, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 1.0 ] ); + + actual = dcopyWithin( 4, 5, x, 1, 0, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 1.0, 2.0, 3.0 ] ); + + actual = dcopyWithin( 3, 2, x, 1, 0, 0, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an offset parameter', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 2.0, 3.0 ] ); + + actual = dcopyWithin( 2, 3, x, 1, 1, 0, 2 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing a stride parameter', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + expected = new Float64Array( [ 3.0, 2.0, 5.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + actual = dcopyWithin( 2, 0, x, 2, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns input array' ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing negative strides', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 5.0, 6.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 3, 2, x, -1, 0, 5, 3 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 2, 3, x, -1, 0, 5, 0 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the strided array unchanged if `N` is less than or equal to `0`', opts, function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + actual = dcopyWithin( 0, 3, x, 1, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + actual = dcopyWithin( -1, 3, x, 1, 0, 1, 4 ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); From 9724d8bae9bb6328410647243d5a0d72074344a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 13 Oct 2025 19:07:49 +0000 Subject: [PATCH 2/2] chore: update copyright years --- .../@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile index ff5293d3059f..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile +++ b/lib/node_modules/@stdlib/blas/ext/base/dcopy-within/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# Copyright (c) 2025 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.