diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/README.md b/lib/node_modules/@stdlib/blas/ext/base/sediff/README.md new file mode 100644 index 000000000000..723b25a2d58e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/README.md @@ -0,0 +1,368 @@ + + +# sediff + +> Calculate the differences between consecutive elements of a single-precision floating-point strided array. + +
+ +## Usage + +```javascript +var sediff = require( '@stdlib/blas/ext/base/sediff' ); +``` + + + +#### sediff( N, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut ) + +Calculates the differences between consecutive elements 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 ); + +sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 11.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **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 after computing differences. +- **strideP**: stride length for `prepend`. +- **N2**: number of elements to `append`. +- **append**: a [`Float32Array`][@stdlib/array/float32] containing values to append after computing differences. +- **strideA**: stride length for `append`. +- **out**: output [`Float32Array`][@stdlib/array/float32]. Must have `N + N1 + N2 - 1` elements. +- **strideOut**: stride length for `out`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute 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 ); + +sediff( 3, x, 2, 1, p, 1, 1, a, 1, out, 1 ); + +console.log( out ); +// out => [ 1.0, 4.0, 4.0, 11.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 ); + +sediff( x1.length, x1, 1, 1, p, 1, 1, a, 1, out, 1 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 11.0 ] +``` + + + +#### sediff.ndarray( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) + +Calculates the differences between consecutive elements 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 ); + +sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 11.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`. + +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 ); + +sediff.ndarray( 3, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 11.0 ] +``` + +
+ + + +
+ +## Notes + +- If the sum of `N`, `N1`, and `N2` is less than or equal to `1`, both functions return the output array unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sediff = require( '@stdlib/blas/ext/base/sediff' ); + +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( 13 ); + +sediff( x.length, x, 1, 2, p, 1, 2, a, 1, out, 1 ); +console.log( 'Output', out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/sediff.h" +``` + + + +#### stdlib_strided_sediff( N, \*X, strideX, N1, \*prepend, strideP, N2, \*append, strideA, \*Out, strideOut ) + +Calculates the differences between consecutive elements 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 }; + +stdlib_strided_sediff( 5, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **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 after 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 after computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `append`. +- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - 1` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `Out`. + +```c +void stdlib_strided_sediff( const CBLAS_INT N, 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 ); +``` + + + +#### stdlib_strided_sediff_ndarray( N, \*X, strideX, offsetX, N1, \*prepend, strideP, offsetP, N2, \*append, strideA, offsetA, \*Out, strideOut, offsetOut ) + +Calculates the differences between consecutive elements 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 }; + +stdlib_strided_sediff_ndarray( 5, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **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 after 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 after 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 - 1` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `Out`. +- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`. + +```c +void stdlib_strided_sediff_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 ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/sediff.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, 0.0f, 0.0f }; + + // Compute forward differences: + stdlib_strided_sediff( 8, x, 1, 1, p, 1, 1, a, 1, out, 1 ); + + // Print the result: + for ( int i = 0; i < 9; i++ ) { + printf( "out[ %i ] = %f\n", i, out[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.js new file mode 100644 index 000000000000..faf19a81de59 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +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 sediff = require( './../lib/sediff.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 o; + var N; + + N = len; + N1 = 1; + N2 = 1; + ol = N + N1 + N2 - 1; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + 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++ ) { + sediff( N, x, 1, N1, p, 1, N2, a, 1, o, 1 ); + if ( isnanf( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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/sediff/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.native.js new file mode 100644 index 000000000000..35a399053c05 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.native.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +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 sediff = tryRequire( resolve( __dirname, './../lib/sediff.native.js' ) ); +var opts = { + 'skip': ( sediff 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 o; + var N; + + N = len; + N1 = 1; + N2 = 1; + ol = N + N1 + N2 - 1; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + 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++ ) { + sediff( N, x, 1, N1, p, 1, N2, a, 1, o, 1 ); + if ( isnanf( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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/sediff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..c3c1baf7d37b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.ndarray.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +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 sediff = 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 o; + var N; + + N = len; + N1 = 1; + N2 = 1; + ol = N + N1 + N2 - 1; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + 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++ ) { + sediff( N, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0 ); + if ( isnanf( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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/sediff/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..92a8982f632c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +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 sediff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sediff 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 o; + var N; + + N = len; + N1 = 1; + N2 = 1; + ol = N + N1 + N2 - 1; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + 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++ ) { + sediff( N, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0 ); + if ( isnanf( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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/sediff/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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/sediff/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..59e4414816ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/benchmark/c/benchmark.length.c @@ -0,0 +1,251 @@ +/** +* @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/sediff.h" +#include +#include +#include +#include +#include + +#define NAME "sediff" +#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; + double t; + int ol; + int N1; + int N2; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + ol = 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; + } + + 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_sediff( N, x, 1, N1, p, 1, N2, a, 1, o, 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( 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; + double t; + int ol; + int N1; + int N2; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + ol = 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; + } + + 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_sediff_ndarray( N, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 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( 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::native::%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::native::%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/sediff/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/sediff/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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/sediff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/repl.txt new file mode 100644 index 000000000000..e4f60d7f39e2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/repl.txt @@ -0,0 +1,162 @@ +{{alias}}( N, x, sx, N1, p, sp, N2, a, sa, out, so ) + Calculates the differences between consecutive elements 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 the sum of `N`, `N1`, and `N2` is less than or equal to `1`, the function + returns the output array unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float32Array + Input array. + + sx: integer + Stride length for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Float32Array + Array containing values to prepend after computing differences. + + sp: integer + Stride length for `prepend`. + + N2: integer + Number of elements to `append`. + + a: Float32Array + Array containing values to append after computing differences. + + sa: integer + Stride length for `append`. + + out: Float32Array + Output array. + + so: integer + Stride length for `out`. + + 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 ); + > {{alias}}( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ) + [ 0.0, -3.0, 4.0, 3.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 ); + > {{alias}}( 3, x, 2, 1, p, 1, 1, a, 1, out, 1 ) + [ 1.0, 4.0, 4.0, 11.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 ); + > {{alias}}( x1.length, x1, 1, 1, p, 1, 1, a, 1, out, 1 ) + [ 1.0, 2.0, 2.0, 2.0, 11.0 ] + + +{{alias}}.ndarray( N, x, sx, ox, N1, p, sp, op, N2, a, sa, oa, out, so, oo ) + Calculates the differences between consecutive elements 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. + + 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 after 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 after 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`. + + 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 ); + > {{alias}}.ndarray( 3, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ) + [ 0.0, -3.0, 4.0, 3.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 ); + > {{alias}}.ndarray( 2, x, 1, 1, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ) + [ 0.0, 4.0, 3.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/types/index.d.ts new file mode 100644 index 000000000000..9af60cce3cb6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/types/index.d.ts @@ -0,0 +1,139 @@ +/* +* @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 `sediff`. +*/ +interface Routine { + /** + * Calculates the differences between consecutive elements of a single-precision floating-point strided array. + * + * @param N - number of indexed elements + * @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` + * @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( 6 ); + * + * sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); + * + * console.log( out ); + * // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] + */ + ( N: number, x: Float32Array, strideX: number, N1: number, prepend: Float32Array, strideP: number, N2: number, append: Float32Array, strideA: number, out: Float32Array, strideOut: number ): Float32Array; + + /** + * Calculates the differences between consecutive elements 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` + * @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( 6 ); + * + * sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); + * + * console.log( out ); + * // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] + */ + ndarray( N: 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 ): Float32Array; +} + +/** +* Calculates the differences between consecutive elements of a single-precision floating-point strided array. +* +* @param N - number of indexed elements +* @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` +* @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( 6 ); +* +* sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.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( 6 ); +* +* sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +declare var sediff: Routine; + + +// EXPORTS // + +export = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/types/test.ts new file mode 100644 index 000000000000..f19831b974d7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/docs/types/test.ts @@ -0,0 +1,530 @@ +/* +* @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 sediff = 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 ); + + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 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 ); + + sediff( '10', x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( true, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( false, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( null, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( undefined, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( [], x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( {}, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( ( x: number ): number => x, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float32Array... +{ + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff( 10, 10, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, '10', 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, true, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, false, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, null, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, undefined, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, [], 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, {}, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( 10, ( x: number ): number => x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third 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 ); + + sediff( x.length, x, '10', 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, true, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, false, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, null, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, undefined, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, [], 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, {}, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, ( x: number ): number => x, 1, p, 1, 1, a, 1, out, 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 ); + + sediff( x.length, x, 1, '10', p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, true, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, false, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, null, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, undefined, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, [], p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, {}, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, ( x: number ): number => x, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff( x.length, x, 1, 1, 10, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, '10', 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, true, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, false, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, null, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, undefined, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, [], 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, {}, 1, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, ( x: number ): number => x, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function 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 ); + + sediff( x.length, x, 1, 1, p, '10', 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, true, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, false, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, null, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, undefined, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, [], 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, {}, 1, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, ( x: number ): number => x, 1, a, 1, out, 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 ); + + sediff( x.length, x, 1, 1, p, 1, '10', a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, true, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, false, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, null, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, undefined, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, [], a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, {}, a, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, ( x: number ): number => x, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff( x.length, x, 1, 1, p, 1, 1, 10, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, '10', 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, true, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, false, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, null, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, undefined, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, [], 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, {}, 1, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, ( x: number ): number => x, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function 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 ); + + sediff( x.length, x, 1, 1, p, 1, 1, a, '10', out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, true, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, false, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, null, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, undefined, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, [], out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, {}, out, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, ( x: number ): number => x, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, 10, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, '10', 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, true, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, false, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, null, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, undefined, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, [], 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, {}, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh 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 ); + + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, '10' ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, true ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, false ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, null ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, undefined ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, [] ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, {} ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, ( 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 ); + + sediff(); // $ExpectError + sediff( x.length ); // $ExpectError + sediff( x.length, x ); // $ExpectError + sediff( x.length, x, 1 ); // $ExpectError + sediff( x.length, x, 1, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1 ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError + sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1, 10 ); // $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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 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 ); + + sediff.ndarray( '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( false, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( null, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( undefined, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( [], x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( {}, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( ( x: number ): number => x, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Float32Array... +{ + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff.ndarray( 10, 10, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, '10', 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, [], 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( 10, ( x: number ): number => x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff.ndarray( x.length, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, false, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, null, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, undefined, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, [], 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, {}, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, ( x: number ): number => x, 0, 1, p, 1, 0, 1, a, 1, 0, out, 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 ); + + sediff.ndarray( x.length, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, false, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, null, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, undefined, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, [], 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, {}, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, ( x: number ): number => x, 1, p, 1, 0, 1, a, 1, 0, out, 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 ); + + sediff.ndarray( x.length, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, false, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, null, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, undefined, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, [], p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, {}, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, ( x: number ): number => x, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, 10, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, '10', 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, false, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, null, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, undefined, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, [], 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, {}, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, ( x: number ): number => x, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, false, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, null, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, undefined, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, [], 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, {}, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, ( x: number ): number => x, 0, 1, a, 1, 0, out, 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, '10', 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, true, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, false, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, null, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, undefined, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, [], 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, {}, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, ( x: number ): number => x, 1, a, 1, 0, out, 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, false, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, null, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, undefined, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, [], a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, {}, a, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, ( x: number ): number => x, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, 10, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, '10', 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, false, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, null, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, undefined, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, [], 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, {}, 1, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, false, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, null, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, undefined, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, [], 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, {}, 0, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, ( x: number ): number => x, 0, out, 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, false, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, null, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, undefined, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, [], out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, {}, out, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, 10, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, '10', 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, false, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, null, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, undefined, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, [], 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, {}, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, false, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, null, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, undefined, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, [], 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, {}, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, ( x: number ): number => x, 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 ); + + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10' ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, false ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, null ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, undefined ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, [] ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, {} ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 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 ); + + sediff.ndarray(); // $ExpectError + sediff.ndarray( x.length ); // $ExpectError + sediff.ndarray( x.length, x ); // $ExpectError + sediff.ndarray( x.length, x, 1 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1 ); // $ExpectError + sediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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/sediff/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/c/example.c new file mode 100644 index 000000000000..bdfeb5d6ef19 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/c/example.c @@ -0,0 +1,42 @@ +/** +* @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/sediff.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, 0.0f, 0.0f }; + + // Compute forward differences: + stdlib_strided_sediff( 8, x, 1, 1, p, 1, 1, a, 1, out, 1 ); + + // Print the result: + for ( int i = 0; i < 9; i++ ) { + printf( "out[ %i ] = %f\n", i, out[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/index.js new file mode 100644 index 000000000000..97506062687a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 sediff = 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( 13 ); + +sediff( x.length, x, 1, 2, p, 1, 2, a, 1, out, 1 ); +console.log( 'Output', out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sediff/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.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 sediff; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + sediff = main; +} else { + sediff = tmp; +} + + +// EXPORTS // + +module.exports = sediff; + +// exports: { "ndarray": "sediff.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/main.js new file mode 100644 index 000000000000..943508239d95 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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 sediff = require( './sediff.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( sediff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/native.js new file mode 100644 index 000000000000..e1e456e905c3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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 sediff = require( './sediff.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( sediff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/ndarray.js new file mode 100644 index 000000000000..c925222fe412 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/ndarray.js @@ -0,0 +1,100 @@ +/** +* @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' ); + + +// MAIN // + +/** +* Calculates the differences between consecutive elements of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} 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 {NonNegativeInteger} 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 {NonNegativeInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @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( 6 ); +* +* sediff( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +function sediff( 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 i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + // Copy `prepend` into output array: + scopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + + // Compute differences of input array: + ix = offsetX; + io = offsetOut + ( N1 * strideOut ); + prev = x[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + + // Copy `append` into output array: + scopy.ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + + return out; +} + + +// EXPORTS // + +module.exports = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/ndarray.native.js new file mode 100644 index 000000000000..bd93527866ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/ndarray.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 differences between consecutive elements of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} 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 {NonNegativeInteger} 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 {NonNegativeInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @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( 6 ); +* +* sediff( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +function sediff( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + addon.ndarray( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; +} + + +// EXPORTS // + +module.exports = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/sediff.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/sediff.js new file mode 100644 index 000000000000..fadf32bb96de --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/sediff.js @@ -0,0 +1,72 @@ +/** +* @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 differences between consecutive elements of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @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` +* @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( 6 ); +* +* sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +function sediff( N, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut ) { + var ox = stride2offset( N, strideX ); + var op = stride2offset( N1, strideP ); + var oa = stride2offset( N2, strideA ); + var oo = stride2offset( N + N1 + N2 - 1, strideOut ); + ndarray( N, x, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo ); + return out; +} + + +// EXPORTS // + +module.exports = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/sediff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/sediff.native.js new file mode 100644 index 000000000000..6e5b072a21f5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/lib/sediff.native.js @@ -0,0 +1,67 @@ +/** +* @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 differences between consecutive elements of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @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` +* @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( 6 ); +* +* sediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +function sediff( N, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut ) { + addon( N, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut ); + return out; +} + + +// EXPORTS // + +module.exports = sediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sediff/manifest.json new file mode 100644 index 000000000000..f9ac5c23cdb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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/sediff/package.json b/lib/node_modules/@stdlib/blas/ext/base/sediff/package.json new file mode 100644 index 000000000000..e59db15b6e9b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/ext/base/sediff", + "version": "0.0.0", + "description": "Calculate the differences between consecutive elements 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/sediff/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sediff/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/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/sediff/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sediff/src/addon.c new file mode 100644 index 000000000000..362aef16f0bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/src/addon.c @@ -0,0 +1,79 @@ +/** +* @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/sediff.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, 11 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-1, strideOut, argv, 9 ); + API_SUFFIX(stdlib_strided_sediff)( N, X, strideX, N1, prepend, strideP, N2, append, strideA, Out, strideOut ); + 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, 15 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, offsetP, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 10 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 13 ); + STDLIB_NAPI_ARGV_INT64( env, offsetOut, argv, 14 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 9 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-1, strideOut, argv, 12 ); + API_SUFFIX(stdlib_strided_sediff_ndarray)( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/sediff/src/main.c new file mode 100644 index 000000000000..49483d27dc5d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/src/main.c @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sediff.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/scopy.h" +#include "stdlib/blas/base/shared.h" + +/** +* Calculates the differences between consecutive elements of a single-precision floating-point strided array. +* +* @param N number of indexed elements +* @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` +*/ +void API_SUFFIX(stdlib_strided_sediff)( const CBLAS_INT N, 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 ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + const CBLAS_INT op = stdlib_strided_stride2offset( N1, strideP ); + const CBLAS_INT oa = stdlib_strided_stride2offset( N2, strideA ); + const CBLAS_INT oo = stdlib_strided_stride2offset( N+N1+N2-1, strideOut ); + API_SUFFIX(stdlib_strided_sediff_ndarray)( N, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, Out, strideOut, oo ); +} + +/** +* Calculates the differences between consecutive elements 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` +*/ +void API_SUFFIX(stdlib_strided_sediff_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 i; + float prev; + float curr; + + total = N + N1 + N2; + if ( total <= 1 ) { + return; + } + + // Copy `prepend` into output array: + c_scopy_ndarray( N1, prepend, strideP, offsetP, Out, strideOut, offsetOut ); + + // Compute differences of input array: + ix = offsetX; + io = offsetOut + ( N1 * strideOut ); + prev = X[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = X[ ix ]; + Out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + + // Copy `append` into output array: + c_scopy_ndarray( N2, append, strideA, offsetA, Out, strideOut, io ); + + return; +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.js new file mode 100644 index 000000000000..212c78eb618a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var sediff = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof sediff.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var sediff = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sediff, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var sediff; + var main; + + main = require( './../lib/main.js' ); + + sediff = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sediff, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.ndarray.js new file mode 100644 index 000000000000..33e66a799aa0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.ndarray.js @@ -0,0 +1,193 @@ +/** +* @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 sediff = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', function test( t ) { + t.strictEqual( sediff.length, 15, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a single-precision floating-point strided array', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( x.length, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0 ); + expected = new Float32Array([ + 10.0, + 15.0, + 4.0, + 4.0, + 4.0, + 4.0, + 30.0, + 35.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the sum of `N`, `N1` & `N2` parameter is less than or equal to `1`, the function returns `out` unchanged', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, o, 1, 0 ); + expected = new Float32Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, 2, 0, 2, p, 2, 0, 2, a, 2, 0, o, 2, 0 ); + expected = new Float32Array([ + 10.0, + 0.0, + 25.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 30.0, + 0.0, + 45.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, -2, 4, 2, p, -2, 2, 2, a, -2, 2, o, -2, 10 ); + expected = new Float32Array([ + 30.0, + 0.0, + 45.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + 25.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports offset parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 0.0, 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0 ] ); + a = new Float32Array( [ 30.0 ] ); + o = new Float32Array( 6 ); + + out = sediff( 3, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, o, 1, 0 ); + expected = new Float32Array([ + 10.0, + 4.0, + 4.0, + 30.0, + 0.0, + 0.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.ndarray.native.js new file mode 100644 index 000000000000..5f37bf5e3f55 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.ndarray.native.js @@ -0,0 +1,202 @@ +/** +* @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 sediff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sediff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', opts, function test( t ) { + t.strictEqual( sediff.length, 15, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a single-precision floating-point strided array', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( x.length, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0 ); + expected = new Float32Array([ + 10.0, + 15.0, + 4.0, + 4.0, + 4.0, + 4.0, + 30.0, + 35.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the sum of `N`, `N1` & `N2` parameter is less than or equal to `1`, the function returns `out` unchanged', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, o, 1, 0 ); + expected = new Float32Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, 2, 0, 2, p, 2, 0, 2, a, 2, 0, o, 2, 0 ); + expected = new Float32Array([ + 10.0, + 0.0, + 25.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 30.0, + 0.0, + 45.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, -2, 4, 2, p, -2, 2, 2, a, -2, 2, o, -2, 10 ); + expected = new Float32Array([ + 30.0, + 0.0, + 45.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + 25.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports offset parameters', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 0.0, 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0 ] ); + a = new Float32Array( [ 30.0 ] ); + o = new Float32Array( 6 ); + + out = sediff( 3, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, o, 1, 0 ); + expected = new Float32Array([ + 10.0, + 4.0, + 4.0, + 30.0, + 0.0, + 0.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.sediff.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.sediff.js new file mode 100644 index 000000000000..a5bfbdc019e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.sediff.js @@ -0,0 +1,165 @@ +/** +* @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 sediff = require( './../lib/sediff.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', function test( t ) { + t.strictEqual( sediff.length, 11, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a single-precision floating-point strided array', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( x.length, x, 1, 2, p, 1, 2, a, 1, o, 1 ); + expected = new Float32Array([ + 10.0, + 15.0, + 4.0, + 4.0, + 4.0, + 4.0, + 30.0, + 35.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the sum of `N`, `N1` & `N2` parameter is less than or equal to `1`, the function returns `out` unchanged', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( 1, x, 1, 0, p, 1, 0, a, 1, o, 1 ); + expected = new Float32Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, 2, 2, p, 2, 2, a, 2, o, 2 ); + expected = new Float32Array([ + 10.0, + 0.0, + 25.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 30.0, + 0.0, + 45.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, -2, 2, p, -2, 2, a, -2, o, -2 ); + expected = new Float32Array([ + 30.0, + 0.0, + 45.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + 25.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.sediff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.sediff.native.js new file mode 100644 index 000000000000..fdecd46fa40a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sediff/test/test.sediff.native.js @@ -0,0 +1,174 @@ +/** +* @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 sediff = tryRequire( resolve( __dirname, './../lib/sediff.native.js' ) ); +var opts = { + 'skip': ( sediff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', opts, function test( t ) { + t.strictEqual( sediff.length, 11, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a single-precision floating-point strided array', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( x.length, x, 1, 2, p, 1, 2, a, 1, o, 1 ); + expected = new Float32Array([ + 10.0, + 15.0, + 4.0, + 4.0, + 4.0, + 4.0, + 30.0, + 35.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the sum of `N`, `N1` & `N2` parameter is less than or equal to `1`, the function returns `out` unchanged', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0 ] ); + a = new Float32Array( [ 30.0, 35.0 ] ); + o = new Float32Array( 8 ); + + out = sediff( 1, x, 1, 0, p, 1, 0, a, 1, o, 1 ); + expected = new Float32Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, 2, 2, p, 2, 2, a, 2, o, 2 ); + expected = new Float32Array([ + 10.0, + 0.0, + 25.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 30.0, + 0.0, + 45.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = new Float32Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float32Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float32Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float32Array( 11 ); + + out = sediff( 3, x, -2, 2, p, -2, 2, a, -2, o, -2 ); + expected = new Float32Array([ + 30.0, + 0.0, + 45.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + 25.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +});