From 1b26f50030a48a2f60bff01e852d85033213bcee Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 13 Mar 2026 02:31:38 +0500 Subject: [PATCH 1/4] feat: add blas/ext/base/gcopy --- .../@stdlib/blas/ext/base/gdiff/README.md | 220 ++++++ .../ext/base/gdiff/benchmark/benchmark.js | 130 ++++ .../base/gdiff/benchmark/benchmark.ndarray.js | 130 ++++ .../@stdlib/blas/ext/base/gdiff/docs/repl.txt | 186 +++++ .../blas/ext/base/gdiff/docs/types/index.d.ts | 149 ++++ .../blas/ext/base/gdiff/docs/types/test.ts | 663 ++++++++++++++++++ .../blas/ext/base/gdiff/examples/index.js | 45 ++ .../blas/ext/base/gdiff/lib/accessors.js | 274 ++++++++ .../@stdlib/blas/ext/base/gdiff/lib/gdiff.js | 75 ++ .../@stdlib/blas/ext/base/gdiff/lib/index.js | 64 ++ .../@stdlib/blas/ext/base/gdiff/lib/main.js | 35 + .../blas/ext/base/gdiff/lib/ndarray.js | 263 +++++++ .../@stdlib/blas/ext/base/gdiff/package.json | 65 ++ .../blas/ext/base/gdiff/test/test.gdiff.js | 532 ++++++++++++++ .../@stdlib/blas/ext/base/gdiff/test/test.js | 38 + .../blas/ext/base/gdiff/test/test.ndarray.js | 520 ++++++++++++++ 16 files changed, 3389 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.gdiff.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md new file mode 100644 index 000000000000..db646241ff28 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md @@ -0,0 +1,220 @@ + + +# gdiff + +> Calculate the k-th discrete forward difference of a strided array. + +
+ +## Usage + +```javascript +var gdiff = require( '@stdlib/blas/ext/base/gdiff' ); +``` + + + +#### gdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) + +Calculates the k-th discrete forward differences of a strided array. + +```javascript +var x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; +var p = [ 1.0 ]; +var a = [ 11.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( 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 array. +- **strideX**: stride length for `x`. +- **N1**: number of elements to `prepend`. +- **prepend**: array containing values to prepend prior to computing differences. +- **strideP**: stride length for `prepend`. +- **N2**: number of elements to `append`. +- **append**: array containing values to append prior to computing differences. +- **strideA**: stride length for `append`. +- **out**: output array. Must have `N + N1 + N2 - k` elements. +- **strideOut**: stride length for `out`. +- **workspace**: workspace array. 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 compute differences of every other element: + +```javascript +var x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; +var p = [ 1.0 ]; +var a = [ 11.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0 ]; + +gdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// => [ 1.0, 4.0, 4.0, 1.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var p = [ 1.0 ]; +var a = [ 11.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gdiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + +console.log( out ); +// => [ 3.0, 2.0, 2.0, 2.0, 1.0 ] +``` + + + +#### gdiff.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 strided array using alternative indexing semantics. + +```javascript +var x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; +var p = [ 1.0 ]; +var a = [ 11.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + +console.log( 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 x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; +var p = [ 1.0 ]; +var a = [ 11.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; +var w = [ 0.0, 0.0, 0.0, 0.0 ]; + +gdiff.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 ); +// => [ 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 zeros = require( '@stdlib/array/zeros' ); +var gdiff = require( '@stdlib/blas/ext/base/gdiff' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'generic' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'generic' +}); +console.log( 'Append array: ', a ); + +var out = zeros( 10, 'generic' ); + +var w = zeros( 13, 'generic' ); + +gdiff( 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/gdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js new file mode 100644 index 000000000000..6458121b3c8b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js @@ -0,0 +1,130 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gdiff = require( './../lib/gdiff.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// 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; + var i; + + 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 = []; + for ( i = 0; i < N+N1+N2-1; i++ ) { + w.push( 0.0 ); + } + o = []; + for ( i = 0; i < ol; i++ ) { + o.push( 0.0 ); + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + gdiff( 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/gdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..5457037926bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js @@ -0,0 +1,130 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gdiff = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// 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; + var i; + + 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 = []; + for ( i = 0; i < N+N1+N2-1; i++ ) { + w.push( 0.0 ); + } + o = []; + for ( i = 0; i < ol; i++ ) { + o.push( 0.0 ); + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + gdiff( 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/gdiff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/repl.txt new file mode 100644 index 000000000000..548531155a77 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/repl.txt @@ -0,0 +1,186 @@ + +{{alias}}( N, k, x,sx, N1,p,sp, N2,a,sa, out,so, w,sw ) + Calculates the k-th discrete forward differences of a 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: Array|TypedArray + Input array. + + sx: integer + Stride length for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Array|TypedArray + Array containing values to prepend prior to computing differences. + + sp: integer + Stride length for `prepend`. + + N2: integer + Number of elements to `append`. + + a: Array|TypedArray + Array containing values to append prior to computing differences. + + sa: integer + Stride length for `append`. + + out: Array|TypedArray + Output array. + + so: integer + Stride length for `out`. + + w: Array|TypedArray + Workspace array. + + sw: integer + Stride length for `workspace`. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > var p = [ 0.0 ]; + > var a = [ 3.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > var w = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{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 = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + > p = [ 1.0 ]; + > a = [ 11.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0 ]; + > w = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ) + [ 1.0, 4.0, 4.0, 1.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > p = [ 1.0 ]; + > a = [ 11.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{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 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: Array|TypedArray + Input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + N1: integer + Number of elements to `prepend`. + + p: Array|TypedArray + 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: Array|TypedArray + Array containing values to append prior to computing differences. + + sa: integer + Stride length for `append`. + + oa: integer + Starting index for `append`. + + out: Array|TypedArray + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + w: Array|TypedArray + Workspace array. + + sw: integer + Stride length for `workspace`. + + ow: integer + Starting index for `workspace`. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > var p = [ 0.0 ]; + > var a = [ 3.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > var w = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{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 = [ 1.0, -2.0, 2.0 ]; + > p = [ 0.0 ]; + > a = [ 3.0 ]; + > out = [ 0.0, 0.0, 0.0 ]; + > w = [ 0.0, 0.0, 0.0 ]; + > {{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/gdiff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts new file mode 100644 index 000000000000..ac12b28d94e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts @@ -0,0 +1,149 @@ +/* +* @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 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Interface describing `gdiff`. +*/ +interface Routine { + /** + * Calculates the k-th discrete forward difference of a 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 x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; + * var p = [ 1.0 ]; + * var a = [ 22.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + * + * console.log( out ); + * // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ( N: number, k: number, x: Collection, strideX: number, N1: number, prepend: Collection, strideP: number, N2: number, append: Collection, strideA: number, out: Collection, strideOut: number, workspace: Collection, strideW: number ): Collection; + + /** + * Calculates the k-th discrete forward difference of a 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 x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; + * var p = [ 1.0 ]; + * var a = [ 22.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + * + * console.log( out ); + * // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] + */ + ndarray( N: number, k: number, x: Collection, strideX: number, offsetX: number, N1: number, prepend: Collection, strideP: number, offsetP: number, N2: number, append: Collection, strideA: number, offsetA: number, out: Collection, strideOut: number, offsetOut: number, workspace: Collection, strideW: number, offsetW: number ): Collection; +} + +/** +* Calculates the k-th discrete forward difference of a 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 x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; +* var p = [ 1.0 ]; +* var a = [ 22.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; +* var p = [ 1.0 ]; +* var a = [ 22.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +declare var gdiff: Routine; + + +// EXPORTS // + +export = gdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts new file mode 100644 index 000000000000..84cf244be0ce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts @@ -0,0 +1,663 @@ +/* +* @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 gdiff = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Collection +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( '10', 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( true, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( false, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( null, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( undefined, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( [], 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( {}, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( ( 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... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, '10', x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, true, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, false, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, null, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, undefined, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, [], x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, {}, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 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 collection... +{ + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 1, 10, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 5, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 5, 1, false, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 5, 1, null, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 5, 1, undefined, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 5, 1, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, '10', 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, true, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, false, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, null, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, undefined, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, [], 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, {}, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, '10', p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, true, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, false, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, null, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, undefined, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, [], p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, {}, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, 10, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, true, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, false, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, null, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, undefined, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, '10', 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, true, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, false, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, null, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, undefined, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, [], 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, {}, 1, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, '10', a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, true, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, false, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, null, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, undefined, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, [], a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, {}, a, 1, out, 1, w, 1 ); // $ExpectError + gdiff( 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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, 10, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, true, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, false, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, null, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, undefined, 1, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, '10', out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, true, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, false, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, null, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, undefined, out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, [], out, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, {}, out, 1, w, 1 ); // $ExpectError + gdiff( 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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, 10, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, true, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, false, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, null, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, undefined, 1, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, {}, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, '10', w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, true, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, false, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, null, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, undefined, w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, [], w, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, {}, w, 1 ); // $ExpectError + gdiff( 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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, 10, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, true, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, false, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, null, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, undefined, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourteenth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, '10' ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, true ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, false ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, null ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, undefined ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, [] ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, {} ); // $ExpectError + gdiff( 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff(); // $ExpectError + gdiff( x.length ); // $ExpectError + gdiff( x.length, 1 ); // $ExpectError + gdiff( x.length, 1, x ); // $ExpectError + gdiff( x.length, 1, x, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w ); // $ExpectError + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Collection +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( '10', 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( true, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( false, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( null, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( undefined, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( [], 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( {}, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( ( x: number ): number => x, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, false, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, null, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, undefined, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, [], x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, {}, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 collection... +{ + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( 5, 1, 10, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( 5, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( 5, 1, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( 5, 1, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( 5, 1, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( 5, 1, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, false, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, null, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, undefined, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, [], 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, {}, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, false, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, null, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, undefined, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, [], 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, {}, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, false, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, null, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, undefined, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, [], p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, {}, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, 10, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, false, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, null, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, undefined, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, false, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, null, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, undefined, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, [], 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, {}, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, '10', 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, true, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, false, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, null, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, undefined, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, [], 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, {}, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, false, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, null, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, undefined, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, [], a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, {}, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, 10, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, false, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, null, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, undefined, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, false, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, null, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, undefined, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, [], 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, {}, 0, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, false, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, null, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, undefined, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, [], out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, {}, out, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, 10, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, false, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, null, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, undefined, 1, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, {}, 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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, false, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, null, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, undefined, 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, [], 0, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, {}, 0, w, 1, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10', w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, false, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, null, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, undefined, w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, [], w, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, {}, w, 1, 0 ); // $ExpectError + gdiff.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 collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, 10, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, true, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, false, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, null, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, undefined, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighteenth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, '10', 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, true, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, false, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, null, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, undefined, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, [], 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, {}, 0 ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, '10' ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, true ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, false ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, null ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, undefined ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, [] ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, {} ); // $ExpectError + gdiff.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 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 0.0 ]; + const a = [ 6.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff.ndarray(); // $ExpectError + gdiff.ndarray( x.length ); // $ExpectError + gdiff.ndarray( x.length, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1 ); // $ExpectError + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js new file mode 100644 index 000000000000..5eca2464bbc9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/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 zeros = require( '@stdlib/array/zeros' ); +var gdiff = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( 'Input array: ', x ); + +var p = discreteUniform( 2, -100, 100, { + 'dtype': 'generic' +}); +console.log( 'Prepend array: ', p ); + +var a = discreteUniform( 2, -100, 100, { + 'dtype': 'generic' +}); +console.log( 'Append array: ', a ); + +var out = zeros( 10, 'generic' ); + +var w = zeros( 13, 'generic' ); + +gdiff( 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/gdiff/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/accessors.js new file mode 100644 index 000000000000..1df8dc9f9ec4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/accessors.js @@ -0,0 +1,274 @@ +/** +* @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 gcopy = require( '@stdlib/blas/base/gcopy' ); + + +// FUNCTIONS // + +/** +* Calculates the forward difference of a strided array using alternative indexing semantics and accessor arrays. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {Object} prepend - prepend array object +* @param {Collection} prepend.data - prepend array data +* @param {Array} prepend.accessors - array element accessors +* @param {integer} strideP - stride length for `prepend` +* @param {NonNegativeInteger} offsetP - starting index for `prepend` +* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {Object} append - append array object +* @param {Collection} append.data - append array data +* @param {Array} append.accessors - array element accessors +* @param {integer} strideA - stride length for `append` +* @param {NonNegativeInteger} offsetA - starting index for `append` +* @param {Object} out - output array object +* @param {Collection} out.data - output array data +* @param {Array} out.accessors - array element accessors +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Object} output array object +*/ +function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var total; + var xget; + var pget; + var aget; + var oset; + var xbuf; + var pbuf; + var abuf; + var obuf; + var prev; + var curr; + var ix; + var io; + var ip; + var ia; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + // Cache references to array data and accessors: + xbuf = x.data; + xget = x.accessors[ 0 ]; + pbuf = prepend.data; + pget = prepend.accessors[ 0 ]; + abuf = append.data; + aget = append.accessors[ 0 ]; + obuf = out.data; + oset = out.accessors[ 1 ]; + + if ( N1 === 0 && N2 === 0 ) { + ix = offsetX; + io = offsetOut; + prev = xget( xbuf, ix ); + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = xget( xbuf, ix ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + } + return out; + } + + // Prepend + if ( N1 > 0 ) { + io = offsetOut; + ip = offsetP; + prev = pget( pbuf, ip ); + for ( i = 1; i < N1; i++ ) { + ip += strideP; + curr = pget( pbuf, ip ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + } + if ( N > 0 ) { + curr = xget( xbuf, offsetX ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + } else if ( N2 > 0 ) { + curr = aget( abuf, offsetA ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + } + } else if ( N > 0 ) { + prev = xget( xbuf, offsetX ); + io = offsetOut; + } else { + prev = aget( abuf, offsetA ); + io = offsetOut; + } + + // x + if ( N > 0 ) { + ix = offsetX; + if ( N1 === 0 ) { + prev = xget( xbuf, ix ); + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = xget( xbuf, ix ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + ix += strideX; + } + } else { + ix += strideX; + for ( i = 1; i < N; i++ ) { + curr = xget( xbuf, ix ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + ix += strideX; + } + } + if ( N2 > 0 ) { + curr = aget( abuf, offsetA ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + } + } + + // Append + if ( N2 > 0 ) { + ia = offsetA + strideA; + for ( i = 1; i < N2; i++ ) { + curr = aget( abuf, ia ); + oset( obuf, io, curr - prev ); + prev = curr; + io += strideOut; + ia += strideA; + } + } + return out; +} + + +// MAIN // + +/** +* Calculates the k-th discrete forward difference of a strided array using alternative indexing semantics and accessor arrays. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {Object} prepend - prepend array object +* @param {Collection} prepend.data - prepend array data +* @param {Array} prepend.accessors - array element accessors +* @param {integer} strideP - stride length for `prepend` +* @param {NonNegativeInteger} offsetP - starting index for `prepend` +* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {Object} append - append array object +* @param {Collection} append.data - append array data +* @param {Array} append.accessors - array element accessors +* @param {integer} strideA - stride length for `append` +* @param {NonNegativeInteger} offsetA - starting index for `append` +* @param {Object} out - output array object +* @param {Collection} out.data - output array data +* @param {Array} out.accessors - array element accessors +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @param {Object} workspace - workspace array object +* @param {Collection} workspace.data - workspace array data +* @param {Array} workspace.accessors - array element accessors +* @param {integer} strideW - stride length for `workspace` +* @param {NonNegativeInteger} offsetW - starting index for `workspace` +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 4.0, 7.0, 11.0, 16.0 ] ); +* var p = toAccessorArray( [ 1.0 ] ); +* var a = toAccessorArray( [ 22.0 ] ); +* var out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* var w = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* gdiff( 5, 2, arraylike2object( x ), 1, 0, 1, arraylike2object( p ), 1, 0, 1, arraylike2object( a ), 1, 0, arraylike2object( out ), 1, 0, arraylike2object( w ), 1, 0 ); +* +* var o = out.get( 0 ); +* // returns 1.0 +*/ +function gdiff( 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 ( k === 0 ) { + // Copy `prepend` into output array: + gcopy.ndarray( N1, prepend.data, strideP, offsetP, out.data, strideOut, offsetOut ); + + // Copy `x` into output array: + io = offsetOut + ( N1 * strideOut ); + gcopy.ndarray( N, x.data, strideX, offsetX, out.data, strideOut, io ); + + // Copy `append` into output array: + io = offsetOut + ( ( N1 + N ) * strideOut ); + gcopy.ndarray( N2, append.data, strideA, offsetA, out.data, 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 = gdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js new file mode 100644 index 000000000000..13e0802dff12 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js @@ -0,0 +1,75 @@ +/** +* @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 strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NumericArray} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NumericArray} append - append array +* @param {integer} strideA - stride length for `append` +* @param {NumericArray} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NumericArray} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @returns {NumericArray} output array +* +* @example +* var x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; +* var p = [ 1.0 ]; +* var a = [ 22.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function gdiff( 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 = gdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/index.js new file mode 100644 index 000000000000..ced6881ce5ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/index.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Calculate the k-th discrete forward difference of a strided array. +* +* @module @stdlib/blas/ext/base/gdiff +* +* @example +* var gdiff = require( '@stdlib/blas/ext/base/gdiff' ); +* +* var x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; +* var p = [ 1.0 ]; +* var a = [ 22.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var gdiff = require( '@stdlib/blas/ext/base/gdiff' ); +* +* var x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; +* var p = [ 1.0 ]; +* var a = [ 22.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gdiff.ndarray( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/main.js new file mode 100644 index 000000000000..04e1796929b4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/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 gdiff = require( './gdiff.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( gdiff, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = gdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js new file mode 100644 index 000000000000..a09a8c5ec972 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js @@ -0,0 +1,263 @@ +/** +* @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 gcopy = require( '@stdlib/blas/base/gcopy' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// FUNCTIONS // + +/** +* Calculates the forward difference of a strided array using alternative indexing semantics. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NumericArray} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {NonNegativeInteger} offsetP - starting index for `prepend` +* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NumericArray} append - append array +* @param {integer} strideA - stride length for `append` +* @param {NonNegativeInteger} offsetA - starting index for `append` +* @param {NumericArray} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {NumericArray} 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 strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {PositiveInteger} k - number of times to recursively compute differences +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NumericArray} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {NonNegativeInteger} offsetP - starting index for `prepend` +* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NumericArray} append - append array +* @param {integer} strideA - stride length for `append` +* @param {NonNegativeInteger} offsetA - starting index for `append` +* @param {NumericArray} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @param {NumericArray} workspace - workspace array +* @param {integer} strideW - stride length for `workspace` +* @param {NonNegativeInteger} offsetW - starting index for `workspace` +* @returns {NumericArray} output array +* +* @example +* var x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; +* var p = [ 1.0 ]; +* var a = [ 22.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +*/ +function gdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW ) { + var total; + var ox; + var op; + var oa; + var oo; + var ow; + 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; + } + + ox = arraylike2object( x ); + op = arraylike2object( prepend ); + oa = arraylike2object( append ); + oo = arraylike2object( out ); + ow = arraylike2object( workspace ); + if ( ox.accessorProtocol || op.accessorProtocol || oa.accessorProtocol || oo.accessorProtocol || ow.accessorProtocol ) { + accessors( N, k, ox, strideX, offsetX, N1, op, strideP, offsetP, N2, oa, strideA, offsetA, oo, strideOut, offsetOut, ow, strideW, offsetW ); + return oo.data; + } + + if ( k === 0 ) { + // Copy `prepend` into output array: + gcopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + + // Copy `x` into output array: + io = offsetOut + ( N1 * strideOut ); + gcopy.ndarray( N, x, strideX, offsetX, out, strideOut, io ); + + // Copy `append` into output array: + io = offsetOut + ( ( N1 + N ) * strideOut ); + gcopy.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 = gdiff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/package.json b/lib/node_modules/@stdlib/blas/ext/base/gdiff/package.json new file mode 100644 index 000000000000..1b6684bf15e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/gdiff", + "version": "0.0.0", + "description": "Calculate the k-th discrete forward difference of a 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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "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" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.gdiff.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.gdiff.js new file mode 100644 index 000000000000..a5260b38dcc0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.gdiff.js @@ -0,0 +1,532 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gdiff = require( './../lib/gdiff.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gdiff, '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 = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; + p = [ 1.0 ]; + a = [ 22.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 2, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 3, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 2.0, 4.0, 6.0 ]; + p = [ 1.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 0, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 2.0, 4.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = [ 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( 1, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = [ 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( x.length, 5, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 1.0, 3.0, 6.0, 10.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, -1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 6.0, 8.0 ]; + p = [ 1.0, 3.0 ]; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 2, p, 1, 0, a, 1, out, 1, w, 1 ); + + expected = [ 2.0, 3.0, 2.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = []; + p = [ 1.0, 3.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, x, 1, 2, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 2.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = [ 2.0, 4.0 ]; + p = [ 1.0 ]; + a = [ 6.0, 10.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 1, p, 1, 2, a, 1, out, 1, w, 1 ); + + expected = [ 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 = [ 2.0, 5.0 ]; + p = []; + a = [ 10.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, p, 1, 1, a, 1, out, 1, w, 1 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = []; + p = []; + a = [ 1.0, 4.0, 9.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, x, 1, 0, p, 1, 3, a, 1, out, 1, w, 1 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 1, toAccessorArray( x ), 1, 1, toAccessorArray( p ), 1, 1, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 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 (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; + p = [ 1.0 ]; + a = [ 22.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 2, toAccessorArray( x ), 1, 1, toAccessorArray( p ), 1, 1, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 3, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 0, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 0.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input) (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 6.0 ]; + p = [ 1.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 3, 0, toAccessorArray( x ), 1, 1, toAccessorArray( p ), 1, 1, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 1.0, 2.0, 4.0, 6.0, 7.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 1.0, 3.0, 6.0, 10.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( 4, 1, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 0, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 2.0, 3.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 1, toAccessorArray( x ), -1, 1, toAccessorArray( p ), 1, 1, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged for trivial cases (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = [ 2.0, 4.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 0, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Single element (total <= 1): + x = [ 5.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( 1, 1, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 0, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // k >= total: + x = [ 1.0, 2.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( x.length, 5, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 0, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Multiple prepend (N1=2), no append: + x = [ 6.0, 8.0 ]; + p = [ 1.0, 3.0 ]; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, toAccessorArray( x ), 1, 2, toAccessorArray( p ), 1, 0, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 2.0, 3.0, 2.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = []; + p = [ 1.0, 3.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, toAccessorArray( x ), 1, 2, toAccessorArray( p ), 1, 1, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 2.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = [ 2.0, 4.0 ]; + p = [ 1.0 ]; + a = [ 6.0, 10.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, toAccessorArray( x ), 1, 1, toAccessorArray( p ), 1, 2, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 1.0, 2.0, 2.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // No prepend, x present, single append: + x = [ 2.0, 5.0 ]; + p = []; + a = [ 10.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( x.length, 1, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 1, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = []; + p = []; + a = [ 1.0, 4.0, 9.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, toAccessorArray( x ), 1, 0, toAccessorArray( p ), 1, 3, toAccessorArray( a ), 1, toAccessorArray( out ), 1, toAccessorArray( w ), 1 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.js new file mode 100644 index 000000000000..ff31275f57bf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/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 gdiff = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof gdiff.ndarray, 'function', 'has method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.ndarray.js new file mode 100644 index 000000000000..568b606ac087 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/test/test.ndarray.js @@ -0,0 +1,520 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gdiff = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gdiff, '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 = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; + p = [ 1.0 ]; + a = [ 22.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 2, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 3, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 2.0, 4.0, 6.0 ]; + p = [ 1.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 0, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 2.0, 4.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Single element (total <= 1 in base): + x = [ 5.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( 1, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( x.length, 5, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 1.0, 3.0, 6.0, 10.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 3, 1, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 5.0, 2.0, 2.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Negative strides: + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, -1, 4, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Strided access (stride=2): + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 3, 1, x, 2, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 6.0, 8.0 ]; + p = [ 1.0, 3.0 ]; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, 2, p, 1, 0, 0, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 2.0, 3.0, 2.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Multiple prepend (N1=2) and append (N2=1), no x: + x = []; + p = [ 1.0, 3.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, x, 1, 0, 2, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 2.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Prepend (N1=1), x, and multiple append (N2=2): + x = [ 2.0, 4.0 ]; + p = [ 1.0 ]; + a = [ 6.0, 10.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, 1, p, 1, 0, 2, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 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 = [ 2.0, 5.0 ]; + p = []; + a = [ 10.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( x.length, 1, x, 1, 0, 0, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // No prepend, no x, only append (N2=3): + x = []; + p = []; + a = [ 1.0, 4.0, 9.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, x, 1, 0, 0, p, 1, 0, 3, a, 1, 0, out, 1, 0, w, 1, 0 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the first forward difference (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 1, toAccessorArray( x ), 1, 0, 1, toAccessorArray( p ), 1, 0, 1, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 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 (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 7.0, 11.0, 16.0 ]; + p = [ 1.0 ]; + a = [ 22.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 2, toAccessorArray( x ), 1, 0, 1, toAccessorArray( p ), 1, 0, 1, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 1.0, 1.0, 1.0, 1.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Third forward difference (k=3): + x = [ 1.0, 3.0, 6.0, 10.0, 15.0, 21.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 6, 3, toAccessorArray( x ), 1, 0, 0, toAccessorArray( p ), 1, 0, 0, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 0.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports k=0 (copies input) (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 4.0, 6.0 ]; + p = [ 1.0 ]; + a = [ 7.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 3, 0, toAccessorArray( x ), 1, 0, 1, toAccessorArray( p ), 1, 0, 1, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 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 (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // N <= 0: + x = [ 2.0, 4.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 0, 1, toAccessorArray( x ), 1, 0, 0, toAccessorArray( p ), 1, 0, 0, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Single element (total <= 1): + x = [ 5.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( 1, 1, toAccessorArray( x ), 1, 0, 0, toAccessorArray( p ), 1, 0, 0, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // k >= total: + x = [ 1.0, 2.0 ]; + p = []; + a = []; + out = [ 0.0 ]; + w = [ 0.0 ]; + + gdiff( x.length, 5, toAccessorArray( x ), 1, 0, 0, toAccessorArray( p ), 1, 0, 0, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports no prepend and no append (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 1.0, 3.0, 6.0, 10.0 ]; + p = []; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( 4, 1, toAccessorArray( x ), 1, 0, 0, toAccessorArray( p ), 1, 0, 0, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 2.0, 3.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports strides and offsets (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + // Offset for `x`: + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 3, 1, toAccessorArray( x ), 1, 2, 1, toAccessorArray( p ), 1, 0, 1, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 5.0, 2.0, 2.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + // Negative strides: + x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + p = [ 1.0 ]; + a = [ 11.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gdiff( 5, 1, toAccessorArray( x ), -1, 4, 1, toAccessorArray( p ), 1, 0, 1, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 9.0, -2.0, -2.0, -2.0, -2.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple prepend and append values (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 6.0, 8.0 ]; + p = [ 1.0, 3.0 ]; + a = []; + out = [ 0.0, 0.0, 0.0 ]; + w = [ 0.0, 0.0, 0.0 ]; + + gdiff( 2, 1, toAccessorArray( x ), 1, 0, 2, toAccessorArray( p ), 1, 0, 0, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 2.0, 3.0, 2.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports append without prepend (accessors)', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var w; + + x = [ 2.0, 5.0 ]; + p = []; + a = [ 10.0 ]; + out = [ 0.0, 0.0 ]; + w = [ 0.0, 0.0 ]; + + gdiff( 2, 1, toAccessorArray( x ), 1, 0, 0, toAccessorArray( p ), 1, 0, 1, toAccessorArray( a ), 1, 0, toAccessorArray( out ), 1, 0, toAccessorArray( w ), 1, 0 ); + + expected = [ 3.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); From 71abd14508a433628ebab12056bdf022158196a3 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 22 Apr 2026 00:28:32 +0500 Subject: [PATCH 2/4] fix: apply suggestions from code review --- .../@stdlib/blas/ext/base/gdiff/README.md | 18 +- .../ext/base/gdiff/benchmark/benchmark.js | 2 +- .../base/gdiff/benchmark/benchmark.ndarray.js | 2 +- .../@stdlib/blas/ext/base/gdiff/docs/repl.txt | 41 +- .../blas/ext/base/gdiff/docs/types/index.d.ts | 43 ++- .../blas/ext/base/gdiff/docs/types/test.ts | 361 +++++++++--------- .../blas/ext/base/gdiff/examples/index.js | 3 +- .../blas/ext/base/gdiff/lib/accessors.js | 25 +- .../@stdlib/blas/ext/base/gdiff/lib/gdiff.js | 20 +- .../blas/ext/base/gdiff/lib/ndarray.js | 48 ++- 10 files changed, 296 insertions(+), 267 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md b/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md index db646241ff28..ba291fe0bcfa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/README.md @@ -34,7 +34,7 @@ var gdiff = require( '@stdlib/blas/ext/base/gdiff' ); #### gdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW ) -Calculates the k-th discrete forward differences of a strided array. +Calculates the k-th discrete forward difference of a strided array. ```javascript var x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; @@ -55,10 +55,10 @@ The function has the following parameters: - **k**: number of times to recursively compute differences. - **x**: input array. - **strideX**: stride length for `x`. -- **N1**: number of elements to `prepend`. +- **N1**: number of indexed elements to `prepend`. - **prepend**: array 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**: array containing values to append prior to computing differences. - **strideA**: stride length for `append`. - **out**: output array. Must have `N + N1 + N2 - k` elements. @@ -107,7 +107,7 @@ console.log( out ); #### gdiff.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 strided array using alternative indexing semantics. +Calculates the k-th discrete forward difference of a strided array using alternative indexing semantics. ```javascript var x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; @@ -128,9 +128,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 x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; @@ -153,7 +153,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. @@ -186,11 +187,10 @@ var a = discreteUniform( 2, -100, 100, { console.log( 'Append array: ', a ); var out = zeros( 10, 'generic' ); - var w = zeros( 13, 'generic' ); gdiff( 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/gdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js index 6458121b3c8b..06ef532362b2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js @@ -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 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js index 5457037926bd..fcb9b7d1c25e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js @@ -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 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/repl.txt index 548531155a77..311fe079a0f0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/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 strided array. + Calculates the k-th discrete forward difference of a strided array. The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. @@ -8,7 +8,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 ---------- @@ -25,34 +26,34 @@ Stride length for `x`. N1: integer - Number of elements to `prepend`. + Number of indexed elements for `p`. p: Array|TypedArray 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: Array|TypedArray Array containing values to append prior to computing differences. sa: integer - Stride length for `append`. + Stride length for `a`. out: Array|TypedArray - Output array. + Output array. Must have `N + N1 + N2 - k` indexed elements. so: integer Stride length for `out`. w: Array|TypedArray - Workspace array. + Workspace array. Must have `N + N1 + N2 - 1` indexed elements. sw: integer - Stride length for `workspace`. + Stride length for `w`. Returns ------- @@ -91,7 +92,7 @@ {{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 strided array using + Calculates the k-th discrete forward difference of a strided array using alternative indexing semantics. While typed array views mandate a view offset based on the underlying @@ -116,31 +117,31 @@ Starting index for `x`. N1: integer - Number of elements to `prepend`. + Number of indexed elements for `p`. p: Array|TypedArray 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: Array|TypedArray 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: Array|TypedArray - Output array. + Output array. Must have `N + N1 + N2 - k` indexed elements. so: integer Stride length for `out`. @@ -149,13 +150,13 @@ Starting index for `out`. w: Array|TypedArray - Workspace array. + 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 ------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts index ac12b28d94e3..5f082b873d7e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/index.d.ts @@ -20,7 +20,17 @@ /// -import { Collection } from '@stdlib/types/array'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = NumericArray | Collection | AccessorArrayLike; /** * Interface describing `gdiff`. @@ -29,14 +39,19 @@ interface Routine { /** * Calculates the k-th discrete forward difference of a 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 @@ -57,21 +72,26 @@ interface Routine { * console.log( out ); * // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] */ - ( N: number, k: number, x: Collection, strideX: number, N1: number, prepend: Collection, strideP: number, N2: number, append: Collection, strideA: number, out: Collection, strideOut: number, workspace: Collection, strideW: number ): Collection; + ( N: number, k: number, x: InputArray, strideX: number, N1: number, prepend: InputArray, strideP: number, N2: number, append: InputArray, strideA: number, out: T, strideOut: number, workspace: InputArray, strideW: number ): T; /** * Calculates the k-th discrete forward difference of a 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` @@ -95,20 +115,25 @@ interface Routine { * console.log( out ); * // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] */ - ndarray( N: number, k: number, x: Collection, strideX: number, offsetX: number, N1: number, prepend: Collection, strideP: number, offsetP: number, N2: number, append: Collection, strideA: number, offsetA: number, out: Collection, strideOut: number, offsetOut: number, workspace: Collection, strideW: number, offsetW: number ): Collection; + ndarray( N: number, k: number, x: InputArray, strideX: number, offsetX: number, N1: number, prepend: InputArray, strideP: number, offsetP: number, N2: number, append: InputArray, strideA: number, offsetA: number, out: T, strideOut: number, offsetOut: number, workspace: InputArray, strideW: number, offsetW: number ): T; } /** * Calculates the k-th discrete forward difference of a 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/gdiff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts index 84cf244be0ce..8dd3f65a4ff4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/docs/types/test.ts @@ -16,29 +16,31 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import gdiff = require( './index' ); // TESTS // -// The function returns a collection... +// The function returns a numeric array... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); - gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Collection + gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectType Float64Array + gdiff( x.length, 1, new AccessorArray( x ), 1, 1, new AccessorArray( p ), 1, 1, new AccessorArray( a ), 1, new AccessorArray( out ), 1, new AccessorArray( w ), 1 ); // $ExpectType AccessorArray } // The compiler throws an error if the function is provided a first argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( '10', 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( true, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -52,11 +54,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a second argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, '10', x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, true, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -70,10 +72,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a third argument which is not a collection... { - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( 5, 1, 10, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( 5, 1, true, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -85,11 +87,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a fourth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, '10', 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, true, 1, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -103,11 +105,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a fifth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, '10', p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, true, p, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -121,10 +123,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a sixth argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, 10, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, true, 1, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -136,11 +138,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a seventh argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, '10', 1, a, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, true, 1, a, 1, out, 1, w, 1 ); // $ExpectError @@ -154,11 +156,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided an eighth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, '10', a, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, true, a, 1, out, 1, w, 1 ); // $ExpectError @@ -172,10 +174,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a ninth argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, 10, 1, out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, 1, true, 1, out, 1, w, 1 ); // $ExpectError @@ -187,11 +189,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a tenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, '10', out, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, true, out, 1, w, 1 ); // $ExpectError @@ -205,10 +207,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided an eleventh argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, 10, 1, w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, true, 1, w, 1 ); // $ExpectError @@ -220,11 +222,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a twelfth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, '10', w, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, true, w, 1 ); // $ExpectError @@ -238,10 +240,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a thirteenth argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, 10, 1 ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, true, 1 ); // $ExpectError @@ -253,11 +255,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided a fourteenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, '10' ); // $ExpectError gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, true ); // $ExpectError @@ -271,11 +273,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff(); // $ExpectError gdiff( x.length ); // $ExpectError @@ -294,24 +296,25 @@ import gdiff = require( './index' ); gdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1, 10 ); // $ExpectError } -// Attached to main export is an `ndarray` method which returns a collection... +// Attached to main export is an `ndarray` method which returns a numeric array... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); - gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Collection + gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectType Float64Array + gdiff.ndarray( x.length, 1, new AccessorArray( x ), 1, 0, 1, new AccessorArray( p ), 1, 0, 1, new AccessorArray( a ), 1, 0, new AccessorArray( out ), 1, 0, new AccessorArray( w ), 1, 0 ); // $ExpectType AccessorArray } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( '10', 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( true, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -325,11 +328,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -343,10 +346,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... { - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( 5, 1, 10, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( 5, 1, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -358,11 +361,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -376,11 +379,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -394,11 +397,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -412,10 +415,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, 10, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -427,11 +430,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -445,11 +448,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, '10', 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, true, 1, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -463,11 +466,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -481,10 +484,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, 10, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -496,11 +499,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -514,11 +517,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0, w, 1, 0 ); // $ExpectError @@ -532,10 +535,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a fourteenth argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, 10, 1, 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError @@ -547,11 +550,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a fifteenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0, w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0, w, 1, 0 ); // $ExpectError @@ -565,11 +568,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a sixteenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10', w, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true, w, 1, 0 ); // $ExpectError @@ -583,10 +586,10 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a seventeenth argument which is not a collection... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, 10, 1, 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, true, 1, 0 ); // $ExpectError @@ -598,11 +601,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided an eighteenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, '10', 0 ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, true, 0 ); // $ExpectError @@ -616,11 +619,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a nineteenth argument which is not a number... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, '10' ); // $ExpectError gdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, true ); // $ExpectError @@ -634,11 +637,11 @@ import gdiff = require( './index' ); // The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... { - const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - const p = [ 0.0 ]; - const a = [ 6.0 ]; - const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - const w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + const x = new Float64Array( 5 ); + const p = new Float64Array( 1 ); + const a = new Float64Array( 1 ); + const out = new Float64Array( 6 ); + const w = new Float64Array( 6 ); gdiff.ndarray(); // $ExpectError gdiff.ndarray( x.length ); // $ExpectError diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js index 5eca2464bbc9..39347cc9287f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/examples/index.js @@ -38,8 +38,7 @@ var a = discreteUniform( 2, -100, 100, { console.log( 'Append array: ', a ); var out = zeros( 10, 'generic' ); - var w = zeros( 13, 'generic' ); gdiff( 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/gdiff/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/accessors.js index 1df8dc9f9ec4..aaf093211b06 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/accessors.js @@ -22,7 +22,7 @@ // MODULES // -var gcopy = require( '@stdlib/blas/base/gcopy' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; // FUNCTIONS // @@ -37,13 +37,13 @@ var gcopy = require( '@stdlib/blas/base/gcopy' ); * @param {Array} x.accessors - array element accessors * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NonNegativeInteger} N1 - number of indexed elements for `prepend` * @param {Object} prepend - prepend array object * @param {Collection} prepend.data - prepend array data * @param {Array} prepend.accessors - array element accessors * @param {integer} strideP - stride length for `prepend` * @param {NonNegativeInteger} offsetP - starting index for `prepend` -* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NonNegativeInteger} N2 - number of indexed elements for `append` * @param {Object} append - append array object * @param {Collection} append.data - append array data * @param {Array} append.accessors - array element accessors @@ -89,6 +89,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append obuf = out.data; oset = out.accessors[ 1 ]; + // Compute forward differences: if ( N1 === 0 && N2 === 0 ) { ix = offsetX; io = offsetOut; @@ -103,7 +104,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append return out; } - // Prepend + // Compute forward differences over the list of prepended values: if ( N1 > 0 ) { io = offsetOut; ip = offsetP; @@ -133,8 +134,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append prev = aget( abuf, offsetA ); io = offsetOut; } - - // x + // Compute forward differences over the input array: if ( N > 0 ) { ix = offsetX; if ( N1 === 0 ) { @@ -164,8 +164,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append io += strideOut; } } - - // Append + // Compute forward differences over the list of appended values: if ( N2 > 0 ) { ia = offsetA + strideA; for ( i = 1; i < N2; i++ ) { @@ -193,13 +192,13 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append * @param {Array} x.accessors - array element accessors * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NonNegativeInteger} N1 - number of indexed elements for `prepend` * @param {Object} prepend - prepend array object * @param {Collection} prepend.data - prepend array data * @param {Array} prepend.accessors - array element accessors * @param {integer} strideP - stride length for `prepend` * @param {NonNegativeInteger} offsetP - starting index for `prepend` -* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NonNegativeInteger} N2 - number of indexed elements for `append` * @param {Object} append - append array object * @param {Collection} append.data - append array data * @param {Array} append.accessors - array element accessors @@ -241,15 +240,15 @@ function gdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, ap total = N + N1 + N2; if ( k === 0 ) { // Copy `prepend` into output array: - gcopy.ndarray( N1, prepend.data, strideP, offsetP, out.data, strideOut, offsetOut ); + gcopy( N1, prepend.data, strideP, offsetP, out.data, strideOut, offsetOut ); // Copy `x` into output array: io = offsetOut + ( N1 * strideOut ); - gcopy.ndarray( N, x.data, strideX, offsetX, out.data, strideOut, io ); + gcopy( N, x.data, strideX, offsetX, out.data, strideOut, io ); // Copy `append` into output array: io = offsetOut + ( ( N1 + N ) * strideOut ); - gcopy.ndarray( N2, append.data, strideA, offsetA, out.data, strideOut, io ); + gcopy( N2, append.data, strideA, offsetA, out.data, strideOut, io ); return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js index 13e0802dff12..7cc34f4563d2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/gdiff.js @@ -35,10 +35,10 @@ var ndarray = require( './ndarray.js' ); * @param {PositiveInteger} k - number of times to recursively compute differences * @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` -* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NonNegativeInteger} N1 - number of indexed elements for `prepend` * @param {NumericArray} prepend - prepend array * @param {integer} strideP - stride length for `prepend` -* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NonNegativeInteger} N2 - number of indexed elements for `append` * @param {NumericArray} append - append array * @param {integer} strideA - stride length for `append` * @param {NumericArray} out - output array @@ -60,11 +60,17 @@ var ndarray = require( './ndarray.js' ); * // => [ 1.0, 1.0, 1.0, 1.0, 1.0 ] */ function gdiff( 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 ); + var ox; + var op; + var oa; + var oo; + var ow; + + ox = stride2offset( N, strideX ); + op = stride2offset( N1, strideP ); + oa = stride2offset( N2, strideA ); + oo = stride2offset( N + N1 + N2 - k, strideOut ); + 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; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js index a09a8c5ec972..89b53b1d5fd0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/lib/ndarray.js @@ -22,7 +22,7 @@ // MODULES // -var gcopy = require( '@stdlib/blas/base/gcopy' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var accessors = require( './accessors.js' ); @@ -37,11 +37,11 @@ var accessors = require( './accessors.js' ); * @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NonNegativeInteger} N1 - number of indexed elements for `prepend` * @param {NumericArray} prepend - prepend array * @param {integer} strideP - stride length for `prepend` * @param {NonNegativeInteger} offsetP - starting index for `prepend` -* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NonNegativeInteger} N2 - number of indexed elements for `append` * @param {NumericArray} append - append array * @param {integer} strideA - stride length for `append` * @param {NonNegativeInteger} offsetA - starting index for `append` @@ -64,7 +64,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append if ( total <= 1 ) { return out; } - + // Compute forward differences: if ( N1 === 0 && N2 === 0 ) { ix = offsetX; io = offsetOut; @@ -78,8 +78,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append } return out; } - - // Prepend + // Compute forward differences over the list of prepended values: if ( N1 > 0 ) { io = offsetOut; ip = offsetP; @@ -109,8 +108,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append prev = append[ offsetA ]; io = offsetOut; } - - // x + // Compute forward differences over the input array: if ( N > 0 ) { ix = offsetX; if ( N1 === 0 ) { @@ -140,8 +138,7 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append io += strideOut; } } - - // Append + // Compute forward differences over the list of appended values: if ( N2 > 0 ) { ia = offsetA + strideA; for ( i = 1; i < N2; i++ ) { @@ -166,11 +163,11 @@ function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append * @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {NonNegativeInteger} N1 - number of indexed elements of prepend +* @param {NonNegativeInteger} N1 - number of indexed elements for `prepend` * @param {NumericArray} prepend - prepend array * @param {integer} strideP - stride length for `prepend` * @param {NonNegativeInteger} offsetP - starting index for `prepend` -* @param {NonNegativeInteger} N2 - number of indexed elements of append +* @param {NonNegativeInteger} N2 - number of indexed elements for `append` * @param {NumericArray} append - append array * @param {integer} strideA - stride length for `append` * @param {NonNegativeInteger} offsetA - starting index for `append` @@ -206,15 +203,12 @@ function gdiff( 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; } - + // Dispatch to the accessor path when any array uses the accessor protocol... ox = arraylike2object( x ); op = arraylike2object( prepend ); oa = arraylike2object( append ); @@ -224,36 +218,38 @@ function gdiff( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, ap accessors( N, k, ox, strideX, offsetX, N1, op, strideP, offsetP, N2, oa, strideA, offsetA, oo, strideOut, offsetOut, ow, strideW, offsetW ); return oo.data; } - + // 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: - gcopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + gcopy( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); // Copy `x` into output array: io = offsetOut + ( N1 * strideOut ); - gcopy.ndarray( N, x, strideX, offsetX, out, strideOut, io ); + gcopy( N, x, strideX, offsetX, out, strideOut, io ); // Copy `append` into output array: io = offsetOut + ( ( N1 + N ) * strideOut ); - gcopy.ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + gcopy( 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; } From 178a483e034844e595c421d46e8ca764cc3316bd Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 25 Apr 2026 12:03:08 +0500 Subject: [PATCH 3/4] 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: passed - 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 --- --- .../blas/ext/base/gdiff/benchmark/benchmark.js | 12 +++--------- .../ext/base/gdiff/benchmark/benchmark.ndarray.js | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js index 06ef532362b2..84f6b0d3b514 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); @@ -56,7 +57,6 @@ function createBenchmark( len ) { var o; var k; var N; - var i; N = len; N1 = 1; @@ -67,14 +67,8 @@ function createBenchmark( len ) { x = uniform( N, -100, 100, options ); p = uniform( N1, -100, 100, options ); a = uniform( N2, -100, 100, options ); - w = []; - for ( i = 0; i < N+N1+N2-1; i++ ) { - w.push( 0.0 ); - } - o = []; - for ( i = 0; i < ol; i++ ) { - o.push( 0.0 ); - } + w = zeros( N+N1+N2-1, 'generic' ); + o = zeros( ol, 'generic' ); return benchmark; /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js index fcb9b7d1c25e..43dae20da58f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); @@ -56,7 +57,6 @@ function createBenchmark( len ) { var o; var k; var N; - var i; N = len; N1 = 1; @@ -67,14 +67,8 @@ function createBenchmark( len ) { x = uniform( N, -100, 100, options ); p = uniform( N1, -100, 100, options ); a = uniform( N2, -100, 100, options ); - w = []; - for ( i = 0; i < N+N1+N2-1; i++ ) { - w.push( 0.0 ); - } - o = []; - for ( i = 0; i < ol; i++ ) { - o.push( 0.0 ); - } + w = zeros( N+N1+N2-1, 'generic' ); + o = zeros( ol, 'generic' ); return benchmark; /** From 2d525c98494d3fc45660373b3b809df16e795ba1 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 26 Apr 2026 14:03:09 -0700 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js | 4 ++-- .../blas/ext/base/gdiff/benchmark/benchmark.ndarray.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js index 84f6b0d3b514..120d2a306bff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.js @@ -67,8 +67,8 @@ function createBenchmark( len ) { x = uniform( N, -100, 100, options ); p = uniform( N1, -100, 100, options ); a = uniform( N2, -100, 100, options ); - w = zeros( N+N1+N2-1, 'generic' ); - o = zeros( ol, 'generic' ); + w = zeros( N+N1+N2-1, options.dtype ); + o = zeros( ol, options.dtype ); return benchmark; /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js index 43dae20da58f..190a4ff84664 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gdiff/benchmark/benchmark.ndarray.js @@ -67,8 +67,8 @@ function createBenchmark( len ) { x = uniform( N, -100, 100, options ); p = uniform( N1, -100, 100, options ); a = uniform( N2, -100, 100, options ); - w = zeros( N+N1+N2-1, 'generic' ); - o = zeros( ol, 'generic' ); + w = zeros( N+N1+N2-1, options.dtype ); + o = zeros( ol, options.dtype ); return benchmark; /**