diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md new file mode 100644 index 000000000000..c3357bf519ef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md @@ -0,0 +1,391 @@ + + +# sdiff + +> Calculate the k-th discrete forward difference of a single-precision floating-point strided array. + +
+ +## Usage + +```javascript +var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); +``` + + + +#### sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 6 ); +var w = new Float32Array( 6 ); + +sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **k**: number of times to recursively compute differences. +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. +- **N1**: number of elements to `prepend`. +- **prepend**: a [`Float32Array`][@stdlib/array/float32] containing values to prepend prior to computing differences. +- **strideP**: stride length for `prepend`. +- **N2**: number of elements to `append`. +- **append**: a [`Float32Array`][@stdlib/array/float32] containing values to append prior to computing differences. +- **strideA**: stride length for `append`. +- **out**: output [`Float32Array`][@stdlib/array/float32]. Must have `N + N1 + N2 - k` elements. +- **strideOut**: stride length for `out`. +- **workspace**: workspace [`Float32Array`][@stdlib/array/float32]. Must have `N + N1 + N2 - 1` elements. +- **strideW**: stride length for `workspace`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to differences of every other element: + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 4 ); +var w = new Float32Array( 4 ); + +sdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 1.0, 4.0, 4.0, 1.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +// Initial array... +var x0 = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + +// Create an offset view... +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 5 ); +var w = new Float32Array( 5 ); + +sdiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 3.0, 2.0, 2.0, 2.0, 1.0 ] +``` + + + +#### sdiff.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 6 ); +var w = new Float32Array( 6 ); + +sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetP**: starting index for `prepend`. +- **offsetA**: starting index for `append`. +- **offsetOut**: starting index for `out`. +- **offsetW**: starting index of `workspace`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 4 ); +var w = new Float32Array( 4 ); + +sdiff.ndarray( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( out ); +// out => [ 5.0, 2.0, 2.0, 1.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the output array unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Append array: ', a ); + +var out = new Float32Array( 10 ); + +var w = new Float32Array( 13 ); + +sdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); +console.log( 'Output', out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/sdiff.h" +``` + + + +#### stdlib_strided_sdiff( N, k, \*X, strideX, N1, \*prepend, strideP, N2, \*append, strideA, \*Out, strideOut, \*Workspace, strideW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array. + +```c +const float x[] = { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f }; +const float p[] = { 1.0f }; +const float a[] = { 11.0f }; +float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; +float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_sdiff( 5, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **k**: `[in] CBLAS_INT` number of times to recursively compute differences. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `x`. +- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. +- **prepend**: `[in] float*` array containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. +- **N2**: `[in] CBLAS_INT` number of elements in `append`. +- **append**: `[in] float*` array containing values to append prior to computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `append`. +- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `out`. +- **Workspace**: `[inout] float*` workspace array. Must have `N + N1 + N2 - 1` elements. +- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. + +```c +void stdlib_strided_sdiff( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ); +``` + + + +#### stdlib_strided_sdiff_ndarray( N, k, \*X, strideX, offsetX, N1, \*prepend, strideP, offsetP, N2, \*append, strideA, offsetA, \*Out, strideOut, offsetOut, \*Workspace, strideW, offsetW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. + +```c +const float x[] = { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f }; +const float p[] = { 1.0f }; +const float a[] = { 11.0f }; +float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; +float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_sdiff_ndarray( 5, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **k**: `[in] CBLAS_INT` number of times to recursively compute differences. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `x`. +- **offsetX**: `[in] CBLAS_INT` starting index for `x`. +- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. +- **prepend**: `[in] float*` array containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. +- **offsetP**: `[in] CBLAS_INT` starting index for `prepend`. +- **N2**: `[in] CBLAS_INT` number of elements in `append`. +- **append**: `[in] float*` array containing values to append prior to computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `append`. +- **offsetA**: `[in] CBLAS_INT` starting index for `append`. +- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `out`. +- **offsetOut**: `[in] CBLAS_INT` starting index for `out`. +- **Workspace**: `[inout] float*` workspace array. Must have `N + N1 + N2 - 1` elements. +- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. +- **offsetW**: `[in] CBLAS_INT` starting index for `workspace`. + +```c +void stdlib_strided_sdiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/sdiff.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Define prepend values: + const float p[] = { -1.0f }; + + // Define append values: + const float a[] = { 10.0f }; + + // Define output array: + float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Define workspace: + float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Compute forward differences: + stdlib_strided_sdiff( 8, 3, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + // Print the result: + for ( int i = 0; i < 7; i++ ) { + printf( "out[ %i ] = %f\n", i, out[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js new file mode 100644 index 000000000000..b9d5ad893ff7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var sdiff = require( './../lib/sdiff.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js new file mode 100644 index 000000000000..e4df3440af8c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; +var sdiff = tryRequire( resolve( __dirname, './../lib/sdiff.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..a308547d5137 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var sdiff = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..ac03c4d98d29 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; +var sdiff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:ndarray:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# 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/sdiff/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..ca14bf52618d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c @@ -0,0 +1,273 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include +#include +#include +#include +#include + +#define NAME "sdiff" +#define ITERATIONS 1000000 +#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 benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + 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 number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float *x; + float *p; + float *a; + float *o; + float *w; + double t; + int wl; + int ol; + int N1; + int N2; + int k; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + wl = N + N1 + N2 - 1; + + x = (float *) malloc( N * sizeof( float ) ); + for ( i = 0; i < N; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + p = (float *) malloc( N1 * sizeof( float ) ); + a = (float *) malloc( N2 * sizeof( float ) ); + for ( i = 0; i < N1; i++ ) { + p[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + a[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + w = (float *) malloc( wl * sizeof( float ) ); + for ( i = 0; i < wl; i++ ) { + w[ i ] = 0.0f; + } + + o = (float *) malloc( ol * sizeof( float ) ); + for ( i = 0; i < ol; i++ ) { + o[ i ] = 0.0f; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( o[ 0 ] != o[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( o[ ol-1 ] != o[ ol-1 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( p ); + free( a ); + free( w ); + free( o ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float *x; + float *p; + float *a; + float *o; + float *w; + double t; + int wl; + int ol; + int N1; + int N2; + int k; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + wl = N + N1 + N2 - 1; + + x = (float *) malloc( N * sizeof( float ) ); + for ( i = 0; i < N; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + p = (float *) malloc( N1 * sizeof( float ) ); + a = (float *) malloc( N2 * sizeof( float ) ); + for ( i = 0; i < N1; i++ ) { + p[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + a[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + w = (float *) malloc( wl * sizeof( float ) ); + for ( i = 0; i < wl; i++ ) { + w[ i ] = 0.0f; + } + + o = (float *) malloc( ol * sizeof( float ) ); + for ( i = 0; i < ol; i++ ) { + o[ i ] = 0.0f; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_sdiff_ndarray( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( o[ 0 ] != o[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( o[ ol-1 ] != o[ ol-1 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( p ); + free( a ); + free( w ); + free( o ); + 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; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp @@ -0,0 +1,265 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # 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 + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # 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/sdiff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt new file mode 100644 index 000000000000..2a828d16994e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt @@ -0,0 +1,187 @@ + +{{alias}}( N, k, x,sx, N1,p,sp, N2,a,sa, out,so, w,sw ) + Calculates the k-th discrete forward differences of a single-precision + floating-point strided array. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns the output array unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of times to recursively compute differences. + + x: Float32Array + Input array. + + sx: integer + Stride length for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Float32Array + Array containing values to prepend prior to computing differences. + + sp: integer + Stride length for `prepend`. + + N2: integer + Number of elements to `append`. + + a: Float32Array + Array containing values to append prior to computing differences. + + sa: integer + Stride length for `append`. + + out: Float32Array + Output array. + + so: integer + Stride length for `out`. + + w: Float32Array + Workspace array. + + sw: integer + Stride length for `workspace`. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 4 ); + > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > {{alias}}( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, -3.0, 4.0, 1.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > p = new {{alias:@stdlib/array/float32}}( [ 1.0 ] ); + > a = new {{alias:@stdlib/array/float32}}( [ 11.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 4 ); + > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > {{alias}}( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, 4.0, 4.0, 1.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > p = new {{alias:@stdlib/array/float32}}( [ 1.0 ] ); + > a = new {{alias:@stdlib/array/float32}}( [ 11.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 5 ); + > var w = new {{alias:@stdlib/array/float32}}( 5 ); + > {{alias}}( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 3.0, 2.0, 2.0, 2.0, 1.0 ] + + +{{alias}}.ndarray( N, k, X,sx,ox, N1,p,sp,op, N2,a,sa,oa, Out,so,oo, W,sw,ow ) + Calculates the k-th discrete forward differences of a single-precision + floating-point strided array using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of times to recursively compute differences. + + X: Float32Array + Input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Float32Array + Array containing values to prepend prior to computing differences. + + sp: integer + Stride length for `prepend`. + + op: integer + Starting index for `prepend`. + + N2: integer + Number of elements to `append`. + + a: Float32Array + Array containing values to append prior to computing differences. + + sa: integer + Stride length for `append`. + + oa: integer + Starting index for `append`. + + Out: Float32Array + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + W: Float32Array + Workspace array. + + sw: integer + Stride length for `workspace`. + + ow: integer + Starting index for `workspace`. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 4 ); + > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > {{alias}}.ndarray( 3, 1, x,1,0, 1, p,1,0, 1, a,1,0, out,1,0, w,1,0 ) + [ 1.0, -3.0, 4.0, 1.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); + > a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); + > out = new {{alias:@stdlib/array/float32}}( 3 ); + > w = new {{alias:@stdlib/array/float32}}( 3 ); + > {{alias}}.ndarray( 2, 1, x,1,1, 1, p,1,0, 1, a,1,0, out,1,0, w,1,0 ) + [ -2.0, 4.0, 1.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts new file mode 100644 index 000000000000..158d19b6d8b3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts @@ -0,0 +1,153 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `sdiff`. +*/ +interface Routine { + /** + * Calculates the k-th discrete forward difference of a single-precision floating-point strided array. + * + * @param N - number of indexed elements + * @param k - number of times to recursively compute differences + * @param x - input array + * @param strideX - stride length for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + * var p = new Float32Array( [ 1.0 ] ); + * var a = new Float32Array( [ 22.0 ] ); + * var out = new Float32Array( 5 ); + * var w = new Float32Array( 6 ); + * + * sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + * + * console.log( out ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ( N: number, k: number, x: Float32Array, strideX: number, N1: number, prepend: Float32Array, strideP: number, N2: number, append: Float32Array, strideA: number, out: Float32Array, strideOut: number, workspace: Float32Array, strideW: number ): Float32Array; + + /** + * Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param k - number of times to recursively compute differences + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param offsetP - starting index for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param offsetA - starting index for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @param offsetW - starting index for `workspace` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + * var p = new Float32Array( [ 1.0 ] ); + * var a = new Float32Array( [ 22.0 ] ); + * var out = new Float32Array( 5 ); + * var w = new Float32Array( 6 ); + * + * sdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + * + * console.log( out ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ndarray( N: number, k: number, x: Float32Array, strideX: number, offsetX: number, N1: number, prepend: Float32Array, strideP: number, offsetP: number, N2: number, append: Float32Array, strideA: number, offsetA: number, out: Float32Array, strideOut: number, offsetOut: number, workspace: Float32Array, strideW: number, offsetW: number ): Float32Array; +} + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param N - number of indexed elements +* @param k - number of times to recursively compute differences +* @param x - input array +* @param strideX - stride length for `x` +* @param N1 - number of indexed elements of prepend +* @param prepend - prepend array +* @param strideP - stride length for `prepend` +* @param N2 - number of indexed elements of append +* @param append - append array +* @param strideA - stride length for `append` +* @param out - output array +* @param strideOut - stride length for `out` +* @param workspace - workspace array +* @param strideW - stride length for `workspace` +* @returns output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +declare var sdiff: Routine; + + +// EXPORTS // + +export = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts new file mode 100644 index 000000000000..daafa1cd28eb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts @@ -0,0 +1,681 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import sdiff = require( './index' ); + + +// TESTS // + +// The function returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( '10', 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( true, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( false, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( null, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( undefined, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( [], 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( {}, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( ( x: number ): number => x, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, '10', x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, true, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, false, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, null, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, undefined, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, [], x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, {}, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, ( x: number ): number => x, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( 10, 1, '10', 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, false, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, null, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, undefined, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, [], 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, {}, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, ( x: number ): number => x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, '10', 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, true, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, false, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, null, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, undefined, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, [], 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, {}, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, ( x: number ): number => x, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, '10', p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, true, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, false, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, null, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, undefined, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, [], p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, {}, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, ( x: number ): number => x, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, '10', 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, true, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, false, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, null, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, undefined, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, [], 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, {}, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, ( x: number ): number => x, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, '10', 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, true, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, false, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, null, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, undefined, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, [], 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, {}, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, ( x: number ): number => x, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, '10', a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, true, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, false, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, null, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, undefined, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, [], a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, {}, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, ( x: number ): number => x, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, '10', 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, true, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, false, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, null, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, undefined, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, [], 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, {}, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, ( x: number ): number => x, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, '10', out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, true, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, false, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, null, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, undefined, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, [], out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, {}, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, ( x: number ): number => x, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, '10', 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, true, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, false, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, null, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, undefined, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, [], 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, {}, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, ( x: number ): number => x, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, '10', w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, true, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, false, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, null, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, undefined, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, [], w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, {}, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, ( x: number ): number => x, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a thirteenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, '10', 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, true, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, false, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, null, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, undefined, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, [], 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, {}, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, '10' ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, true ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, false ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, null ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, undefined ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, [] ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, {} ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff(); // $ExpectError + sdiff( x.length ); // $ExpectError + sdiff( x.length, 1 ); // $ExpectError + sdiff( x.length, 1, x ); // $ExpectError + sdiff( x.length, 1, x, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( '10', 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( true, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( false, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( null, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( undefined, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( [], 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( {}, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( ( x: number ): number => x, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, false, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, null, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, undefined, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, [], x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, {}, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, ( x: number ): number => x, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... +{ + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( 10, 1, '10', 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, [], 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, ( x: number ): number => x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, false, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, null, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, undefined, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, [], 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, {}, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, ( x: number ): number => x, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, false, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, null, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, undefined, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, [], 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, {}, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, ( x: number ): number => x, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, false, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, null, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, undefined, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, [], p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, {}, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, ( x: number ): number => x, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, '10', 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, false, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, null, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, undefined, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, [], 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, {}, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, ( x: number ): number => x, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, false, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, null, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, undefined, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, [], 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, {}, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, ( x: number ): number => x, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, '10', 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, true, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, false, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, null, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, undefined, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, [], 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, {}, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, ( x: number ): number => x, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, false, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, null, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, undefined, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, [], a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, {}, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, ( x: number ): number => x, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, '10', 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, false, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, null, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, undefined, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, [], 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, {}, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, ( x: number ): number => x, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, false, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, null, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, undefined, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, [], 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, {}, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, ( x: number ): number => x, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, false, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, null, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, undefined, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, [], out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, {}, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, ( x: number ): number => x, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourteenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, '10', 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, false, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, null, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, undefined, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, [], 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, {}, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, ( x: number ): number => x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, false, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, null, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, undefined, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, [], 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, {}, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10', w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, false, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, null, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, undefined, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, [], w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, {}, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventeenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, '10', 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, true, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, false, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, null, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, undefined, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, [], 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, {}, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, '10', 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, true, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, false, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, null, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, undefined, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, [], 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, {}, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a nineteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, '10' ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, true ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, false ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, null ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, undefined ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, [] ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, {} ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray(); // $ExpectError + sdiff.ndarray( x.length ); // $ExpectError + sdiff.ndarray( x.length, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# 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/sdiff/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c new file mode 100644 index 000000000000..0a17b25467ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Define prepend values: + const float p[] = { -1.0f }; + + // Define append values: + const float a[] = { 10.0f }; + + // Define output array: + float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Define workspace: + float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Compute forward differences: + stdlib_strided_sdiff( 8, 3, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + // Print the result: + for ( int i = 0; i < 7; i++ ) { + printf( "out[ %i ] = %f\n", i, out[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js new file mode 100644 index 000000000000..c4e79b629048 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Append array: ', a ); + +var out = new Float32Array( 10 ); + +var w = new Float32Array( 13 ); + +sdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); +console.log( 'Output', out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi new file mode 100644 index 000000000000..dcb556d250e8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi @@ -0,0 +1,70 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.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 sdiff; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + sdiff = main; +} else { + sdiff = tmp; +} + + +// EXPORTS // + +module.exports = sdiff; + +// exports: { "ndarray": "sdiff.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js new file mode 100644 index 000000000000..96560206424c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var sdiff = require( './sdiff.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( sdiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js new file mode 100644 index 000000000000..aea31a58b03b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var sdiff = require( './sdiff.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( sdiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js new file mode 100644 index 000000000000..dd4fbf154b3c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js @@ -0,0 +1,248 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var scopy = require( '@stdlib/blas/base/scopy' ); + + +// FUNCTIONS // + +/** +* Calculates the forward difference of a single-precision floating-point strided array using alternative indexing semantics. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @returns {Float32Array} output array +*/ +function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var total; + var prev; + var curr; + var ix; + var io; + var ip; + var ia; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + if ( N1 === 0 && N2 === 0 ) { + ix = offsetX; + io = offsetOut; + prev = x[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + return out; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = x[ offsetX ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = x[ offsetX ]; + io = offsetOut; + } else { + prev = append[ offsetA ]; + io = offsetOut; + } + + // x + if ( N > 0 ) { + ix = offsetX; + if ( N1 === 0 ) { + prev = x[ ix ]; + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = append[ ia ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ia += strideA; + } + } + return out; +} + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {PositiveInteger} offsetW - starting index for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + var total; + var io; + var n; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + // If k >= total number of elements, the k-th forward difference results in an empty array, so this function is a no-op. + if ( k >= total ) { + return out; + } + + if ( k === 0 ) { + // Copy `prepend` into output array: + scopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + + // Copy `x` into output array: + io = offsetOut + ( N1 * strideOut ); + scopy.ndarray( N, x, strideX, offsetX, out, strideOut, io ); + + // Copy `append` into output array: + io = offsetOut + ( ( N1 + N ) * strideOut ); + scopy.ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + + return out; + } + + if ( k === 1 ) { + base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; + } + + base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, workspace, strideW, offsetW ); + + n = total - 1; + for ( i = 1; i < k - 1; i++ ) { + base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, workspace, strideW, offsetW ); + n -= 1; + } + + base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js new file mode 100644 index 000000000000..113c33ce6552 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {PositiveInteger} offsetW - starting index for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + addon.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js new file mode 100644 index 000000000000..2792282d0f0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) { + var ox = stride2offset( N, strideX ); + var op = stride2offset( N1, strideP ); + var oa = stride2offset( N2, strideA ); + var oo = stride2offset( N + N1 + N2 - k, strideOut ); + var ow = stride2offset( N + N1 + N2 - 1, strideW ); + ndarray( N, k, x, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo, workspace, strideW, ow ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js new file mode 100644 index 000000000000..cb70f8cf692c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) { + addon( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json new file mode 100644 index 000000000000..f9ac5c23cdb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json @@ -0,0 +1,81 @@ +{ + "options": { + "task": "build" + }, + "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", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/scopy", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/scopy" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/scopy" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json b/lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json new file mode 100644 index 000000000000..7de10049bfe3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/ext/base/sdiff", + "version": "0.0.0", + "description": "Calculate the k-th discrete forward difference of a single-precision floating-point strided array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "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", + "diff", + "difference", + "gradient", + "strided", + "array", + "float32", + "float", + "float32array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# 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/sdiff/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c new file mode 100644 index 000000000000..2b7f1dee233e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.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_float32array.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, 14 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-k, strideOut, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Workspace, N+N1+N2-1, strideW, argv, 12 ); + API_SUFFIX(stdlib_strided_sdiff)( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, Out, strideOut, Workspace, strideW ); + 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, 19 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, offsetP, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 12 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 14 ); + STDLIB_NAPI_ARGV_INT64( env, offsetOut, argv, 15 ); + STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 17 ); + STDLIB_NAPI_ARGV_INT64( env, offsetW, argv, 18 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-k, strideOut, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Workspace, N+N1+N2-1, strideW, argv, 16 ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut, Workspace, strideW, offsetW ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c new file mode 100644 index 000000000000..d265a72a2f28 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c @@ -0,0 +1,235 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/scopy.h" + +/** +* Calculates the k-th discrete forward differences of a single-precision floating-point strided array. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param X input array +* @param strideX stride length for X +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for prepend +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for append +* @param Out Output array +* @param strideOut stride length for Out +* @param Workspace Workspace array +* @param strideW stride length for Workspace +*/ +void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT op = stdlib_strided_stride2offset( N1, strideP ); + CBLAS_INT oa = stdlib_strided_stride2offset( N2, strideA ); + CBLAS_INT oo = stdlib_strided_stride2offset( N+N1+N2-k, strideOut ); + CBLAS_INT ow = stdlib_strided_stride2offset( N+N1+N2-1, strideW ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, Out, strideOut, oo, Workspace, strideW, ow ); +} + +/** +* Calculates the forward difference of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length for X +* @param offsetX starting index for X +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for prepend +* @param offsetP starting index for prepend +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for append +* @param offsetA starting index for append +* @param Out Output array +* @param strideOut stride length for Out +* @param offsetOut starting index for Out +*/ +static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { + CBLAS_INT total; + CBLAS_INT ix; + CBLAS_INT io; + CBLAS_INT ip; + CBLAS_INT ia; + CBLAS_INT i; + float prev; + float curr; + + total = N + N1 + N2; + if ( total <= 1 ) { + return; + } + + if ( N1 == 0 && N2 == 0 ) { + ix = offsetX; + io = offsetOut; + prev = X[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = X[ ix ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + return; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = X[ offsetX ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = X[ offsetX ]; + io = offsetOut; + } else { + prev = append[ offsetA ]; + io = offsetOut; + } + + // X + if ( N > 0 ) { + ix = offsetX; + if ( N1 == 0 ) { + prev = X[ ix ]; + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = X[ ix ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = X[ ix ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = append[ offsetA ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = append[ ia ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ia += strideA; + } + } +} + +/** +* Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param X input array +* @param strideX stride length for X +* @param offsetX starting index for X +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for prepend +* @param offsetP starting index for prepend +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for append +* @param offsetA starting index for append +* @param Out Output array +* @param strideOut stride length for Out +* @param offsetOut starting index for Out +* @param Workspace Workspace array +* @param strideW stride length for Workspace +* @param offsetW starting index for Workspace +*/ +void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { + CBLAS_INT total; + CBLAS_INT io; + CBLAS_INT n; + CBLAS_INT i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return; + } + if ( k >= total ) { + return; + } + if ( k == 0 ) { + // Copy `prepend` into Output array: + c_scopy_ndarray( N1, prepend, strideP, offsetP, Out, strideOut, offsetOut ); + + // Copy `X` into Output array: + io = offsetOut + ( N1 * strideOut ); + c_scopy_ndarray( N, X, strideX, offsetX, Out, strideOut, io ); + + // Copy `append` into Output array: + io = offsetOut + ( ( N1 + N ) * strideOut ); + c_scopy_ndarray( N2, append, strideA, offsetA, Out, strideOut, io ); + return; + } + if ( k == 1 ) { + stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut ); + return; + } + stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Workspace, strideW, offsetW ); + + n = total - 1; + for ( i = 1; i < k - 1; i++ ) { + stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Workspace, strideW, offsetW ); + n -= 1; + } + stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Out, strideOut, offsetOut ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js new file mode 100644 index 000000000000..2baa802ca7f0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sdiff = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof sdiff.ndarray, 'function', 'has method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js new file mode 100644 index 000000000000..4b47fab22dbd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js @@ -0,0 +1,302 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Single element (total <= 1 in base): + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides and offsets', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Offset for `x`: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 5.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 4, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 2, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 2, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 3, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js new file mode 100644 index 000000000000..b63122560dfb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js @@ -0,0 +1,310 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sdiff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides and offsets', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Offset for `x`: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 5.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 4, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 2, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 2, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 3, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js new file mode 100644 index 000000000000..5369f57f22b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js @@ -0,0 +1,289 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( './../lib/sdiff.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 2, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 2, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 2, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 3, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js new file mode 100644 index 000000000000..d3c2f1209076 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js @@ -0,0 +1,298 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sdiff = tryRequire( resolve( __dirname, './../lib/sdiff.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 2, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 2, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 2, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 3, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +});