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(); +});