diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/ddiff/README.md new file mode 100644 index 000000000000..5678bdae5954 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/README.md @@ -0,0 +1,391 @@ + + +# ddiff + +> Calculate the k-th discrete forward difference of a double-precision floating-point strided array. + +
+ +## Usage + +```javascript +var ddiff = require( '@stdlib/blas/ext/base/ddiff' ); +``` + + + +#### ddiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) + +Calculates the k-th discrete forward differences of a double-precision floating-point strided array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float64Array( [ 1.0 ] ); +var a = new Float64Array( [ 11.0 ] ); +var out = new Float64Array( 6 ); +var w = new Float64Array( 6 ); + +ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **k**: number of times to recursively compute differences. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: stride length for `x`. +- **N1**: number of elements to `prepend`. +- **prepend**: a [`Float64Array`][@stdlib/array/float64] containing values to prepend prior to computing differences. +- **strideP**: stride length for `prepend`. +- **N2**: number of elements to `append`. +- **append**: a [`Float64Array`][@stdlib/array/float64] containing values to append prior to computing differences.. +- **strideA**: strides length for `append`. +- **out**: output [`Float64Array`][@stdlib/array/float64]. +- **strideOut**: stride length for `out`. +- **workspace**: workspace [`Float64Array`][@stdlib/array/float64]. +- **strideW**: stride length for `workspace`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to differences of every other element: + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float64Array( [ 1.0 ] ) +var a = new Float64Array( [ 11.0 ] ); +var out = new Float64Array( 4 ); +var w = new Float64Array( 4 ); + +ddiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 1.0, 4.0, 4.0, 1.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var p = new Float64Array( [ 1.0 ] ) +var a = new Float64Array( [ 11.0 ] ); +var out = new Float64Array( 5 ); +var w = new Float64Array( 5 ); + +ddiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 3.0, 2.0, 2.0, 2.0, 11.0 ] +``` + + + +#### ddiff.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) + +Calculates the k-th discrete forward differences of a double-precision floating-point strided array using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float64Array( [ 1.0 ] ); +var a = new Float64Array( [ 11.0 ] ); +var out = new Float64Array( 6 ); +var w = new Float64Array( 6 ); + +ddiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetP**: starting index for `prepend`. +- **offsetA**: starting index for `append`. +- **offsetOut**: starting index for `out`. +- **offsetW**: starting index of `workspace`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float64Array( [ 1.0 ] ) +var a = new Float64Array( [ 11.0 ] ); +var out = new Float64Array( 4 ); +var w = new Float64Array( 4 ); + +ddiff( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( out ); +// out => [ 5.0, 2.0, 2.0, 1.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `x` unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ddiff = require( '@stdlib/blas/ext/base/ddiff' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'float64' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'float64' +}); +console.log( 'Append array: ', a ); + +var out = new Float64Array( 10 ); + +var w = new Float64Array( 13 ); + +ddiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); +console.log( 'Output', out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ddiff.h" +``` + + + +#### stdlib_strided_ddiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, \*out, strideOut, workspace, strideW ) + +Calculates the k-th discrete forward differences of a double-precision floating-point strided array. + +```c +double x[] = { 2.0, 4.0, 6.0, 8.0, 10.0 }; +double p[] = { 1.0 }; +double a[] = { 11.0 }; +double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; +double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + +stdlib_strided_ddiff( 5, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **k**: `[in] CBLAS_INT` number of times to recursively compute differences. +- **x**: `[in] double` input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: `[in] CBLAS_INT` stride length for `x`. +- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. +- **prepend**: `[in] double` a [`Float64Array`][@stdlib/array/float64] containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. +- **N2**: `[in] CBLAS_INT` number of elements in `append`. +- **append**: `[in] double` a [`Float64Array`][@stdlib/array/float64] containing values to append prior to computing differences.. +- **strideA**: `[in] CBLAS_INT` strides length for `append`. +- **out**: `[in] double` output [`Float64Array`][@stdlib/array/float64]. +- **strideOut**: `[in] CBLAS_INT` stride length for `out`. +- **workspace**: `[in] double` workspace [`Float64Array`][@stdlib/array/float64]. +- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. + +```c +void stdlib_strided_ddiff( const CBLAS_INT N, const CBLAS_INT k, double *X, const CBLAS_INT strideX, const CBLAS_INT N1, double *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, double *append, const CBLAS_INT strideA, double *out, const CBLAS_INT strideOut, const double workspace, const CBLAS_INT strideW ); +``` + + + +#### stdlib_strided_ddiff_ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, \*out, strideOut, offsetOut, w, strideW, offsetW ) + +Calculates the k-th discrete forward differences of a double-precision floating-point strided array using alternative indexing semantics. + +```c +double x[] = { 2.0, 4.0, 6.0, 8.0, 10.0 }; +double p[] = { 1.0 }; +double a[] = { 11.0 }; +double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; +double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + +stdlib_strided_ddiff_ndarray( 5, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **k**: `[in] CBLAS_INT` number of times to recursively compute differences. +- **x**: `[in] double` input [`Float64Array`][@stdlib/array/float64]. +- **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] double` a [`Float64Array`][@stdlib/array/float64] containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. +- **offsetP**: `[in] CBLAS_INT` starting index for `prepend`. +- **N2**: `[in] CBLAS_INT` number of elements in `append`. +- **append**: `[in] double` a [`Float64Array`][@stdlib/array/float64] containing values to append prior to computing differences.. +- **strideA**: `[in] CBLAS_INT` strides length for `append`. +- **offsetA**: `[in] CBLAS_INT` starting index for `append`. +- **out**: `[in] double` output [`Float64Array`][@stdlib/array/float64]. +- **strideOut**: `[in] CBLAS_INT` stride length for `out`. +- **offsetOut**: `[in] CBLAS_INT` starting index for `out`. +- **workspace**: `[in] double` workspace [`Float64Array`][@stdlib/array/float64]. +- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. +- **offsetW**: `[in] CBLAS_INT` starting index for `workspace`. + +```c +void stdlib_strided_ddiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, double *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, double *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, double *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, double *workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ddiff.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Define prepend values: + double p[] = { -1.0 }; + + // Define append values: + double a[] = { 10.0 }; + + // Define output array: + double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Define workspace: + double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Fill the array: + stdlib_strided_ddiff( 8, 3, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + // Print the result: + for ( int i = 0; i < 7; i++ ) { + printf( "out[ %i ] = %lf\n", i, out[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.js new file mode 100644 index 000000000000..410abdcfc8c9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ddiff = require( './../lib/ddiff.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float64Array( N+N1+N2-1 ); + o = new Float64Array( 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++ ) { + ddiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.native.js new file mode 100644 index 000000000000..2af38abe472a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.native.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; +var ddiff = tryRequire( resolve( __dirname, './../lib/ddiff.native.js' ) ); +var opts = { + 'skip': ( ddiff instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float64Array( N+N1+N2-1 ); + o = new Float64Array( 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++ ) { + ddiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6da61d94c29e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.ndarray.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ddiff = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float64Array( N+N1+N2-1 ); + o = new Float64Array( 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++ ) { + ddiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..3ef25a13da0b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; +var ddiff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( ddiff instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float64Array( N+N1+N2-1 ); + o = new Float64Array( 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++ ) { + ddiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:ndarray:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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/ddiff/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..d44fbc873fa0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/benchmark/c/benchmark.length.c @@ -0,0 +1,273 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/ddiff.h" +#include +#include +#include +#include +#include + +#define NAME "ddiff" +#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 double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* 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; + double *x; + double *p; + double *a; + double *o; + double *w; + double t; + int wl; + int ol; + int N1; + int N2; + int k; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + wl = N + N1 + N2 - 1; + + x = (double *) malloc( N * sizeof( double ) ); + for ( i = 0; i < N; i++ ) { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + + p = (double *) malloc( N1 * sizeof( double ) ); + a = (double *) malloc( N2 * sizeof( double ) ); + for ( i = 0; i < N1; i++ ) { + p[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + a[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + + w = (double *) malloc( wl * sizeof( double ) ); + for ( i = 0; i < wl; i++ ) { + w[ i ] = 0.0; + } + + o = (double *) malloc( ol * sizeof( double ) ); + for ( i = 0; i < ol; i++ ) { + o[ i ] = 0.0; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ddiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( o[ 0 ] != o[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( o[ ol-1 ] != o[ ol-1 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( p ); + free( a ); + free( w ); + free( o ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double *x; + double *p; + double *a; + double *o; + double *w; + double t; + int wl; + int ol; + int N1; + int N2; + int k; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + wl = N + N1 + N2 - 1; + + x = (double *) malloc( N * sizeof( double ) ); + for ( i = 0; i < N; i++ ) { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + + p = (double *) malloc( N1 * sizeof( double ) ); + a = (double *) malloc( N2 * sizeof( double ) ); + for ( i = 0; i < N1; i++ ) { + p[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + a[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + + w = (double *) malloc( wl * sizeof( double ) ); + for ( i = 0; i < wl; i++ ) { + w[ i ] = 0.0; + } + + o = (double *) malloc( ol * sizeof( double ) ); + for ( i = 0; i < ol; i++ ) { + o[ i ] = 0.0; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ddiff_ndarray( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( o[ 0 ] != o[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( o[ ol-1 ] != o[ ol-1 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( p ); + free( a ); + free( w ); + free( o ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/ddiff/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/binding.gyp @@ -0,0 +1,170 @@ +# @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', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/repl.txt new file mode 100644 index 000000000000..497f420a25cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/repl.txt @@ -0,0 +1,188 @@ + +{{alias}}( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) + Calculates the k-th discrete forward differences of a double-precision + floating-point strided array. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `x` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of times to recursively compute differences. + + x: Float64Array + Input array. + + strideX: integer + Stride length for `x`. + + N1: integer + Number of elements to `prepend`. + + prepend: Float64Array + Array containing values to prepend prior to computing differences. + + strideP: integer + Stride length for `prepend`. + + N2: integer + Number of elements to `append`. + + append: Float64Array + Array containing values to append prior to computing differences. + + strideA: integer + Stride length for `append`. + + out: Float64Array + Output array. + + strideOut: integer + Stride length for `Out`. + + workspace: Float64Array + Workspace array. + + strideW: integer + Stride length for `workspace`. + + Returns + ------- + out: Float64Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float64}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float64}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 4 ); + > var w = new {{alias:@stdlib/array/float64}}( 4 ); + > {{alias}}( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, -3.0, 4.0, 1.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > p = new {{alias:@stdlib/array/float64}}( [ 1.0 ] ); + > a = new {{alias:@stdlib/array/float64}}( [ 11.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 4 ); + > var w = new {{alias:@stdlib/array/float64}}( 4 ); + > {{alias}}( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, 4.0, 4.0, 1.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > p = new {{alias:@stdlib/array/float64}}( [ 1.0 ] ); + > a = new {{alias:@stdlib/array/float64}}( [ 11.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 5 ); + > var w = new {{alias:@stdlib/array/float64}}( 5 ); + > {{alias}}( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 3.0, 2.0, 2.0, 2.0, 1.0 ] + + +{{alias}}.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) + Calculates the k-th discrete forward differences of a double-precision + floating-point strided array using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of times to recursively compute differences. + + x: Float64Array + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + N1: integer + Number of elements to `prepend`. + + prepend: Float64Array + Array containing values to prepend prior to computing differences. + + strideP: integer + Stride length for `prepend`. + + offsetP: integer + Starting index for `prepend`. + + N2: integer + Number of elements to `append`. + + append: Float64Array + Array containing values to append prior to computing differences. + + strideA: integer + Stride length for `append`. + + offsetA: integer + Starting index for `append`. + + out: Float64Array + Output array. + + strideOut: integer + Stride length for `Out`. + + offsetOut: integer + Stride length for `Out`. + + workspace: Float64Array + Workspace array. + + strideW: integer + Stride length for `workspace`. + + offsetW: integer + Starting index for `workspace`. + + Returns + ------- + out: Float64Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float64}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float64}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 4 ); + > var w = new {{alias:@stdlib/array/float64}}( 4 ); + > {{alias}}.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ) + [ 1.0, -3.0, 4.0, 1.0 ] + + // Advanced indexing: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float64}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float64}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 3 ); + > var w = new {{alias:@stdlib/array/float64}}( 3 ); + > {{alias}}.ndarray( 2, 1, x, 1, x.length-2, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ) + [ -2.0, 4.0, 1.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/types/index.d.ts new file mode 100644 index 000000000000..d69d36a691b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/types/index.d.ts @@ -0,0 +1,153 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `ddiff`. +*/ +interface Routine { + /** + * Calculates the k-th discrete forward difference of a double-precision floating-point strided array. + * + * @param N - number of indexed elements + * @param k - number of times to recursively compute differences + * @param x - input array + * @param strideX - stride length for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + * var p = new Float64Array( [ 1.0 ] ); + * var a = new Float64Array( [ 22.0 ] ); + * var out = new Float64Array( 5 ); + * var w = new Float64Array( 6 ) + * + * ddiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + * + * console.log( out ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ( N: number, k: number, x: Float64Array, strideX: number, N1: number, prepend: Float64Array, strideP: number, N2: number, append: Float64Array, strideA: number, out: Float64Array, strideOut: number, workspace: Float64Array, strideW: number ): Float64Array; + + /** + * Calculates the k-th discrete forward difference of a double-precision floating-point strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param k - number of times to recursively compute differences + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param offsetP - starting index for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param offsetA - starting index for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @param offsetW - starting index for `workspace` + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + * var p = new Float64Array( [ 1.0 ] ); + * var a = new Float64Array( [ 22.0 ] ); + * var out = new Float64Array( 5 ); + * var w = new Float64Array( 6 ) + * + * ddiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + * + * console.log( out ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ndarray ( N: number, k: number, x: Float64Array, strideX: number, offsetX: number, N1: number, prepend: Float64Array, strideP: number, offsetP: number, N2: number, append: Float64Array, strideA: number, offsetA: number, out: Float64Array, strideOut: number, offsetOut: number, workspace: Float64Array, strideW: number, offsetW: number ): Float64Array; +} + +/** +* Calculates the k-th discrete forward difference of a double-precision floating-point strided array. +* +* @param N - number of indexed elements +* @param k - number of times to recursively compute differences +* @param x - input array +* @param strideX - stride length for `x` +* @param N1 - number of indexed elements of prepend +* @param prepend - prepend array +* @param strideP - stride length for `prepend` +* @param N2 - number of indexed elements of append +* @param append - append array +* @param strideA - stride length for `append` +* @param out - output array +* @param strideOut - stride length for `out` +* @param workspace - workspace array +* @param strideW - stride length for `workspace` +* @returns output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float64Array( [ 1.0 ] ); +* var a = new Float64Array( [ 22.0 ] ); +* var out = new Float64Array( 5 ); +* var w = new Float64Array( 6 ) +* +* ddiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float64Array( [ 1.0 ] ); +* var a = new Float64Array( [ 22.0 ] ); +* var out = new Float64Array( 5 ); +* var w = new Float64Array( 6 ) +* +* ddiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +declare var ddiff: Routine; + + +// EXPORTS // + +export = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/types/test.ts new file mode 100644 index 000000000000..a5188f29ccf8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/docs/types/test.ts @@ -0,0 +1,685 @@ +/* +* @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 ddiff = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( '10', 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( true, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( false, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( null, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( undefined, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( [], 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( {}, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( ( x: number ): number => x, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, '10', x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, true, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, false, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, null, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, undefined, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, [], x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, {}, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, ( x: number ): number => x, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, '10', 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, false, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, null, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, undefined, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, [], 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, {}, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, ( x: number ): number => x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, '10', 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, true, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, false, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, null, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, undefined, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, [], 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, {}, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, ( x: number ): number => x, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, '10', p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, true, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, false, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, null, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, undefined, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, [], p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, {}, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, ( x: number ): number => x, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, '10', 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, true, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, false, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, null, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, undefined, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, [], 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, {}, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, ( x: number ): number => x, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, p, '10', 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, true, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, false, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, null, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, undefined, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, [], 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, {}, 1, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, ( x: number ): number => x, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eigth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, '10', a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, true, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, false, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, null, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, undefined, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, [], a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, {}, a, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, ( x: number ): number => x, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, 1, '10', 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, true, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, false, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, null, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, undefined, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, [], 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, {}, 1, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, ( x: number ): number => x, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, '10', out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, true, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, false, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, null, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, undefined, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, [], out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, {}, out, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, ( x: number ): number => x, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const w = new Float64Array( 9 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, '10', 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, true, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, false, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, null, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, undefined, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, [], 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, {}, 1, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, ( x: number ): number => x, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelveth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, '10', w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, true, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, false, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, null, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, undefined, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, [], w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, {}, w, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, ( x: number ): number => x, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a thirteenth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 9 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, '10', 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, true, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, false, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, null, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, undefined, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, [], 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, {}, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, '10' ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, true ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, false ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, null ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, undefined ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, [] ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, {} ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff(); // $ExpectError + ddiff( x.length ); // $ExpectError + ddiff( x.length, 1 ); // $ExpectError + ddiff( x.length, 1, x ); // $ExpectError + ddiff( x.length, 1, x, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w ); // $ExpectError + ddiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1, {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( '10', 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( true, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( false, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( null, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( undefined, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( [], 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( {}, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( ( x: number ): number => x, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, false, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, null, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, undefined, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, [], x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, {}, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, ( x: number ): number => x, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, '10', 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, [], 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, ( x: number ): number => x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, false, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, null, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, undefined, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, [], 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, {}, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, ( x: number ): number => x, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, false, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, null, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, undefined, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, [], 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, {}, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, ( x: number ): number => x, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, false, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 1, null, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, undefined, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, [], p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, {}, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, ( x: number ): number => x, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, '10', 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, false, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, null, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, undefined, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, [], 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, {}, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, ( x: number ): number => x, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eigth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, false, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, null, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, undefined, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, [], 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, {}, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, ( x: number ): number => x, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, '10', 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, true, 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, false, 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, null, 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, undefined, 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, [], 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, {}, 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, ( x: number ): number => x, 1, a, 0, 1, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, false, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, null, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, undefined, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, [], a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, {}, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, ( x: number ): number => x, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 9 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, '10', 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, false, 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, null, 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, undefined, 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, [], 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, {}, 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, ( x: number ): number => x, 1, 0, out, 0, 1, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelveth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, false, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, null, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, undefined, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, [], 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, {}, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, ( x: number ): number => x, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 9 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, false, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, null, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, undefined, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, [], out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, {}, out, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, ( x: number ): number => x, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, '10', 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, false, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, null, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, undefined, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, [], 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, {}, 1, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, ( x: number ): number => x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, false, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, null, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, undefined, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, [], 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, {}, 0, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10', w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, false, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, null, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, undefined, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, [], w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, {}, w, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventeenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, '10', 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, true, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, false, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, null, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, undefined, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, [], 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, {}, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a eighteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, '10', 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, true, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, false, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, null, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, undefined, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, [], 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, {}, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a nineteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, '10' ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, true ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, false ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, null ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, undefined ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, [] ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, {} ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 11 ); + const w = new Float64Array( 11 ); + + ddiff.ndarray(); // $ExpectError + ddiff.ndarray( x.length ); // $ExpectError + ddiff.ndarray( x.length, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1 ); // $ExpectError + ddiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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/ddiff/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/c/example.c new file mode 100644 index 000000000000..e3e5c561834a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/c/example.c @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/ddiff.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Define prepend values: + double p[] = { -1.0 }; + + // Define append values: + double a[] = { 10.0 }; + + // Define output array: + double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Define workspace: + double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Fill the array: + stdlib_strided_ddiff( 8, 3, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + // Print the result: + for ( int i = 0; i < 7; i++ ) { + printf( "out[ %i ] = %lf\n", i, out[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/index.js new file mode 100644 index 000000000000..fe1c0280d3b0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ddiff = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'float64' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'float64' +}); +console.log( 'Append array: ', a ); + +var out = new Float64Array( 10 ); + +var w = new Float64Array( 13 ); + +ddiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); +console.log( 'Output', out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/ddiff/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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, 1, 1, 1, 1 ] +*/ +function ddiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) { + var ox = stride2offset( N, strideX ); + var op = stride2offset( N1, strideP ); + var oa = stride2offset( N2, strideA ); + var oo = stride2offset( N + N1 + N2 - k, strideOut ); + var ow = stride2offset( N + N1 + N2 - 1, strideW ); + ndarray( N, k, x, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo, workspace, strideW, ow ); + return out; +} + + +// EXPORTS // + +module.exports = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ddiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ddiff.native.js new file mode 100644 index 000000000000..2001856b8e47 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ddiff.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a double-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float64Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float64Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float64Array( [ 1.0 ] ); +* var a = new Float64Array( [ 22.0 ] ); +* var out = new Float64Array( 5 ); +* var w = new Float64Array( 6 ) +* +* ddiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function ddiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) { + addon( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ); + return out; +} + + +// EXPORTS // + +module.exports = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/index.js new file mode 100644 index 000000000000..f059ed607ee6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/index.js @@ -0,0 +1,65 @@ +/** +* @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'; + +/** +* Calculate the k-th discrete forward difference of a double-precision floating-point strided array. +* +* @module @stdlib/blas/ext/base/ddiff +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ddiff = require( '@stdlib/blas/ext/base/ddiff' ); +* +* var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float64Array( [ 1.0 ] ); +* var a = new Float64Array( [ 22.0 ] ); +* var out = new Float64Array( 5 ); +* var w = new Float64Array( 6 ) +* +* ddiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ + +// 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 ddiff; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + ddiff = main; +} else { + ddiff = tmp; +} + + +// EXPORTS // + +module.exports = ddiff; + +// exports: { "ndarray": "ddiff.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/main.js new file mode 100644 index 000000000000..029900015701 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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 ddiff = require( './ddiff.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( ddiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/native.js new file mode 100644 index 000000000000..d347f3666b64 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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 ddiff = require( './ddiff.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( ddiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.js new file mode 100644 index 000000000000..2fadef74919f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.js @@ -0,0 +1,252 @@ +/** +* @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'; + +// FUNCTIONS // + +/** +* Calculates the forward difference of a double-precision floating-point strided array using alternative indexing semantics. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float64Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float64Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @returns {Float64Array} output array +*/ +function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var total; + var prev; + var curr; + var ix; + var io; + var ip; + var ia; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + if ( N1 === 0 && N2 === 0 ) { + ix = offsetX + ( ( N - 1 ) * strideX ); + io = offsetOut + ( ( N - 2 ) * strideOut ); + prev = x[ ix ]; + for ( i = N-2; i >= 0; i-- ) { + ix -= strideX; + curr = x[ ix ]; + out[ io ] = prev - curr; + prev = curr; + io -= strideOut; + } + return out; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = x[ offsetX ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = x[ offsetX ]; + } else { + prev = append[ offsetA ]; + } + + // x + if ( N > 0 ) { + ix = offsetX; + if ( N1 === 0 ) { + prev = x[ ix ]; + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = append[ ia ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ia += strideA; + } + } + return out; +} + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a double-precision floating-point strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float64Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float64Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {PositiveInteger} offsetW - starting index for `workspace` +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float64Array( [ 1.0 ] ); +* var a = new Float64Array( [ 22.0 ] ); +* var out = new Float64Array( 5 ); +* var w = new Float64Array( 6 ) +* +* ddiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function ddiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + var total; + var ix; + var ip; + var ia; + var io; + var n; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + if ( k >= total ) { + return out; + } + + if ( k === 0 ) { + io = offsetOut; + ip = offsetP; + for ( i = 0; i < N1; i++ ) { + out[ io ] = prepend[ ip ]; + io += strideOut; + ip += strideP; + } + + ix = offsetX; + for ( i = 0; i < N; i++ ) { + out[ io ] = x[ ix ]; + io += strideOut; + ix += strideX; + } + + ia = offsetA; + for ( i = 0; i < N2; i++ ) { + out[ io ] = append[ ia ]; + io += strideOut; + ia += strideA; + } + } + + if ( k === 1 ) { + base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; + } + + base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, workspace, strideW, offsetW ); + + n = total - 1; + for ( i = 1; i < k - 1; i++ ) { + base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, workspace, strideW, offsetW ); + n -= 1; + } + + base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; +} + + +// EXPORTS // + +module.exports = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.native.js new file mode 100644 index 000000000000..130555f1c442 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/lib/ndarray.native.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a double-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float64Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float64Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {PositiveInteger} offsetW - starting index for `workspace` +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float64Array( [ 1.0 ] ); +* var a = new Float64Array( [ 22.0 ] ); +* var out = new Float64Array( 5 ); +* var w = new Float64Array( 6 ) +* +* ddiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function ddiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + addon.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ); + return out; +} + + +// EXPORTS // + +module.exports = ddiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ddiff/manifest.json new file mode 100644 index 000000000000..fb41f9fb7ad5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/manifest.json @@ -0,0 +1,78 @@ +{ + "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/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/package.json b/lib/node_modules/@stdlib/blas/ext/base/ddiff/package.json new file mode 100644 index 000000000000..b0130193b6dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/ext/base/ddiff", + "version": "0.0.0", + "description": "Calculate the k-th discrete forward difference of a double-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", + "float64", + "double", + "float64array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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/ddiff/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/addon.c new file mode 100644 index 000000000000..f64803338ba4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/addon.c @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/ddiff.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 14 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, prepend, N1, strideP, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, append, N2, strideA, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, out, N+N1+N2-k, strideOut, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, workspace, N+N1+N2-1, strideW, argv, 12 ); + API_SUFFIX(stdlib_strided_ddiff)( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 19 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, offsetP, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 12 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 14 ); + STDLIB_NAPI_ARGV_INT64( env, offsetOut, argv, 15 ); + STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 17 ); + STDLIB_NAPI_ARGV_INT64( env, offsetW, argv, 18 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, prepend, N1, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, append, N2, strideA, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, out, N+N1+N2-k, strideOut, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, workspace, N+N1+N2-1, strideW, argv, 16 ); + API_SUFFIX(stdlib_strided_ddiff_ndarray)( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/main.c new file mode 100644 index 000000000000..7c81a744b5e6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/src/main.c @@ -0,0 +1,247 @@ +/** +* @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/ddiff.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" + +/** +* Calculates the k-th discrete forward difference of a double-precision floating-point strided array. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param x input array +* @param strideX stride length for `x` +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for `prepend` +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for `append` +* @param out output array +* @param strideOut stride length for `out` +* @param workspace workspace array +* @param strideW stride length for `workspace` +*/ +void API_SUFFIX(stdlib_strided_ddiff)( const CBLAS_INT N, const CBLAS_INT k, double *X, const CBLAS_INT strideX, const CBLAS_INT N1, double *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, double *append, const CBLAS_INT strideA, double *out, const CBLAS_INT strideOut, double *workspace, const CBLAS_INT strideW ) { + 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-k, strideOut ); + const CBLAS_INT ow = stdlib_strided_stride2offset( N+N1+N2-1, strideW ); + API_SUFFIX(stdlib_strided_ddiff_ndarray)( N, k, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo, workspace, strideW, ow ); +} + +/** +* Calculates the forward difference of a double-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param x input array +* @param strideX stride length for `x` +* @param offsetX starting index for `x` +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for `prepend` +* @param offsetP starting index for `prepend` +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for `append` +* @param offsetA starting index for `append` +* @param out output array +* @param strideOut stride length for `out` +* @param offsetOut starting index for `out` +*/ +static void stdlib_strided_base_ddiff_ndarray( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, double *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, double *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, double *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { + CBLAS_INT total; + double prev; + double curr; + CBLAS_INT ix; + CBLAS_INT ip; + CBLAS_INT ia; + CBLAS_INT io; + CBLAS_INT i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return; + } + + io = 0; + if ( N1 == 0 && N2 == 0 ) { + ix = offsetX + ( ( N - 1 ) * strideX ); + io = offsetOut + ( ( N - 2 ) * strideOut ); + prev = X[ ix ]; + for ( i = N-2; i >= 0; i-- ) { + ix -= strideX; + curr = X[ ix ]; + out[ io ] = prev - curr; + prev = curr; + io -= strideOut; + } + return; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = X[ offsetX ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = X[ offsetX ]; + } else { + prev = append[ offsetA ]; + } + + // x + if ( N > 0 ) { + ix = offsetX; + if ( N1 == 0 ) { + prev = X[ ix ]; + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = X[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = X[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = append[ ia ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ia += strideA; + } + } + return; +} + +/** +* Calculates the k-th discrete forward difference of a double-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param x input array +* @param strideX stride length for `x` +* @param offsetX starting index for `x` +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for `prepend` +* @param offsetP starting index for `prepend` +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for `append` +* @param offsetA starting index for `append` +* @param out output array +* @param strideOut stride length for `out` +* @param offsetOut starting index for `out` +* @param workspace workspace array +* @param strideW stride length for `workspace` +* @param offsetW starting index for `workspace` +*/ +void API_SUFFIX(stdlib_strided_ddiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, double *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, double *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, double *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, double *workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { + CBLAS_INT total; + CBLAS_INT ix; + CBLAS_INT ip; + CBLAS_INT ia; + CBLAS_INT io; + CBLAS_INT n; + CBLAS_INT i; + + total = N + N1 + N2; + if ( total <= 1 || k >= total ) { + return; + } + + if ( k == 0 ) { + io = offsetOut; + ip = offsetP; + for ( i = 0; i < N1; i++ ) { + out[ io ] = prepend[ ip ]; + io += strideOut; + ip += strideP; + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + out[ io ] = X[ ix ]; + io += strideOut; + ix += strideX; + } + ia = offsetA; + for ( i = 0; i < N2; i++ ) { + out[ io ] = append[ ia ]; + io += strideOut; + ia += strideA; + } + } + + if ( k == 1 ) { + stdlib_strided_base_ddiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + return; + } + + stdlib_strided_base_ddiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, workspace, strideW, offsetW ); + + n = total - 1; + for ( i = 1; i < k - 1; i++ ) { + stdlib_strided_base_ddiff_ndarray( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, workspace, strideW, offsetW ); + n -= 1; + } + stdlib_strided_base_ddiff_ndarray( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); + return; +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ddiff.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ddiff.js new file mode 100644 index 000000000000..9f60cd2be39d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ddiff.js @@ -0,0 +1,218 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ddiff = require( './../lib/ddiff.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 14', function test( t ) { + t.strictEqual( ddiff.length, 14, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the k-th discrete forward differences of a double-precision floating-point strided array', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 1, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + 5.0, + -11.0, + 4.0, + 4.0, + 4.0, + 4.0, + 10.0, + 5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 7 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 2, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + -16.0, + 15.0, + 0.0, + 0.0, + 0.0, + 6.0, + -5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 6 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 3, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + 31.0, + -15.0, + 0.0, + 0.0, + 6.0, + -11.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 5 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + -46.0, + 15.0, + 0.0, + 6.0, + -17.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); + +tape( 'if provided 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + 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, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, 2, 2, p, 2, 2, a, 2, o, 2, w, 2 ); + expected = new Float64Array([ + 15.0, + 0.0, + -21.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 10.0, + 0.0, + 15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, -2, 2, p, -2, 2, a, -2, o, -2, w, -2 ); + expected = new Float64Array([ + -15.0, + 0.0, + 41.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + -15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ddiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ddiff.native.js new file mode 100644 index 000000000000..5e6e969e04cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ddiff.native.js @@ -0,0 +1,227 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var ddiff = tryRequire( resolve( __dirname, './../lib/ddiff.native.js' ) ); +var opts = { + 'skip': ( ddiff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 14', opts, function test( t ) { + t.strictEqual( ddiff.length, 14, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the k-th discrete forward differences of a double-precision floating-point strided array', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 1, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + 5.0, + -11.0, + 4.0, + 4.0, + 4.0, + 4.0, + 10.0, + 5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 7 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 2, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + -16.0, + 15.0, + 0.0, + 0.0, + 0.0, + 6.0, + -5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 6 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 3, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + 31.0, + -15.0, + 0.0, + 0.0, + 6.0, + -11.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 5 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + -46.0, + 15.0, + 0.0, + 6.0, + -17.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); + +tape( 'if provided 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, o, 1, w, 1 ); + expected = new Float64Array([ + 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, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, 2, 2, p, 2, 2, a, 2, o, 2, w, 2 ); + expected = new Float64Array([ + 15.0, + 0.0, + -21.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 10.0, + 0.0, + 15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, -2, 2, p, -2, 2, a, -2, o, -2, w, -2 ); + expected = new Float64Array([ + -15.0, + 0.0, + 41.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + -15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.js new file mode 100644 index 000000000000..b36476b38039 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/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 ddiff = 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 ddiff, '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 ddiff.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 ddiff = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( ddiff, 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 ddiff; + var main; + + main = require( './../lib/ddiff.js' ); + + ddiff = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( ddiff, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ndarray.js new file mode 100644 index 000000000000..f2385b211b6a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ndarray.js @@ -0,0 +1,248 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ddiff = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 19', function test( t ) { + t.strictEqual( ddiff.length, 19, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the k-th discrete forward differences of a double-precision floating-point strided array', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + 5.0, + -11.0, + 4.0, + 4.0, + 4.0, + 4.0, + 10.0, + 5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 7 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 2, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + -16.0, + 15.0, + 0.0, + 0.0, + 0.0, + 6.0, + -5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 6 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 3, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + 31.0, + -15.0, + 0.0, + 0.0, + 6.0, + -11.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 5 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 4, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + -46.0, + 15.0, + 0.0, + 6.0, + -17.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); + +tape( 'if provided 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, o, 1, 0, w, 1, 0 ); + expected = new Float64Array([ + 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, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, 2, 0, 2, p, 2, 0, 2, a, 2, 0, o, 2, 0, w, 2, 0 ); + expected = new Float64Array([ + 15.0, + 0.0, + -21.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 10.0, + 0.0, + 15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, -2, 4, 2, p, -2, 2, 2, a, -2, 2, o, -2, 10, w, -2, 10 ); // eslint-disable-line max-len + expected = new Float64Array([ + -15.0, + 0.0, + 41.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + -15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 6 ); + w = new Float64Array( 6 ); + + out = ddiff( 3, 1, x, 1, 2, 1, p, 1, 2, 1, a, 1, 2, o, 1, 2, w, 1, 2 ); + expected = new Float64Array([ + 0.0, + 0.0, + -13, + 4, + 4, + 25 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ndarray.native.js new file mode 100644 index 000000000000..6312e95860b7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ddiff/test/test.ndarray.native.js @@ -0,0 +1,257 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var ddiff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( ddiff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 19', opts, function test( t ) { + t.strictEqual( ddiff.length, 19, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the k-th discrete forward differences of a double-precision floating-point strided array', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + 5.0, + -11.0, + 4.0, + 4.0, + 4.0, + 4.0, + 10.0, + 5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 7 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 2, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + -16.0, + 15.0, + 0.0, + 0.0, + 0.0, + 6.0, + -5.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 6 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 3, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + 31.0, + -15.0, + 0.0, + 0.0, + 6.0, + -11.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + o = new Float64Array( 5 ); + w = new Float64Array( 8 ); + + out = ddiff( x.length, 4, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0, w, 1, 0 ); // eslint-disable-line max-len + expected = new Float64Array([ + -46.0, + 15.0, + 0.0, + 6.0, + -17.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +}); + +tape( 'if provided 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0 ] ); + a = new Float64Array( [ 30.0, 35.0 ] ); + o = new Float64Array( 8 ); + w = new Float64Array( 8 ); + + out = ddiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, o, 1, 0, w, 1, 0 ); + expected = new Float64Array([ + 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, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, 2, 0, 2, p, 2, 0, 2, a, 2, 0, o, 2, 0, w, 2, 0 ); + expected = new Float64Array([ + 15.0, + 0.0, + -21.0, + 0.0, + 8.0, + 0.0, + 8.0, + 0.0, + 10.0, + 0.0, + 15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 11 ); + w = new Float64Array( 11 ); + + out = ddiff( 3, 1, x, -2, 4, 2, p, -2, 2, 2, a, -2, 2, o, -2, 10, w, -2, 10 ); // eslint-disable-line max-len + expected = new Float64Array([ + -15.0, + 0.0, + 41.0, + 0.0, + -8.0, + 0.0, + -8.0, + 0.0, + 10.0, + 0.0, + -15.0 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return 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; + var w; + + x = new Float64Array( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = new Float64Array( [ 10.0, 15.0, 25.0 ] ); + a = new Float64Array( [ 30.0, 35.0, 45.0 ] ); + o = new Float64Array( 6 ); + w = new Float64Array( 6 ); + + out = ddiff( 3, 1, x, 1, 2, 1, p, 1, 2, 1, a, 1, 2, o, 1, 2, w, 1, 2 ); + expected = new Float64Array([ + 0.0, + 0.0, + -13, + 4, + 4, + 25 + ]); + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'return expected value' ); + + t.end(); +});