From a3467f3adccb20fa37a43bdd5c3ff6c7aa853fcf Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 12 Mar 2026 23:37:34 +0500 Subject: [PATCH 1/6] feat: add blas/ext/base/sdiff --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/sdiff/README.md | 391 ++++++++++ .../ext/base/sdiff/benchmark/benchmark.js | 124 ++++ .../base/sdiff/benchmark/benchmark.native.js | 129 ++++ .../base/sdiff/benchmark/benchmark.ndarray.js | 124 ++++ .../benchmark/benchmark.ndarray.native.js | 129 ++++ .../blas/ext/base/sdiff/benchmark/c/Makefile | 146 ++++ .../base/sdiff/benchmark/c/benchmark.length.c | 273 +++++++ .../@stdlib/blas/ext/base/sdiff/binding.gyp | 265 +++++++ .../@stdlib/blas/ext/base/sdiff/docs/repl.txt | 187 +++++ .../blas/ext/base/sdiff/docs/types/index.d.ts | 153 ++++ .../blas/ext/base/sdiff/docs/types/test.ts | 681 ++++++++++++++++++ .../blas/ext/base/sdiff/examples/c/Makefile | 146 ++++ .../blas/ext/base/sdiff/examples/c/example.c | 45 ++ .../blas/ext/base/sdiff/examples/index.js | 45 ++ .../@stdlib/blas/ext/base/sdiff/include.gypi | 70 ++ .../include/stdlib/blas/ext/base/sdiff.h | 46 ++ .../@stdlib/blas/ext/base/sdiff/lib/index.js | 80 ++ .../@stdlib/blas/ext/base/sdiff/lib/main.js | 35 + .../@stdlib/blas/ext/base/sdiff/lib/native.js | 35 + .../blas/ext/base/sdiff/lib/ndarray.js | 248 +++++++ .../blas/ext/base/sdiff/lib/ndarray.native.js | 76 ++ .../@stdlib/blas/ext/base/sdiff/lib/sdiff.js | 77 ++ .../blas/ext/base/sdiff/lib/sdiff.native.js | 71 ++ .../@stdlib/blas/ext/base/sdiff/manifest.json | 81 +++ .../@stdlib/blas/ext/base/sdiff/package.json | 74 ++ .../@stdlib/blas/ext/base/sdiff/src/Makefile | 70 ++ .../@stdlib/blas/ext/base/sdiff/src/addon.c | 86 +++ .../@stdlib/blas/ext/base/sdiff/src/main.c | 235 ++++++ .../@stdlib/blas/ext/base/sdiff/test/test.js | 38 + .../blas/ext/base/sdiff/test/test.ndarray.js | 302 ++++++++ .../base/sdiff/test/test.ndarray.native.js | 310 ++++++++ .../blas/ext/base/sdiff/test/test.sdiff.js | 289 ++++++++ .../ext/base/sdiff/test/test.sdiff.native.js | 298 ++++++++ 33 files changed, 5359 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/include/stdlib/blas/ext/base/sdiff.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md new file mode 100644 index 000000000000..7ff00dca458e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md @@ -0,0 +1,391 @@ + + +# sdiff + +> Calculate the k-th discrete forward difference of a single-precision floating-point strided array. + +
+ +## Usage + +```javascript +var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); +``` + + + +#### sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 6 ); +var w = new Float32Array( 6 ); + +sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **k**: number of times to recursively compute differences. +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. +- **N1**: number of elements to `prepend`. +- **prepend**: a [`Float32Array`][@stdlib/array/float32] containing values to prepend prior to computing differences. +- **strideP**: stride length for `prepend`. +- **N2**: number of elements to `append`. +- **append**: a [`Float32Array`][@stdlib/array/float32] containing values to append prior to computing differences. +- **strideA**: stride length for `append`. +- **out**: output [`Float32Array`][@stdlib/array/float32]. Must have `N + N1 + N2 - k` elements. +- **strideOut**: stride length for `out`. +- **workspace**: workspace [`Float32Array`][@stdlib/array/float32]. Must have `N + N1 + N2 - 1` elements. +- **strideW**: stride length for `workspace`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to differences of every other element: + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 4 ); +var w = new Float32Array( 4 ); + +sdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 1.0, 4.0, 4.0, 1.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +// Initial array... +var x0 = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + +// Create an offset view... +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 5 ); +var w = new Float32Array( 5 ); + +sdiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// out => [ 3.0, 2.0, 2.0, 2.0, 1.0 ] +``` + + + +#### sdiff.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 6 ); +var w = new Float32Array( 6 ); + +sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( out ); +// out => [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetP**: starting index for `prepend`. +- **offsetA**: starting index for `append`. +- **offsetOut**: starting index for `out`. +- **offsetW**: starting index of `workspace`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); +var p = new Float32Array( [ 1.0 ] ); +var a = new Float32Array( [ 11.0 ] ); +var out = new Float32Array( 4 ); +var w = new Float32Array( 4 ); + +sdiff.ndarray( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( out ); +// out => [ 5.0, 2.0, 2.0, 1.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the output array unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Append array: ', a ); + +var out = new Float32Array( 10 ); + +var w = new Float32Array( 13 ); + +sdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); +console.log( 'Output', out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/sdiff.h" +``` + + + +#### stdlib_strided_sdiff( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, \*Out, strideOut, \*Workspace, strideW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array. + +```c +const float x[] = { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f }; +const float p[] = { 1.0f }; +const float a[] = { 11.0f }; +float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; +float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_sdiff( 5, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **k**: `[in] CBLAS_INT` number of times to recursively compute differences. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `x`. +- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. +- **prepend**: `[in] float*` array containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. +- **N2**: `[in] CBLAS_INT` number of elements in `append`. +- **append**: `[in] float*` array containing values to append prior to computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `append`. +- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `out`. +- **Workspace**: `[inout] float*` workspace array. Must have `N + N1 + N2 - 1` elements. +- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. + +```c +void stdlib_strided_sdiff( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ); +``` + + + +#### stdlib_strided_sdiff_ndarray( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, \*Out, strideOut, offsetOut, \*Workspace, strideW, offsetW ) + +Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. + +```c +const float x[] = { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f }; +const float p[] = { 1.0f }; +const float a[] = { 11.0f }; +float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; +float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_sdiff_ndarray( 5, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **k**: `[in] CBLAS_INT` number of times to recursively compute differences. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `x`. +- **offsetX**: `[in] CBLAS_INT` starting index for `x`. +- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. +- **prepend**: `[in] float*` array containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. +- **offsetP**: `[in] CBLAS_INT` starting index for `prepend`. +- **N2**: `[in] CBLAS_INT` number of elements in `append`. +- **append**: `[in] float*` array containing values to append prior to computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `append`. +- **offsetA**: `[in] CBLAS_INT` starting index for `append`. +- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `out`. +- **offsetOut**: `[in] CBLAS_INT` starting index for `out`. +- **Workspace**: `[inout] float*` workspace array. Must have `N + N1 + N2 - 1` elements. +- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. +- **offsetW**: `[in] CBLAS_INT` starting index for `workspace`. + +```c +void stdlib_strided_sdiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/sdiff.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Define prepend values: + const float p[] = { -1.0f }; + + // Define append values: + const float a[] = { 10.0f }; + + // Define output array: + float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Define workspace: + float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Compute forward differences: + stdlib_strided_sdiff( 8, 3, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + // Print the result: + for ( int i = 0; i < 7; i++ ) { + printf( "out[ %i ] = %f\n", i, out[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js new file mode 100644 index 000000000000..b9d5ad893ff7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var sdiff = require( './../lib/sdiff.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js new file mode 100644 index 000000000000..e4df3440af8c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; +var sdiff = tryRequire( resolve( __dirname, './../lib/sdiff.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..a308547d5137 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var sdiff = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..ac03c4d98d29 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,129 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; +var sdiff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ol; + var N1; + var N2; + var x; + var p; + var a; + var w; + var o; + var k; + var N; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + w = new Float32Array( N+N1+N2-1 ); + o = new Float32Array( ol ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sdiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( o[ i%ol ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:ndarray:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile new file mode 100644 index 000000000000..7280962b4c4d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..ca14bf52618d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c @@ -0,0 +1,273 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include +#include +#include +#include +#include + +#define NAME "sdiff" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float *x; + float *p; + float *a; + float *o; + float *w; + double t; + int wl; + int ol; + int N1; + int N2; + int k; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + wl = N + N1 + N2 - 1; + + x = (float *) malloc( N * sizeof( float ) ); + for ( i = 0; i < N; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + p = (float *) malloc( N1 * sizeof( float ) ); + a = (float *) malloc( N2 * sizeof( float ) ); + for ( i = 0; i < N1; i++ ) { + p[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + a[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + w = (float *) malloc( wl * sizeof( float ) ); + for ( i = 0; i < wl; i++ ) { + w[ i ] = 0.0f; + } + + o = (float *) malloc( ol * sizeof( float ) ); + for ( i = 0; i < ol; i++ ) { + o[ i ] = 0.0f; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); + if ( o[ 0 ] != o[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( o[ ol-1 ] != o[ ol-1 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( p ); + free( a ); + free( w ); + free( o ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float *x; + float *p; + float *a; + float *o; + float *w; + double t; + int wl; + int ol; + int N1; + int N2; + int k; + int N; + int i; + + N = len; + N1 = 1; + N2 = 1; + k = 1; // worst case: N + N1 + N2 - 1 + ol = N + N1 + N2 - k; + wl = N + N1 + N2 - 1; + + x = (float *) malloc( N * sizeof( float ) ); + for ( i = 0; i < N; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + p = (float *) malloc( N1 * sizeof( float ) ); + a = (float *) malloc( N2 * sizeof( float ) ); + for ( i = 0; i < N1; i++ ) { + p[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + a[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + + w = (float *) malloc( wl * sizeof( float ) ); + for ( i = 0; i < wl; i++ ) { + w[ i ] = 0.0f; + } + + o = (float *) malloc( ol * sizeof( float ) ); + for ( i = 0; i < ol; i++ ) { + o[ i ] = 0.0f; + } + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_sdiff_ndarray( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); + if ( o[ 0 ] != o[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( o[ ol-1 ] != o[ ol-1 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( p ); + free( a ); + free( w ); + free( o ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/binding.gyp @@ -0,0 +1,265 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt new file mode 100644 index 000000000000..2a828d16994e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt @@ -0,0 +1,187 @@ + +{{alias}}( N, k, x,sx, N1,p,sp, N2,a,sa, out,so, w,sw ) + Calculates the k-th discrete forward differences of a single-precision + floating-point strided array. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns the output array unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of times to recursively compute differences. + + x: Float32Array + Input array. + + sx: integer + Stride length for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Float32Array + Array containing values to prepend prior to computing differences. + + sp: integer + Stride length for `prepend`. + + N2: integer + Number of elements to `append`. + + a: Float32Array + Array containing values to append prior to computing differences. + + sa: integer + Stride length for `append`. + + out: Float32Array + Output array. + + so: integer + Stride length for `out`. + + w: Float32Array + Workspace array. + + sw: integer + Stride length for `workspace`. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 4 ); + > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > {{alias}}( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, -3.0, 4.0, 1.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > p = new {{alias:@stdlib/array/float32}}( [ 1.0 ] ); + > a = new {{alias:@stdlib/array/float32}}( [ 11.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 4 ); + > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > {{alias}}( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, 4.0, 4.0, 1.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > p = new {{alias:@stdlib/array/float32}}( [ 1.0 ] ); + > a = new {{alias:@stdlib/array/float32}}( [ 11.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 5 ); + > var w = new {{alias:@stdlib/array/float32}}( 5 ); + > {{alias}}( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 3.0, 2.0, 2.0, 2.0, 1.0 ] + + +{{alias}}.ndarray( N, k, X,sx,ox, N1,p,sp,op, N2,a,sa,oa, Out,so,oo, W,sw,ow ) + Calculates the k-th discrete forward differences of a single-precision + floating-point strided array using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of times to recursively compute differences. + + X: Float32Array + Input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Float32Array + Array containing values to prepend prior to computing differences. + + sp: integer + Stride length for `prepend`. + + op: integer + Starting index for `prepend`. + + N2: integer + Number of elements to `append`. + + a: Float32Array + Array containing values to append prior to computing differences. + + sa: integer + Stride length for `append`. + + oa: integer + Starting index for `append`. + + Out: Float32Array + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + W: Float32Array + Workspace array. + + sw: integer + Stride length for `workspace`. + + ow: integer + Starting index for `workspace`. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > var p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); + > var a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 4 ); + > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > {{alias}}.ndarray( 3, 1, x,1,0, 1, p,1,0, 1, a,1,0, out,1,0, w,1,0 ) + [ 1.0, -3.0, 4.0, 1.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); + > a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); + > out = new {{alias:@stdlib/array/float32}}( 3 ); + > w = new {{alias:@stdlib/array/float32}}( 3 ); + > {{alias}}.ndarray( 2, 1, x,1,1, 1, p,1,0, 1, a,1,0, out,1,0, w,1,0 ) + [ -2.0, 4.0, 1.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts new file mode 100644 index 000000000000..158d19b6d8b3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts @@ -0,0 +1,153 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `sdiff`. +*/ +interface Routine { + /** + * Calculates the k-th discrete forward difference of a single-precision floating-point strided array. + * + * @param N - number of indexed elements + * @param k - number of times to recursively compute differences + * @param x - input array + * @param strideX - stride length for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + * var p = new Float32Array( [ 1.0 ] ); + * var a = new Float32Array( [ 22.0 ] ); + * var out = new Float32Array( 5 ); + * var w = new Float32Array( 6 ); + * + * sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + * + * console.log( out ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ( N: number, k: number, x: Float32Array, strideX: number, N1: number, prepend: Float32Array, strideP: number, N2: number, append: Float32Array, strideA: number, out: Float32Array, strideOut: number, workspace: Float32Array, strideW: number ): Float32Array; + + /** + * Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param k - number of times to recursively compute differences + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param offsetP - starting index for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param offsetA - starting index for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @param workspace - workspace array + * @param strideW - stride length for `workspace` + * @param offsetW - starting index for `workspace` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + * var p = new Float32Array( [ 1.0 ] ); + * var a = new Float32Array( [ 22.0 ] ); + * var out = new Float32Array( 5 ); + * var w = new Float32Array( 6 ); + * + * sdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + * + * console.log( out ); + * // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ndarray( N: number, k: number, x: Float32Array, strideX: number, offsetX: number, N1: number, prepend: Float32Array, strideP: number, offsetP: number, N2: number, append: Float32Array, strideA: number, offsetA: number, out: Float32Array, strideOut: number, offsetOut: number, workspace: Float32Array, strideW: number, offsetW: number ): Float32Array; +} + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param N - number of indexed elements +* @param k - number of times to recursively compute differences +* @param x - input array +* @param strideX - stride length for `x` +* @param N1 - number of indexed elements of prepend +* @param prepend - prepend array +* @param strideP - stride length for `prepend` +* @param N2 - number of indexed elements of append +* @param append - append array +* @param strideA - stride length for `append` +* @param out - output array +* @param strideOut - stride length for `out` +* @param workspace - workspace array +* @param strideW - stride length for `workspace` +* @returns output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +declare var sdiff: Routine; + + +// EXPORTS // + +export = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts new file mode 100644 index 000000000000..daafa1cd28eb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts @@ -0,0 +1,681 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import sdiff = require( './index' ); + + +// TESTS // + +// The function returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( '10', 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( true, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( false, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( null, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( undefined, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( [], 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( {}, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( ( x: number ): number => x, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, '10', x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, true, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, false, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, null, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, undefined, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, [], x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, {}, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, ( x: number ): number => x, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( 10, 1, '10', 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, false, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, null, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, undefined, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, [], 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, {}, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 10, 1, ( x: number ): number => x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, '10', 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, true, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, false, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, null, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, undefined, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, [], 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, {}, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, ( x: number ): number => x, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, '10', p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, true, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, false, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, null, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, undefined, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, [], p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, {}, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, ( x: number ): number => x, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, '10', 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, true, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, false, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, null, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, undefined, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, [], 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, {}, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, ( x: number ): number => x, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, '10', 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, true, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, false, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, null, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, undefined, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, [], 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, {}, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, ( x: number ): number => x, 1, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, '10', a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, true, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, false, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, null, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, undefined, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, [], a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, {}, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, ( x: number ): number => x, a, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, '10', 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, true, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, false, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, null, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, undefined, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, [], 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, {}, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, ( x: number ): number => x, 1, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, '10', out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, true, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, false, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, null, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, undefined, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, [], out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, {}, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, ( x: number ): number => x, out, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, '10', 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, true, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, false, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, null, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, undefined, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, [], 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, {}, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, ( x: number ): number => x, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, '10', w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, true, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, false, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, null, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, undefined, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, [], w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, {}, w, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, ( x: number ): number => x, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a thirteenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, '10', 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, true, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, false, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, null, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, undefined, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, [], 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, {}, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, '10' ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, true ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, false ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, null ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, undefined ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, [] ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, {} ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff(); // $ExpectError + sdiff( x.length ); // $ExpectError + sdiff( x.length, 1 ); // $ExpectError + sdiff( x.length, 1, x ); // $ExpectError + sdiff( x.length, 1, x, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( '10', 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( true, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( false, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( null, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( undefined, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( [], 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( {}, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( ( x: number ): number => x, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, false, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, null, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, undefined, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, [], x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, {}, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, ( x: number ): number => x, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... +{ + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( 10, 1, '10', 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, [], 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( 10, 1, ( x: number ): number => x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, false, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, null, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, undefined, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, [], 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, {}, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, ( x: number ): number => x, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, false, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, null, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, undefined, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, [], 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, {}, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, ( x: number ): number => x, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, false, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, null, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, undefined, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, [], p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, {}, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, ( x: number ): number => x, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, '10', 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, false, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, null, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, undefined, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, [], 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, {}, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, ( x: number ): number => x, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, false, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, null, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, undefined, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, [], 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, {}, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, ( x: number ): number => x, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, '10', 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, true, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, false, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, null, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, undefined, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, [], 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, {}, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, ( x: number ): number => x, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, false, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, null, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, undefined, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, [], a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, {}, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, ( x: number ): number => x, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, '10', 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, false, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, null, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, undefined, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, [], 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, {}, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, ( x: number ): number => x, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, false, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, null, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, undefined, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, [], 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, {}, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, ( x: number ): number => x, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, false, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, null, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, undefined, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, [], out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, {}, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, ( x: number ): number => x, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourteenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, '10', 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, false, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, null, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, undefined, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, [], 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, {}, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, ( x: number ): number => x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, false, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, null, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, undefined, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, [], 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, {}, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10', w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, false, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, null, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, undefined, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, [], w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, {}, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventeenth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, '10', 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, true, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, false, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, null, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, undefined, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, [], 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, {}, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, '10', 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, true, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, false, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, null, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, undefined, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, [], 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, {}, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a nineteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, '10' ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, true ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, false ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, null ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, undefined ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, [] ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, {} ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const p = new Float32Array( 1 ); + const a = new Float32Array( 1 ); + const out = new Float32Array( 11 ); + const w = new Float32Array( 11 ); + + sdiff.ndarray(); // $ExpectError + sdiff.ndarray( x.length ); // $ExpectError + sdiff.ndarray( x.length, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile new file mode 100644 index 000000000000..ff5293d3059f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c new file mode 100644 index 000000000000..0a17b25467ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Define prepend values: + const float p[] = { -1.0f }; + + // Define append values: + const float a[] = { 10.0f }; + + // Define output array: + float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Define workspace: + float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Compute forward differences: + stdlib_strided_sdiff( 8, 3, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + // Print the result: + for ( int i = 0; i < 7; i++ ) { + printf( "out[ %i ] = %f\n", i, out[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js new file mode 100644 index 000000000000..c4e79b629048 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'float32' +}); +console.log( 'Append array: ', a ); + +var out = new Float32Array( 10 ); + +var w = new Float32Array( 13 ); + +sdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); +console.log( 'Output', out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi new file mode 100644 index 000000000000..dcb556d250e8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/include.gypi @@ -0,0 +1,70 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var sdiff; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + sdiff = main; +} else { + sdiff = tmp; +} + + +// EXPORTS // + +module.exports = sdiff; + +// exports: { "ndarray": "sdiff.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js new file mode 100644 index 000000000000..96560206424c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var sdiff = require( './sdiff.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( sdiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js new file mode 100644 index 000000000000..aea31a58b03b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/native.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var sdiff = require( './sdiff.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( sdiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js new file mode 100644 index 000000000000..dd4fbf154b3c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js @@ -0,0 +1,248 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var scopy = require( '@stdlib/blas/base/scopy' ); + + +// FUNCTIONS // + +/** +* Calculates the forward difference of a single-precision floating-point strided array using alternative indexing semantics. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @returns {Float32Array} output array +*/ +function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var total; + var prev; + var curr; + var ix; + var io; + var ip; + var ia; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + if ( N1 === 0 && N2 === 0 ) { + ix = offsetX; + io = offsetOut; + prev = x[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + return out; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = x[ offsetX ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = x[ offsetX ]; + io = offsetOut; + } else { + prev = append[ offsetA ]; + io = offsetOut; + } + + // x + if ( N > 0 ) { + ix = offsetX; + if ( N1 === 0 ) { + prev = x[ ix ]; + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = append[ ia ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ia += strideA; + } + } + return out; +} + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {PositiveInteger} offsetW - starting index for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + var total; + var io; + var n; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + // If k >= total number of elements, the k-th forward difference results in an empty array, so this function is a no-op. + if ( k >= total ) { + return out; + } + + if ( k === 0 ) { + // Copy `prepend` into output array: + scopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + + // Copy `x` into output array: + io = offsetOut + ( N1 * strideOut ); + scopy.ndarray( N, x, strideX, offsetX, out, strideOut, io ); + + // Copy `append` into output array: + io = offsetOut + ( ( N1 + N ) * strideOut ); + scopy.ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + + return out; + } + + if ( k === 1 ) { + base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; + } + + base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, workspace, strideW, offsetW ); + + n = total - 1; + for ( i = 1; i < k - 1; i++ ) { + base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, workspace, strideW, offsetW ); + n -= 1; + } + + base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js new file mode 100644 index 000000000000..113c33ce6552 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {PositiveInteger} offsetW - starting index for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + addon.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js new file mode 100644 index 000000000000..2792282d0f0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) { + var ox = stride2offset( N, strideX ); + var op = stride2offset( N1, strideP ); + var oa = stride2offset( N2, strideA ); + var oo = stride2offset( N + N1 + N2 - k, strideOut ); + var ow = stride2offset( N + N1 + N2 - 1, strideW ); + ndarray( N, k, x, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo, workspace, strideW, ow ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js new file mode 100644 index 000000000000..cb70f8cf692c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {Float32Array} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = new Float32Array( [ 1.0 ] ); +* var a = new Float32Array( [ 22.0 ] ); +* var out = new Float32Array( 5 ); +* var w = new Float32Array( 6 ); +* +* sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // out => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) { + addon( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ); + return out; +} + + +// EXPORTS // + +module.exports = sdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json new file mode 100644 index 000000000000..f9ac5c23cdb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/manifest.json @@ -0,0 +1,81 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/scopy", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/scopy" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/scopy" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json b/lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json new file mode 100644 index 000000000000..7de10049bfe3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/ext/base/sdiff", + "version": "0.0.0", + "description": "Calculate the k-th discrete forward difference of a single-precision floating-point strided array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "diff", + "difference", + "gradient", + "strided", + "array", + "float32", + "float", + "float32array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c new file mode 100644 index 000000000000..029243979ddb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 14 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, out, N+N1+N2-k, strideOut, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, workspace, N+N1+N2-1, strideW, argv, 12 ); + API_SUFFIX(stdlib_strided_sdiff)( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 19 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N1, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, strideP, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, offsetP, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N2, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideA, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 12 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 14 ); + STDLIB_NAPI_ARGV_INT64( env, offsetOut, argv, 15 ); + STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 17 ); + STDLIB_NAPI_ARGV_INT64( env, offsetW, argv, 18 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, out, N+N1+N2-k, strideOut, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, workspace, N+N1+N2-1, strideW, argv, 16 ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c new file mode 100644 index 000000000000..e8d1563cc528 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c @@ -0,0 +1,235 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/sdiff.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/scopy.h" + +/** +* Calculates the k-th discrete forward differences of a single-precision floating-point strided array. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param X input array +* @param strideX stride length for X +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for prepend +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for append +* @param out output array +* @param strideOut stride length for out +* @param Workspace workspace array +* @param strideW stride length for workspace +*/ +void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT op = stdlib_strided_stride2offset( N1, strideP ); + CBLAS_INT oa = stdlib_strided_stride2offset( N2, strideA ); + CBLAS_INT oo = stdlib_strided_stride2offset( N+N1+N2-k, strideOut ); + CBLAS_INT ow = stdlib_strided_stride2offset( N+N1+N2-1, strideW ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo, Workspace, strideW, ow ); +} + +/** +* Calculates the forward difference of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length for X +* @param offsetX starting index for X +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for prepend +* @param offsetP starting index for prepend +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for append +* @param offsetA starting index for append +* @param out output array +* @param strideOut stride length for out +* @param offsetOut starting index for out +*/ +static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { + CBLAS_INT total; + CBLAS_INT ix; + CBLAS_INT io; + CBLAS_INT ip; + CBLAS_INT ia; + CBLAS_INT i; + float prev; + float curr; + + total = N + N1 + N2; + if ( total <= 1 ) { + return; + } + + if ( N1 == 0 && N2 == 0 ) { + ix = offsetX; + io = offsetOut; + prev = X[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = X[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + return; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = X[ offsetX ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = X[ offsetX ]; + io = offsetOut; + } else { + prev = append[ offsetA ]; + io = offsetOut; + } + + // X + if ( N > 0 ) { + ix = offsetX; + if ( N1 == 0 ) { + prev = X[ ix ]; + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = X[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = X[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = append[ ia ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + ia += strideA; + } + } +} + +/** +* Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param X input array +* @param strideX stride length for X +* @param offsetX starting index for X +* @param N1 number of indexed elements of prepend +* @param prepend prepend array +* @param strideP stride length for prepend +* @param offsetP starting index for prepend +* @param N2 number of indexed elements of append +* @param append append array +* @param strideA stride length for append +* @param offsetA starting index for append +* @param out output array +* @param strideOut stride length for out +* @param offsetOut starting index for out +* @param Workspace workspace array +* @param strideW stride length for workspace +* @param offsetW starting index for workspace +*/ +void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { + CBLAS_INT total; + CBLAS_INT io; + CBLAS_INT n; + CBLAS_INT i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return; + } + if ( k >= total ) { + return; + } + if ( k == 0 ) { + // Copy `prepend` into output array: + c_scopy_ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + + // Copy `X` into output array: + io = offsetOut + ( N1 * strideOut ); + c_scopy_ndarray( N, X, strideX, offsetX, out, strideOut, io ); + + // Copy `append` into output array: + io = offsetOut + ( ( N1 + N ) * strideOut ); + c_scopy_ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + return; + } + if ( k == 1 ) { + stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + return; + } + stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Workspace, strideW, offsetW ); + + n = total - 1; + for ( i = 1; i < k - 1; i++ ) { + stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Workspace, strideW, offsetW ); + n -= 1; + } + stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js new file mode 100644 index 000000000000..2baa802ca7f0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sdiff = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof sdiff.ndarray, 'function', 'has method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js new file mode 100644 index 000000000000..4b47fab22dbd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js @@ -0,0 +1,302 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Single element (total <= 1 in base): + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides and offsets', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Offset for `x`: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 5.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 4, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 2, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 2, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 3, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js new file mode 100644 index 000000000000..b63122560dfb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.native.js @@ -0,0 +1,310 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sdiff = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides and offsets', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Offset for `x`: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 5.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 4, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 2, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 2, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 3, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js new file mode 100644 index 000000000000..5369f57f22b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.js @@ -0,0 +1,289 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sdiff = require( './../lib/sdiff.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 2, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 2, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 2, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 3, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js new file mode 100644 index 000000000000..d3c2f1209076 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.sdiff.native.js @@ -0,0 +1,298 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sdiff = tryRequire( resolve( __dirname, './../lib/sdiff.native.js' ) ); +var opts = { + 'skip': ( sdiff instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 2.0, 2.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates higher-order forward differences', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Second forward difference (k=2): + x = new Float32Array( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 22.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 5 ); + + sdiff( x.length, 3, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input)', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 2.0, 4.0, 6.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 5 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 4.0, 6.0, 7.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0, 0.0 ] ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( [ 0.0 ] ); + w = new Float32Array( 1 ); + + sdiff( x.length, 5, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = new Float32Array( [ 1.0, 3.0, 6.0, 10.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Negative strides: + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 6 ); + w = new Float32Array( 6 ); + + sdiff( x.length, 1, x, -1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = new Float32Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 11.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 4.0, 4.0, 1.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = new Float32Array( [ 6.0, 8.0 ] ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( 0 ); + out = new Float32Array( 3 ); + w = new Float32Array( 3 ); + + sdiff( x.length, 1, x, 1, 2, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 3.0, 2.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = new Float32Array( 0 ); + p = new Float32Array( [ 1.0, 3.0 ] ); + a = new Float32Array( [ 7.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 2, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = new Float32Array( [ 2.0, 4.0 ] ); + p = new Float32Array( [ 1.0 ] ); + a = new Float32Array( [ 6.0, 10.0 ] ); + out = new Float32Array( 4 ); + w = new Float32Array( 4 ); + + sdiff( x.length, 1, x, 1, 1, p, 1, 2, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 1.0, 2.0, 2.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend', opts, function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = new Float32Array( [ 2.0, 5.0 ] ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 10.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( x.length, 1, x, 1, 0, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = new Float32Array( 0 ); + p = new Float32Array( 0 ); + a = new Float32Array( [ 1.0, 4.0, 9.0 ] ); + out = new Float32Array( 2 ); + w = new Float32Array( 2 ); + + sdiff( 0, 1, x, 1, 0, p, 1, 3, a, 1, out, 1, w, 1 ); + + expected = new Float32Array( [ 3.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); From cf8ca6bd09602a99a61ce2dc72b43aef0cfabaad Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 12 Mar 2026 23:47:28 +0500 Subject: [PATCH 2/6] docs: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile index 7280962b4c4d..0756dc7da20a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# 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. From f32d2922376f7c0e78ed02ace632cbef96ef030d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 12 Mar 2026 23:47:57 +0500 Subject: [PATCH 3/6] docs: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/sdiff/examples/c/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile index ff5293d3059f..c8f8e9a1517b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# 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. From b353b7d20e20832b58040320ce313cbb85332769 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 13 Mar 2026 00:03:49 +0500 Subject: [PATCH 4/6] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/sdiff/src/addon.c | 12 ++-- .../@stdlib/blas/ext/base/sdiff/src/main.c | 66 +++++++++---------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c index 029243979ddb..2b7f1dee233e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c @@ -45,9 +45,9 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 5 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 8 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, out, N+N1+N2-k, strideOut, argv, 10 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, workspace, N+N1+N2-1, strideW, argv, 12 ); - API_SUFFIX(stdlib_strided_sdiff)( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-k, strideOut, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Workspace, N+N1+N2-1, strideW, argv, 12 ); + API_SUFFIX(stdlib_strided_sdiff)( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, Out, strideOut, Workspace, strideW ); return NULL; } @@ -77,9 +77,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 6 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 10 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, out, N+N1+N2-k, strideOut, argv, 13 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, workspace, N+N1+N2-1, strideW, argv, 16 ); - API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-k, strideOut, argv, 13 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Workspace, N+N1+N2-1, strideW, argv, 16 ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut, Workspace, strideW, offsetW ); return NULL; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c index e8d1563cc528..d265a72a2f28 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c @@ -34,18 +34,18 @@ * @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 +* @param Out Output array +* @param strideOut stride length for Out +* @param Workspace Workspace array +* @param strideW stride length for Workspace */ -void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ) { +void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); CBLAS_INT op = stdlib_strided_stride2offset( N1, strideP ); CBLAS_INT oa = stdlib_strided_stride2offset( N2, strideA ); CBLAS_INT oo = stdlib_strided_stride2offset( N+N1+N2-k, strideOut ); CBLAS_INT ow = stdlib_strided_stride2offset( N+N1+N2-1, strideW ); - API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo, Workspace, strideW, ow ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, Out, strideOut, oo, Workspace, strideW, ow ); } /** @@ -63,11 +63,11 @@ void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, con * @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 Out Output array +* @param strideOut stride length for Out +* @param offsetOut starting index for Out */ -static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { +static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { CBLAS_INT total; CBLAS_INT ix; CBLAS_INT io; @@ -89,7 +89,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X for ( i = 1; i < N; i++ ) { ix += strideX; curr = X[ ix ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; } @@ -104,18 +104,18 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X for ( i = 1; i < N1; i++ ) { ip += strideP; curr = prepend[ ip ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; } if ( N > 0 ) { curr = X[ offsetX ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; } else if ( N2 > 0 ) { curr = append[ offsetA ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; } @@ -135,7 +135,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X ix += strideX; for ( i = 1; i < N; i++ ) { curr = X[ ix ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; ix += strideX; @@ -144,7 +144,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X ix += strideX; for ( i = 1; i < N; i++ ) { curr = X[ ix ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; ix += strideX; @@ -152,7 +152,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X } if ( N2 > 0 ) { curr = append[ offsetA ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; } @@ -163,7 +163,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X ia = offsetA + strideA; for ( i = 1; i < N2; i++ ) { curr = append[ ia ]; - out[ io ] = curr - prev; + Out[ io ] = curr - prev; prev = curr; io += strideOut; ia += strideA; @@ -187,14 +187,14 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X * @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 +* @param Out Output array +* @param strideOut stride length for Out +* @param offsetOut starting index for Out +* @param Workspace Workspace array +* @param strideW stride length for Workspace +* @param offsetW starting index for Workspace */ -void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { +void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { CBLAS_INT total; CBLAS_INT io; CBLAS_INT n; @@ -208,20 +208,20 @@ void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_IN return; } if ( k == 0 ) { - // Copy `prepend` into output array: - c_scopy_ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + // Copy `prepend` into Output array: + c_scopy_ndarray( N1, prepend, strideP, offsetP, Out, strideOut, offsetOut ); - // Copy `X` into output array: + // Copy `X` into Output array: io = offsetOut + ( N1 * strideOut ); - c_scopy_ndarray( N, X, strideX, offsetX, out, strideOut, io ); + c_scopy_ndarray( N, X, strideX, offsetX, Out, strideOut, io ); - // Copy `append` into output array: + // Copy `append` into Output array: io = offsetOut + ( ( N1 + N ) * strideOut ); - c_scopy_ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + c_scopy_ndarray( N2, append, strideA, offsetA, Out, strideOut, io ); return; } if ( k == 1 ) { - stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); + stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut ); return; } stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Workspace, strideW, offsetW ); @@ -231,5 +231,5 @@ void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_IN stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Workspace, strideW, offsetW ); n -= 1; } - stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); + stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Out, strideOut, offsetOut ); } From df9851ea6aabfbfd51493bfe1f107a21b76884bc Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 13 Mar 2026 01:07:07 +0500 Subject: [PATCH 5/6] docs: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md index 7ff00dca458e..c3357bf519ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md @@ -233,7 +233,7 @@ console.log( 'Output', out ); -#### stdlib_strided_sdiff( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, \*Out, strideOut, \*Workspace, strideW ) +#### stdlib_strided_sdiff( N, k, \*X, strideX, N1, \*prepend, strideP, N2, \*append, strideA, \*Out, strideOut, \*Workspace, strideW ) Calculates the k-th discrete forward differences of a single-precision floating-point strided array. @@ -270,7 +270,7 @@ void stdlib_strided_sdiff( const CBLAS_INT N, const CBLAS_INT k, const float *X, -#### stdlib_strided_sdiff_ndarray( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, \*Out, strideOut, offsetOut, \*Workspace, strideW, offsetW ) +#### stdlib_strided_sdiff_ndarray( N, k, \*X, strideX, offsetX, N1, \*prepend, strideP, offsetP, N2, \*append, strideA, offsetA, \*Out, strideOut, offsetOut, \*Workspace, strideW, offsetW ) Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. From f3d0d83502754fc0f0b425e46ea9a8fd3a147011 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 21 Apr 2026 21:38:52 +0500 Subject: [PATCH 6/6] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/sdiff/README.md | 92 ++++----- .../ext/base/sdiff/benchmark/benchmark.js | 8 +- .../base/sdiff/benchmark/benchmark.native.js | 8 +- .../base/sdiff/benchmark/benchmark.ndarray.js | 8 +- .../benchmark/benchmark.ndarray.native.js | 8 +- .../base/sdiff/benchmark/c/benchmark.length.c | 4 +- .../@stdlib/blas/ext/base/sdiff/docs/repl.txt | 62 +++--- .../blas/ext/base/sdiff/docs/types/index.d.ts | 27 ++- .../blas/ext/base/sdiff/docs/types/test.ts | 96 ++++----- .../blas/ext/base/sdiff/examples/c/example.c | 8 +- .../blas/ext/base/sdiff/examples/index.js | 3 +- .../include/stdlib/blas/ext/base/sdiff.h | 8 +- .../@stdlib/blas/ext/base/sdiff/lib/base.js | 151 ++++++++++++++ .../blas/ext/base/sdiff/lib/ndarray.js | 161 ++------------- .../blas/ext/base/sdiff/lib/ndarray.native.js | 6 +- .../@stdlib/blas/ext/base/sdiff/lib/sdiff.js | 4 +- .../blas/ext/base/sdiff/lib/sdiff.native.js | 4 +- .../@stdlib/blas/ext/base/sdiff/src/addon.c | 12 +- .../@stdlib/blas/ext/base/sdiff/src/main.c | 188 +++++++++--------- .../@stdlib/blas/ext/base/sdiff/test/test.js | 48 ++++- .../blas/ext/base/sdiff/test/test.ndarray.js | 1 - 21 files changed, 498 insertions(+), 409 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/base.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md index c3357bf519ef..1e1eff53f5aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/README.md @@ -34,7 +34,7 @@ var sdiff = require( '@stdlib/blas/ext/base/sdiff' ); #### sdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) -Calculates the k-th discrete forward differences of a single-precision floating-point strided array. +Calculates the k-th discrete forward difference of a single-precision floating-point strided array. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -57,10 +57,10 @@ The function has the following parameters: - **k**: number of times to recursively compute differences. - **x**: input [`Float32Array`][@stdlib/array/float32]. - **strideX**: stride length for `x`. -- **N1**: number of elements to `prepend`. +- **N1**: number of indexed elements to `prepend`. - **prepend**: a [`Float32Array`][@stdlib/array/float32] containing values to prepend prior to computing differences. - **strideP**: stride length for `prepend`. -- **N2**: number of elements to `append`. +- **N2**: number of indexed elements to `append`. - **append**: a [`Float32Array`][@stdlib/array/float32] containing values to append prior to computing differences. - **strideA**: stride length for `append`. - **out**: output [`Float32Array`][@stdlib/array/float32]. Must have `N + N1 + N2 - k` elements. @@ -111,7 +111,7 @@ console.log( out ); #### sdiff.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) -Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. +Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -134,9 +134,9 @@ The function has the following additional parameters: - **offsetP**: starting index for `prepend`. - **offsetA**: starting index for `append`. - **offsetOut**: starting index for `out`. -- **offsetW**: starting index of `workspace`. +- **offsetW**: starting index for `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: +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last three elements: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -161,7 +161,8 @@ console.log( out ); ## Notes -- If `N <= 0`, both functions return the output array unchanged. +- When `k <= 1`, the workspace array is unused and thus ignored. +- If `N + N1 + N2 <= 1` or `k >= N + N1 + N2`, both functions return the output array unchanged. @@ -194,11 +195,10 @@ var a = discreteUniform( 2, -100, 100, { console.log( 'Append array: ', a ); var out = new Float32Array( 10 ); - var w = new Float32Array( 13 ); sdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); -console.log( 'Output', out ); +console.log( 'Output: ', out ); ``` @@ -233,9 +233,9 @@ console.log( 'Output', out ); -#### stdlib_strided_sdiff( N, k, \*X, strideX, N1, \*prepend, strideP, N2, \*append, strideA, \*Out, strideOut, \*Workspace, strideW ) +#### stdlib_strided_sdiff( N, k, \*X, strideX, N1, \*Prepend, strideP, N2, \*Append, strideA, \*Out, strideOut, \*Workspace, strideW ) -Calculates the k-th discrete forward differences of a single-precision floating-point strided array. +Calculates the k-th discrete forward difference of a single-precision floating-point strided array. ```c const float x[] = { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f }; @@ -252,27 +252,27 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **k**: `[in] CBLAS_INT` number of times to recursively compute differences. - **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `x`. -- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. -- **prepend**: `[in] float*` array containing values to prepend prior to computing differences. -- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. -- **N2**: `[in] CBLAS_INT` number of elements in `append`. -- **append**: `[in] float*` array containing values to append prior to computing differences. -- **strideA**: `[in] CBLAS_INT` stride length for `append`. -- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - k` elements. -- **strideOut**: `[in] CBLAS_INT` stride length for `out`. -- **Workspace**: `[inout] float*` workspace array. Must have `N + N1 + N2 - 1` elements. -- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **N1**: `[in] CBLAS_INT` number of indexed elements for `Prepend`. +- **Prepend**: `[in] float*` array containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `Prepend`. +- **N2**: `[in] CBLAS_INT` number of indexed elements for `Append`. +- **Append**: `[in] float*` array containing values to append prior to computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `Append`. +- **Out**: `[out] float*` output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `Out`. +- **Workspace**: `[out] float*` workspace array. Must have `N + N1 + N2 - 1` elements. +- **strideW**: `[in] CBLAS_INT` stride length for `Workspace`. ```c -void stdlib_strided_sdiff( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ); +void stdlib_strided_sdiff( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ); ``` -#### stdlib_strided_sdiff_ndarray( N, k, \*X, strideX, offsetX, N1, \*prepend, strideP, offsetP, N2, \*append, strideA, offsetA, \*Out, strideOut, offsetOut, \*Workspace, strideW, offsetW ) +#### stdlib_strided_sdiff_ndarray( N, k, \*X, strideX, offsetX, N1, \*Prepend, strideP, offsetP, N2, \*Append, strideA, offsetA, \*Out, strideOut, offsetOut, \*Workspace, strideW, offsetW ) -Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. +Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. ```c const float x[] = { 2.0f, 4.0f, 6.0f, 8.0f, 10.0f }; @@ -289,25 +289,25 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **k**: `[in] CBLAS_INT` number of times to recursively compute differences. - **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `x`. -- **offsetX**: `[in] CBLAS_INT` starting index for `x`. -- **N1**: `[in] CBLAS_INT` number of elements in `prepend`. -- **prepend**: `[in] float*` array containing values to prepend prior to computing differences. -- **strideP**: `[in] CBLAS_INT` stride length for `prepend`. -- **offsetP**: `[in] CBLAS_INT` starting index for `prepend`. -- **N2**: `[in] CBLAS_INT` number of elements in `append`. -- **append**: `[in] float*` array containing values to append prior to computing differences. -- **strideA**: `[in] CBLAS_INT` stride length for `append`. -- **offsetA**: `[in] CBLAS_INT` starting index for `append`. -- **Out**: `[inout] float*` output array. Must have `N + N1 + N2 - k` elements. -- **strideOut**: `[in] CBLAS_INT` stride length for `out`. -- **offsetOut**: `[in] CBLAS_INT` starting index for `out`. -- **Workspace**: `[inout] float*` workspace array. Must have `N + N1 + N2 - 1` elements. -- **strideW**: `[in] CBLAS_INT` stride length for `workspace`. -- **offsetW**: `[in] CBLAS_INT` starting index for `workspace`. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **N1**: `[in] CBLAS_INT` number of indexed elements for `Prepend`. +- **Prepend**: `[in] float*` array containing values to prepend prior to computing differences. +- **strideP**: `[in] CBLAS_INT` stride length for `Prepend`. +- **offsetP**: `[in] CBLAS_INT` starting index for `Prepend`. +- **N2**: `[in] CBLAS_INT` number of indexed elements for `Append`. +- **Append**: `[in] float*` array containing values to append prior to computing differences. +- **strideA**: `[in] CBLAS_INT` stride length for `Append`. +- **offsetA**: `[in] CBLAS_INT` starting index for `Append`. +- **Out**: `[out] float*` output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: `[in] CBLAS_INT` stride length for `Out`. +- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`. +- **Workspace**: `[out] float*` workspace array. Must have `N + N1 + N2 - 1` elements. +- **strideW**: `[in] CBLAS_INT` stride length for `Workspace`. +- **offsetW**: `[in] CBLAS_INT` starting index for `Workspace`. ```c -void stdlib_strided_sdiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); +void stdlib_strided_sdiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); ``` @@ -336,16 +336,16 @@ int main( void ) { // Create a strided array: const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; - // Define prepend values: + // Define a list of values to prepend: const float p[] = { -1.0f }; - // Define append values: + // Define a list of values to append: const float a[] = { 10.0f }; - // Define output array: + // Define an output array: float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; - // Define workspace: + // Define a workspace: float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // Compute forward differences: diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js index b9d5ad893ff7..2bfa893cd978 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); var format = require( '@stdlib/string/format' ); @@ -61,7 +61,7 @@ function createBenchmark( len ) { N = len; N1 = 1; N2 = 1; - k = 1; // worst case: N + N1 + N2 - 1 + k = 1; ol = N + N1 + N2 - k; x = uniform( N, -100, 100, options ); @@ -83,12 +83,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js index e4df3440af8c..710a0ea1a5a3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.native.js @@ -23,7 +23,7 @@ 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); var format = require( '@stdlib/string/format' ); @@ -66,7 +66,7 @@ function createBenchmark( len ) { N = len; N1 = 1; N2 = 1; - k = 1; // worst case: N + N1 + N2 - 1 + k = 1; ol = N + N1 + N2 - k; x = uniform( N, -100, 100, options ); @@ -88,12 +88,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { sdiff( N, k, x, 1, N1, p, 1, N2, a, 1, o, 1, w, 1 ); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js index a308547d5137..832ea84a8117 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); var format = require( '@stdlib/string/format' ); @@ -61,7 +61,7 @@ function createBenchmark( len ) { N = len; N1 = 1; N2 = 1; - k = 1; // worst case: N + N1 + N2 - 1 + k = 1; ol = N + N1 + N2 - k; x = uniform( N, -100, 100, options ); @@ -83,12 +83,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { sdiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js index ac03c4d98d29..106be6a3e79e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/benchmark.ndarray.native.js @@ -23,7 +23,7 @@ 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); var format = require( '@stdlib/string/format' ); @@ -66,7 +66,7 @@ function createBenchmark( len ) { N = len; N1 = 1; N2 = 1; - k = 1; // worst case: N + N1 + N2 - 1 + k = 1; ol = N + N1 + N2 - k; x = uniform( N, -100, 100, options ); @@ -88,12 +88,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { sdiff( N, k, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 1, 0, w, 1, 0 ); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( o[ i%ol ] ) ) { + if ( isnanf( o[ i%ol ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c index ca14bf52618d..735b761beead 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/benchmark/c/benchmark.length.c @@ -113,7 +113,7 @@ static double benchmark1( int iterations, int len ) { N = len; N1 = 1; N2 = 1; - k = 1; // worst case: N + N1 + N2 - 1 + k = 1; ol = N + N1 + N2 - k; wl = N + N1 + N2 - 1; @@ -185,7 +185,7 @@ static double benchmark2( int iterations, int len ) { N = len; N1 = 1; N2 = 1; - k = 1; // worst case: N + N1 + N2 - 1 + k = 1; ol = N + N1 + N2 - k; wl = N + N1 + N2 - 1; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt index 2a828d16994e..32394ba22a73 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( N, k, x,sx, N1,p,sp, N2,a,sa, out,so, w,sw ) - Calculates the k-th discrete forward differences of a single-precision + Calculates the k-th discrete forward difference of a single-precision floating-point strided array. The `N` and stride parameters determine which elements in the strided arrays @@ -9,7 +9,8 @@ Indexing is relative to the first index. To introduce an offset, use a typed array view. - If `N <= 0`, the function returns the output array unchanged. + If `N + N1 + N2 <= 1` or `k >= N + N1 + N2`, the function returns the + output array unchanged. Parameters ---------- @@ -26,34 +27,34 @@ Stride length for `x`. N1: integer - Number of elements to `prepend`. + Number of indexed elements for `p`. p: Float32Array Array containing values to prepend prior to computing differences. sp: integer - Stride length for `prepend`. + Stride length for `p`. N2: integer - Number of elements to `append`. + Number of indexed elements for `a`. a: Float32Array Array containing values to append prior to computing differences. sa: integer - Stride length for `append`. + Stride length for `a`. out: Float32Array - Output array. + Output array. Must have `N + N1 + N2 - k` indexed elements. so: integer Stride length for `out`. w: Float32Array - Workspace array. + Workspace array. Must have `N + N1 + N2 - 1` indexed elements. sw: integer - Stride length for `workspace`. + Stride length for `w`. Returns ------- @@ -62,7 +63,7 @@ Examples -------- - // Standard Usage: + // Standard usage: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); > var p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); > var a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); @@ -75,8 +76,8 @@ > x = new {{alias:@stdlib/array/float32}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); > p = new {{alias:@stdlib/array/float32}}( [ 1.0 ] ); > a = new {{alias:@stdlib/array/float32}}( [ 11.0 ] ); - > var out = new {{alias:@stdlib/array/float32}}( 4 ); - > var w = new {{alias:@stdlib/array/float32}}( 4 ); + > out = new {{alias:@stdlib/array/float32}}( 4 ); + > w = new {{alias:@stdlib/array/float32}}( 4 ); > {{alias}}( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ) [ 1.0, 4.0, 4.0, 1.0 ] @@ -85,14 +86,14 @@ > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > p = new {{alias:@stdlib/array/float32}}( [ 1.0 ] ); > a = new {{alias:@stdlib/array/float32}}( [ 11.0 ] ); - > var out = new {{alias:@stdlib/array/float32}}( 5 ); - > var w = new {{alias:@stdlib/array/float32}}( 5 ); + > out = new {{alias:@stdlib/array/float32}}( 5 ); + > w = new {{alias:@stdlib/array/float32}}( 5 ); > {{alias}}( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ) [ 3.0, 2.0, 2.0, 2.0, 1.0 ] -{{alias}}.ndarray( N, k, X,sx,ox, N1,p,sp,op, N2,a,sa,oa, Out,so,oo, W,sw,ow ) - Calculates the k-th discrete forward differences of a single-precision +{{alias}}.ndarray( N, k, x,sx,ox, N1, p,sp,op, N2, a,sa,oa, out,so,oo, w,sw,ow ) + Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. While typed array views mandate a view offset based on the underlying @@ -107,7 +108,7 @@ k: integer Number of times to recursively compute differences. - X: Float32Array + x: Float32Array Input array. sx: integer @@ -117,31 +118,31 @@ Starting index for `x`. N1: integer - Number of elements to `prepend`. + Number of indexed elements for `p`. p: Float32Array Array containing values to prepend prior to computing differences. sp: integer - Stride length for `prepend`. + Stride length for `p`. op: integer - Starting index for `prepend`. + Starting index for `p`. N2: integer - Number of elements to `append`. + Number of indexed elements for `a`. a: Float32Array Array containing values to append prior to computing differences. sa: integer - Stride length for `append`. + Stride length for `a`. oa: integer - Starting index for `append`. + Starting index for `a`. - Out: Float32Array - Output array. + out: Float32Array + Output array. Must have `N + N1 + N2 - k` indexed elements. so: integer Stride length for `out`. @@ -149,14 +150,14 @@ oo: integer Starting index for `out`. - W: Float32Array - Workspace array. + w: Float32Array + Workspace array. Must have `N + N1 + N2 - 1` indexed elements. sw: integer - Stride length for `workspace`. + Stride length for `w`. ow: integer - Starting index for `workspace`. + Starting index for `w`. Returns ------- @@ -165,7 +166,7 @@ Examples -------- - // Standard Usage: + // Standard usage: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); > var p = new {{alias:@stdlib/array/float32}}( [ 0.0 ] ); > var a = new {{alias:@stdlib/array/float32}}( [ 3.0 ] ); @@ -185,3 +186,4 @@ See Also -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts index 158d19b6d8b3..d67709119508 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/index.d.ts @@ -25,14 +25,19 @@ interface Routine { /** * Calculates the k-th discrete forward difference of a single-precision floating-point strided array. * + * ## Notes + * + * - The `out` array must have `N + N1 + N2 - k` elements. + * - The `workspace` array must have `N + N1 + N2 - 1` elements. + * * @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 N1 - number of indexed elements for `prepend` * @param prepend - prepend array * @param strideP - stride length for `prepend` - * @param N2 - number of indexed elements of append + * @param N2 - number of indexed elements for `append` * @param append - append array * @param strideA - stride length for `append` * @param out - output array @@ -60,16 +65,21 @@ interface Routine { /** * Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. * + * ## Notes + * + * - The `out` array must have `N + N1 + N2 - k` elements. + * - The `workspace` array must have `N + N1 + N2 - 1` elements. + * * @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 N1 - number of indexed elements for `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 N2 - number of indexed elements for `append` * @param append - append array * @param strideA - stride length for `append` * @param offsetA - starting index for `append` @@ -101,14 +111,19 @@ interface Routine { /** * Calculates the k-th discrete forward difference of a single-precision floating-point strided array. * +* ## Notes +* +* - The `out` array must have `N + N1 + N2 - k` elements. +* - The `workspace` array must have `N + N1 + N2 - 1` elements. +* * @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 N1 - number of indexed elements for `prepend` * @param prepend - prepend array * @param strideP - stride length for `prepend` -* @param N2 - number of indexed elements of append +* @param N2 - number of indexed elements for `append` * @param append - append array * @param strideA - stride length for `append` * @param out - output array diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts index daafa1cd28eb..4639b6f9acd5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/docs/types/test.ts @@ -29,7 +29,7 @@ import sdiff = require( './index' ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff( x.length, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Float32Array + sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Float32Array } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -40,14 +40,14 @@ import sdiff = require( './index' ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff( '10', 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( true, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( false, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( null, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( undefined, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( [], 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( {}, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( ( x: number ): number => x, 1.0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( '10', 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( true, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( false, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( null, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( undefined, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( [], 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( {}, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( ( x: number ): number => x, 1, 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... @@ -70,19 +70,20 @@ import sdiff = require( './index' ); // The compiler throws an error if the function is provided a third argument which is not a Float32Array... { + const x = new Float32Array( 10 ); const p = new Float32Array( 1 ); const a = new Float32Array( 1 ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff( 10, 1, '10', 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, false, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, null, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, undefined, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, [], 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, {}, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError - sdiff( 10, 1, ( x: number ): number => x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, '10', 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, false, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, null, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, undefined, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, [], 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( x.length, 1, {}, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + sdiff( 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... @@ -214,7 +215,7 @@ import sdiff = require( './index' ); const x = new Float32Array( 10 ); const p = new Float32Array( 1 ); const a = new Float32Array( 1 ); - const w = new Float32Array( 11 ); + const w = new Float32Array( 9 ); sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, '10', 1, w, 1 ); // $ExpectError sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, true, 1, w, 1 ); // $ExpectError @@ -249,7 +250,7 @@ import sdiff = require( './index' ); const x = new Float32Array( 10 ); const p = new Float32Array( 1 ); const a = new Float32Array( 1 ); - const out = new Float32Array( 11 ); + const out = new Float32Array( 9 ); sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, '10', 1 ); // $ExpectError sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, true, 1 ); // $ExpectError @@ -301,6 +302,7 @@ import sdiff = require( './index' ); sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError sdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w ); // $ExpectError + sdiff( 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 Float32Array... @@ -311,7 +313,7 @@ import sdiff = require( './index' ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff.ndarray( x.length, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Float32Array + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Float32Array } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... @@ -322,14 +324,14 @@ import sdiff = require( './index' ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff.ndarray( '10', 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( true, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( false, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( null, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( undefined, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( [], 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( {}, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( ( x: number ): number => x, 1.0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( '10', 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( true, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( false, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( null, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( undefined, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( [], 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( {}, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( ( x: number ): number => x, 1, 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... @@ -352,19 +354,20 @@ import sdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... { + const x = new Float32Array( 10 ); const p = new Float32Array( 1 ); const a = new Float32Array( 1 ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff.ndarray( 10, 1, '10', 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, [], 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError - sdiff.ndarray( 10, 1, ( x: number ): number => x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, '10', 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, [], 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.ndarray( x.length, 1, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + sdiff.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... @@ -497,7 +500,7 @@ import sdiff = require( './index' ); const x = new Float32Array( 10 ); const p = new Float32Array( 1 ); const out = new Float32Array( 11 ); - const w = new Float32Array( 11 ); + const w = new Float32Array( 9 ); sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, '10', 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -532,7 +535,7 @@ import sdiff = require( './index' ); const x = new Float32Array( 10 ); const p = new Float32Array( 1 ); const a = new Float32Array( 1 ); - const out = new Float32Array( 11 ); + const out = new Float32Array( 9 ); const w = new Float32Array( 11 ); sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0, w, 1, 0 ); // $ExpectError @@ -641,14 +644,14 @@ import sdiff = require( './index' ); const out = new Float32Array( 11 ); const w = new Float32Array( 11 ); - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, '10' ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, true ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, false ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, null ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, undefined ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, [] ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, {} ); // $ExpectError - sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, ( x: number ): number => x ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, '10' ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, true ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, false ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, null ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, undefined ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, [] ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, {} ); // $ExpectError + sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 0, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... @@ -678,4 +681,5 @@ import sdiff = require( './index' ); sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w ); // $ExpectError sdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1 ); // $ExpectError + sdiff.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/sdiff/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c index 0a17b25467ee..2c4867ed383f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/c/example.c @@ -23,16 +23,16 @@ int main( void ) { // Create a strided array: const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; - // Define prepend values: + // Define a list of values to prepend: const float p[] = { -1.0f }; - // Define append values: + // Define a list of values to append: const float a[] = { 10.0f }; - // Define output array: + // Define the output array: float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; - // Define workspace: + // Define a workspace: float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // Compute forward differences: diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js index c4e79b629048..f2a5a0056b21 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/examples/index.js @@ -38,8 +38,7 @@ var a = discreteUniform( 2, -100, 100, { console.log( 'Append array: ', a ); var out = new Float32Array( 10 ); - var w = new Float32Array( 13 ); sdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 ); -console.log( 'Output', out ); +console.log( 'Output: ', out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/include/stdlib/blas/ext/base/sdiff.h b/lib/node_modules/@stdlib/blas/ext/base/sdiff/include/stdlib/blas/ext/base/sdiff.h index aad3cf66869a..52617d029bee 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/include/stdlib/blas/ext/base/sdiff.h +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/include/stdlib/blas/ext/base/sdiff.h @@ -29,14 +29,14 @@ extern "C" { #endif /** -* Calculates the k-th discrete forward differences of a single-precision floating-point strided array. +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. */ -void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ); +void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ); /** -* Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. */ -void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); +void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ); #ifdef __cplusplus diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/base.js new file mode 100644 index 000000000000..89ada589a97c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/base.js @@ -0,0 +1,151 @@ +/** +* @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'; + +// MAIN // + +/** +* Calculates the forward difference of a single-precision floating-point strided array. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements for `prepend` +* @param {Float32Array} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements for `append` +* @param {Float32Array} append - append array +* @param {integer} strideA - stride length for `append` +* @param {PositiveInteger} offsetA - starting index for `append` +* @param {Float32Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {PositiveInteger} offsetOut - starting index for `out` +* @returns {Float32Array} output array +*/ +function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var total; + var prev; + var curr; + var ix; + var io; + var ip; + var ia; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + // Compute forward differences: + if ( N1 === 0 && N2 === 0 ) { + ix = offsetX; + io = offsetOut; + prev = x[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + return out; + } + // Compute forward differences over the list of prepended values: + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = prepend[ ip ]; + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = prepend[ ip ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = x[ offsetX ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = append[ offsetA ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = x[ offsetX ]; + io = offsetOut; + } else { + prev = append[ offsetA ]; + io = offsetOut; + } + // Compute forward differences over the input array: + 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; + } + } + // Compute forward differences over the list of appended values: + 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; +} + + +// EXPORTS // + +module.exports = base; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js index dd4fbf154b3c..ab8fafd56de0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.js @@ -22,136 +22,8 @@ // MODULES // -var scopy = require( '@stdlib/blas/base/scopy' ); - - -// FUNCTIONS // - -/** -* Calculates the forward difference of a single-precision floating-point strided array using alternative indexing semantics. -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {Float32Array} x - input array -* @param {integer} strideX - stride length for `x` -* @param {PositiveInteger} offsetX - starting index for `x` -* @param {PositiveInteger} N1 - number of indexed elements of prepend -* @param {Float32Array} prepend - prepend array -* @param {integer} strideP - stride length for `prepend` -* @param {PositiveInteger} offsetP - starting index for `prepend` -* @param {PositiveInteger} N2 - number of indexed elements of append -* @param {Float32Array} append - append array -* @param {integer} strideA - stride length for `append` -* @param {PositiveInteger} offsetA - starting index for `append` -* @param {Float32Array} out - output array -* @param {integer} strideOut - stride length for `out` -* @param {PositiveInteger} offsetOut - starting index for `out` -* @returns {Float32Array} output array -*/ -function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { - var total; - var prev; - var curr; - var ix; - var io; - var ip; - var ia; - var i; - - total = N + N1 + N2; - if ( total <= 1 ) { - return out; - } - - if ( N1 === 0 && N2 === 0 ) { - ix = offsetX; - io = offsetOut; - prev = x[ ix ]; - for ( i = 1; i < N; i++ ) { - ix += strideX; - curr = x[ ix ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - } - return out; - } - - // Prepend - if ( N1 > 0 ) { - io = offsetOut; - ip = offsetP; - prev = prepend[ ip ]; - for ( i = 1; i < N1; i++ ) { - ip += strideP; - curr = prepend[ ip ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - } - if ( N > 0 ) { - curr = x[ offsetX ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - } else if ( N2 > 0 ) { - curr = append[ offsetA ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - } - } else if ( N > 0 ) { - prev = x[ offsetX ]; - io = offsetOut; - } else { - prev = append[ offsetA ]; - io = offsetOut; - } - - // x - if ( N > 0 ) { - ix = offsetX; - if ( N1 === 0 ) { - prev = x[ ix ]; - ix += strideX; - for ( i = 1; i < N; i++ ) { - curr = x[ ix ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - ix += strideX; - } - } else { - ix += strideX; - for ( i = 1; i < N; i++ ) { - curr = x[ ix ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - ix += strideX; - } - } - if ( N2 > 0 ) { - curr = append[ offsetA ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - } - } - - // Append - if ( N2 > 0 ) { - ia = offsetA + strideA; - for ( i = 1; i < N2; i++ ) { - curr = append[ ia ]; - out[ io ] = curr - prev; - prev = curr; - io += strideOut; - ia += strideA; - } - } - return out; -} +var scopy = require( '@stdlib/blas/base/scopy' ).ndarray; +var base = require( './base.js' ); // MAIN // @@ -164,11 +36,11 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append * @param {Float32Array} x - input array * @param {integer} strideX - stride length for `x` * @param {PositiveInteger} offsetX - starting index for `x` -* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {PositiveInteger} N1 - number of indexed elements for `prepend` * @param {Float32Array} prepend - prepend array * @param {integer} strideP - stride length for `prepend` * @param {PositiveInteger} offsetP - starting index for `prepend` -* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {PositiveInteger} N2 - number of indexed elements for `append` * @param {Float32Array} append - append array * @param {integer} strideA - stride length for `append` * @param {PositiveInteger} offsetA - starting index for `append` @@ -201,44 +73,43 @@ function sdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, ap var i; total = N + N1 + N2; - if ( total <= 1 ) { - return out; - } - // If k >= total number of elements, the k-th forward difference results in an empty array, so this function is a no-op. - if ( k >= total ) { + // If `k` is greater than or equal to the total number of elements, the k-th forward difference results in an empty array, so this function is a no-op... + if ( total <= 1 || k >= total ) { return out; } - + // If `k` is equal to zero, there are no differences to compute, so we merely copy the various arrays into the output array... if ( k === 0 ) { // Copy `prepend` into output array: - scopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + scopy( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); // Copy `x` into output array: io = offsetOut + ( N1 * strideOut ); - scopy.ndarray( N, x, strideX, offsetX, out, strideOut, io ); + scopy( N, x, strideX, offsetX, out, strideOut, io ); // Copy `append` into output array: io = offsetOut + ( ( N1 + N ) * strideOut ); - scopy.ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + scopy( N2, append, strideA, offsetA, out, strideOut, io ); return out; } - + // If `k` is equal to one, we can compute the forward difference while writing directly to the output array... if ( k === 1 ) { base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ); return out; } - + // Compute the first forward difference: base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, workspace, strideW, offsetW ); + // Recursively compute the next forward differences... n = total - 1; - for ( i = 1; i < k - 1; i++ ) { + 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; } - + // For the last forward difference, ensure that results are written to the output array: base( n, workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, out, strideOut, offsetOut ); + return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js index 113c33ce6552..8dfc43b4b815 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/ndarray.native.js @@ -28,18 +28,18 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. * * @param {PositiveInteger} N - number of indexed elements * @param {PositiveInteger} k - number of times to recursively compute differences * @param {Float32Array} x - input array * @param {integer} strideX - stride length for `x` * @param {PositiveInteger} offsetX - starting index for `x` -* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {PositiveInteger} N1 - number of indexed elements for `prepend` * @param {Float32Array} prepend - prepend array * @param {integer} strideP - stride length for `prepend` * @param {PositiveInteger} offsetP - starting index for `prepend` -* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {PositiveInteger} N2 - number of indexed elements for `append` * @param {Float32Array} append - append array * @param {integer} strideA - stride length for `append` * @param {PositiveInteger} offsetA - starting index for `append` diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js index 2792282d0f0f..82a1bcc44635 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.js @@ -35,10 +35,10 @@ var ndarray = require( './ndarray.js' ); * @param {PositiveInteger} k - number of times to recursively compute differences * @param {Float32Array} x - input array * @param {integer} strideX - stride length for `x` -* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {PositiveInteger} N1 - number of indexed elements for `prepend` * @param {Float32Array} prepend - prepend array * @param {integer} strideP - stride length for `prepend` -* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {PositiveInteger} N2 - number of indexed elements for `append` * @param {Float32Array} append - append array * @param {integer} strideA - stride length for `append` * @param {Float32Array} out - output array diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js index cb70f8cf692c..e025db9626d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/lib/sdiff.native.js @@ -34,10 +34,10 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} k - number of times to recursively compute differences * @param {Float32Array} x - input array * @param {integer} strideX - stride length for `x` -* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {PositiveInteger} N1 - number of indexed elements for `prepend` * @param {Float32Array} prepend - prepend array * @param {integer} strideP - stride length for `prepend` -* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {PositiveInteger} N2 - number of indexed elements for `append` * @param {Float32Array} append - append array * @param {integer} strideA - stride length for `append` * @param {Float32Array} out - output array diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c index 2b7f1dee233e..812efa08db47 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/addon.c @@ -43,11 +43,11 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 11 ); STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 13 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 5 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Prepend, N1, strideP, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Append, N2, strideA, argv, 8 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-k, strideOut, argv, 10 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Workspace, N+N1+N2-1, strideW, argv, 12 ); - API_SUFFIX(stdlib_strided_sdiff)( N, k, X, strideX, N1, prepend, strideP, N2, append, strideA, Out, strideOut, Workspace, strideW ); + API_SUFFIX(stdlib_strided_sdiff)( N, k, X, strideX, N1, Prepend, strideP, N2, Append, strideA, Out, strideOut, Workspace, strideW ); return NULL; } @@ -75,11 +75,11 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideW, argv, 17 ); STDLIB_NAPI_ARGV_INT64( env, offsetW, argv, 18 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, prepend, N1, strideP, argv, 6 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, append, N2, strideA, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Prepend, N1, strideP, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Append, N2, strideA, argv, 10 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Out, N+N1+N2-k, strideOut, argv, 13 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Workspace, N+N1+N2-1, strideW, argv, 16 ); - API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut, Workspace, strideW, offsetW ); + API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, offsetX, N1, Prepend, strideP, offsetP, N2, Append, strideA, offsetA, Out, strideOut, offsetOut, Workspace, strideW, offsetW ); return NULL; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c index d265a72a2f28..8cd669d7f979 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/src/main.c @@ -17,62 +17,35 @@ */ #include "stdlib/blas/ext/base/sdiff.h" -#include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" #include "stdlib/blas/base/scopy.h" - -/** -* Calculates the k-th discrete forward differences of a single-precision floating-point strided array. -* -* @param N number of indexed elements -* @param k number of times to recursively compute differences -* @param X input array -* @param strideX stride length for X -* @param N1 number of indexed elements of prepend -* @param prepend prepend array -* @param strideP stride length for prepend -* @param N2 number of indexed elements of append -* @param append append array -* @param strideA stride length for append -* @param Out Output array -* @param strideOut stride length for Out -* @param Workspace Workspace array -* @param strideW stride length for Workspace -*/ -void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ) { - CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - CBLAS_INT op = stdlib_strided_stride2offset( N1, strideP ); - CBLAS_INT oa = stdlib_strided_stride2offset( N2, strideA ); - CBLAS_INT oo = stdlib_strided_stride2offset( N+N1+N2-k, strideOut ); - CBLAS_INT ow = stdlib_strided_stride2offset( N+N1+N2-1, strideW ); - API_SUFFIX(stdlib_strided_sdiff_ndarray)( N, k, X, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, Out, strideOut, oo, Workspace, strideW, ow ); -} +#include "stdlib/blas/base/shared.h" /** * Calculates the forward difference of a single-precision floating-point strided array using alternative indexing semantics. * -* @param N number of indexed elements -* @param X input array -* @param strideX stride length for X -* @param offsetX starting index for X -* @param N1 number of indexed elements of prepend -* @param prepend prepend array -* @param strideP stride length for prepend -* @param offsetP starting index for prepend -* @param N2 number of indexed elements of append -* @param append append array -* @param strideA stride length for append -* @param offsetA starting index for append -* @param Out Output array -* @param strideOut stride length for Out -* @param offsetOut starting index for Out +* @param N number of indexed elements +* @param X input array +* @param strideX stride length for X +* @param offsetX starting index for X +* @param N1 number of indexed elements for Prepend +* @param Prepend prepend array +* @param strideP stride length for Prepend +* @param offsetP starting index for Prepend +* @param N2 number of indexed elements for Append +* @param Append append array +* @param strideA stride length for Append +* @param offsetA starting index for Append +* @param Out output array +* @param strideOut stride length for Out +* @param offsetOut starting index for Out */ -static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { +static void stdlib_strided_internal_sdiff_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ) { CBLAS_INT total; CBLAS_INT ix; - CBLAS_INT io; CBLAS_INT ip; CBLAS_INT ia; + CBLAS_INT io; CBLAS_INT i; float prev; float curr; @@ -81,7 +54,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X if ( total <= 1 ) { return; } - + // Calculate the forward difference over the input array... if ( N1 == 0 && N2 == 0 ) { ix = offsetX; io = offsetOut; @@ -95,15 +68,14 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X } return; } - - // Prepend + // Calculate the forward difference over the list of prepended values... if ( N1 > 0 ) { io = offsetOut; ip = offsetP; - prev = prepend[ ip ]; + prev = Prepend[ ip ]; for ( i = 1; i < N1; i++ ) { ip += strideP; - curr = prepend[ ip ]; + curr = Prepend[ ip ]; Out[ io ] = curr - prev; prev = curr; io += strideOut; @@ -114,7 +86,7 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X prev = curr; io += strideOut; } else if ( N2 > 0 ) { - curr = append[ offsetA ]; + curr = Append[ offsetA ]; Out[ io ] = curr - prev; prev = curr; io += strideOut; @@ -123,11 +95,10 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X prev = X[ offsetX ]; io = offsetOut; } else { - prev = append[ offsetA ]; + prev = Append[ offsetA ]; io = offsetOut; } - - // X + // Calculate the forward difference over the input array... if ( N > 0 ) { ix = offsetX; if ( N1 == 0 ) { @@ -151,85 +122,118 @@ static void stdlib_strided_base_sdiff_ndarray( const CBLAS_INT N, const float *X } } if ( N2 > 0 ) { - curr = append[ offsetA ]; + curr = Append[ offsetA ]; Out[ io ] = curr - prev; prev = curr; io += strideOut; } } - - // Append + // Calculate the forward difference over the list of appended values... if ( N2 > 0 ) { ia = offsetA + strideA; for ( i = 1; i < N2; i++ ) { - curr = append[ ia ]; + curr = Append[ ia ]; Out[ io ] = curr - prev; prev = curr; io += strideOut; ia += strideA; } } + return; +} + +/** +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array. +* +* @param N number of indexed elements +* @param k number of times to recursively compute differences +* @param X input array +* @param strideX stride length for X +* @param N1 number of indexed elements for Prepend +* @param Prepend prepend array +* @param strideP stride length for Prepend +* @param N2 number of indexed elements for Append +* @param Append append array +* @param strideA stride length for Append +* @param Out output array +* @param strideOut stride length for Out +* @param Workspace workspace array +* @param strideW stride length for workspace +*/ +void API_SUFFIX(stdlib_strided_sdiff)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, float *Out, const CBLAS_INT strideOut, float *Workspace, const CBLAS_INT strideW ) { + 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_sdiff_ndarray)( N, k, X, strideX, ox, N1, Prepend, strideP, op, N2, Append, strideA, oa, Out, strideOut, oo, Workspace, strideW, ow ); } /** -* Calculates the k-th discrete forward differences of a single-precision floating-point strided array using alternative indexing semantics. +* Calculates the k-th discrete forward difference of a single-precision floating-point strided array using alternative indexing semantics. * -* @param N number of indexed elements -* @param k number of times to recursively compute differences -* @param X input array -* @param strideX stride length for X -* @param offsetX starting index for X -* @param N1 number of indexed elements of prepend -* @param prepend prepend array -* @param strideP stride length for prepend -* @param offsetP starting index for prepend -* @param N2 number of indexed elements of append -* @param append append array -* @param strideA stride length for append -* @param offsetA starting index for append -* @param Out Output array -* @param strideOut stride length for Out -* @param offsetOut starting index for Out -* @param Workspace Workspace array -* @param strideW stride length for Workspace -* @param offsetW starting index for Workspace +* @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 for Prepend +* @param Prepend prepend array +* @param strideP stride length for Prepend +* @param offsetP starting index for Prepend +* @param N2 number of indexed elements for Append +* @param Append append array +* @param strideA stride length for Append +* @param offsetA starting index for Append +* @param Out output array +* @param strideOut stride length for Out +* @param offsetOut starting index for Out +* @param Workspace workspace array +* @param strideW stride length for Workspace +* @param offsetW starting index for Workspace */ -void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { +void API_SUFFIX(stdlib_strided_sdiff_ndarray)( const CBLAS_INT N, const CBLAS_INT k, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const float *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const float *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, float *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, float *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW ) { CBLAS_INT total; CBLAS_INT io; CBLAS_INT n; CBLAS_INT i; total = N + N1 + N2; - if ( total <= 1 ) { - return; - } - if ( k >= total ) { + + // If k >= total number of elements, the k-th forward difference results in an empty array, so this function is a no-op... + if ( total <= 1 || k >= total ) { return; } + // If `k` is equal to zero, there are no differences to compute, so we merely copy the various arrays into the output array... if ( k == 0 ) { - // Copy `prepend` into Output array: - c_scopy_ndarray( N1, prepend, strideP, offsetP, Out, strideOut, offsetOut ); + // Copy `Prepend` into output array: + c_scopy_ndarray( N1, Prepend, strideP, offsetP, Out, strideOut, offsetOut ); - // Copy `X` into Output array: + // Copy `X` into output array: io = offsetOut + ( N1 * strideOut ); c_scopy_ndarray( N, X, strideX, offsetX, Out, strideOut, io ); - // Copy `append` into Output array: + // Copy `Append` into output array: io = offsetOut + ( ( N1 + N ) * strideOut ); - c_scopy_ndarray( N2, append, strideA, offsetA, Out, strideOut, io ); + c_scopy_ndarray( N2, Append, strideA, offsetA, Out, strideOut, io ); + return; } + // If `k` is equal to one, we can compute the forward difference while writing directly to the output array... if ( k == 1 ) { - stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Out, strideOut, offsetOut ); + stdlib_strided_internal_sdiff_ndarray( N, X, strideX, offsetX, N1, Prepend, strideP, offsetP, N2, Append, strideA, offsetA, Out, strideOut, offsetOut ); return; } - stdlib_strided_base_sdiff_ndarray( N, X, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, Workspace, strideW, offsetW ); + // Compute the first forward difference: + stdlib_strided_internal_sdiff_ndarray( N, X, strideX, offsetX, N1, Prepend, strideP, offsetP, N2, Append, strideA, offsetA, Workspace, strideW, offsetW ); + // Recursively compute the next forward differences... n = total - 1; for ( i = 1; i < k - 1; i++ ) { - stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Workspace, strideW, offsetW ); + stdlib_strided_internal_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, Prepend, strideP, offsetP, 0, Append, strideA, offsetA, Workspace, strideW, offsetW ); n -= 1; } - stdlib_strided_base_sdiff_ndarray( n, Workspace, strideW, offsetW, 0, prepend, strideP, offsetP, 0, append, strideA, offsetA, Out, strideOut, offsetOut ); + // For the last forward difference, ensure that results are written to the output array: + stdlib_strided_internal_sdiff_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/sdiff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js index 2baa802ca7f0..a179876ed699 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.js @@ -21,9 +21,18 @@ // MODULES // var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); var sdiff = require( './../lib' ); +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -32,7 +41,42 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'attached to the main export is an `ndarray` method', function test( t ) { - t.strictEqual( typeof sdiff.ndarray, 'function', 'has method' ); +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof sdiff.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 sdiff = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sdiff, 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 sdiff; + var main; + + main = require( './../lib/sdiff.js' ); + + sdiff = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sdiff, main, 'returns expected value' ); t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js index 4b47fab22dbd..12ae8ae0e3d3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdiff/test/test.ndarray.js @@ -129,7 +129,6 @@ tape( 'the function returns the output array unchanged for trivial cases', funct expected = new Float32Array( [ 0.0, 0.0 ] ); t.deepEqual( out, expected, 'returns expected value' ); - // Single element (total <= 1 in base): x = new Float32Array( [ 5.0 ] ); p = new Float32Array( 0 ); a = new Float32Array( 0 );