diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/README.md b/lib/node_modules/@stdlib/blas/ext/base/gediff/README.md new file mode 100644 index 000000000000..15c993a874d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/README.md @@ -0,0 +1,209 @@ + + +# gediff + +> Calculate the differences between consecutive elements of a strided array. + +
+ +## Usage + +```javascript +var gediff = require( '@stdlib/blas/ext/base/gediff' ); +``` + + + +#### gediff( N, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut ) + +Calculates the differences between consecutive elements 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 ]; + +gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); + +console.log( out ); +// => [ 1.0, 2.0, 2.0, 2.0, 2.0, 11.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input array. +- **strideX**: stride length for `x`. +- **N1**: number of elements to `prepend`. +- **prepend**: array containing values to prepend to the output array. +- **strideP**: stride length for `prepend`. +- **N2**: number of elements to `append`. +- **append**: array containing values to append to the output array. +- **strideA**: stride length for `append`. +- **out**: output array. Must have `N + N1 + N2 - 1` elements. +- **strideOut**: stride length for `out`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute differences of every other element: + +```javascript +var 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 ]; + +gediff( 3, x, 2, 1, p, 1, 1, a, 1, out, 1 ); + +console.log( out ); +// => [ 1.0, 4.0, 4.0, 11.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var 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 ]; + +gediff( x1.length, x1, 1, 1, p, 1, 1, a, 1, out, 1 ); + +console.log( out ); +// => [ 1.0, 2.0, 2.0, 2.0, 11.0 ] +``` + + + +#### gediff.ndarray( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) + +Calculates the differences between consecutive elements 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 ]; + +gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); + +console.log( out ); +// => [ 1.0, 2.0, 2.0, 2.0, 2.0, 11.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetP**: starting index for `prepend`. +- **offsetA**: starting index for `append`. +- **offsetOut**: starting index for `out`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var 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 ]; + +gediff.ndarray( 3, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); + +console.log( out ); +// => [ 1.0, 2.0, 2.0, 11.0 ] +``` + +
+ + + +
+ +## Notes + +- If the sum of `N`, `N1`, and `N2` is less than or equal to `1`, both functions return the output array unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gediff = require( '@stdlib/blas/ext/base/gediff' ); + +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( 13 ); + +gediff( x.length, x, 1, 2, p, 1, 2, a, 1, out, 1 ); +console.log( 'Output', out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/benchmark/benchmark.js new file mode 100644 index 000000000000..4d22cb067779 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/benchmark/benchmark.js @@ -0,0 +1,123 @@ +/** +* @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 gediff = require( './../lib/main.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 o; + var N; + var i; + + N = len; + N1 = 1; + N2 = 1; + ol = N + N1 + N2 - 1; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + o = []; + 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++ ) { + gediff( N, x, 1, N1, p, 1, N2, a, 1, o, 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/gediff/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..8839933054ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/benchmark/benchmark.ndarray.js @@ -0,0 +1,123 @@ +/** +* @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 gediff = 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 o; + var N; + var i; + + N = len; + N1 = 1; + N2 = 1; + ol = N + N1 + N2 - 1; + + x = uniform( N, -100, 100, options ); + p = uniform( N1, -100, 100, options ); + a = uniform( N2, -100, 100, options ); + o = []; + 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++ ) { + gediff( N, x, 1, 0, N1, p, 1, 0, N2, a, 1, 0, o, 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/gediff/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/repl.txt new file mode 100644 index 000000000000..933562003001 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/repl.txt @@ -0,0 +1,161 @@ + +{{alias}}( N, x, sx, N1, p, sp, N2, a, sa, out, so ) + Calculates the differences between consecutive elements 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 the sum of `N`, `N1`, and `N2` is less than or equal to `1`, the function + returns the output array unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + sx: integer + Stride length for `x`. + + N1: integer + Number of elements to `prepend`. + + p: ArrayLikeObject + Array containing values to prepend to the output array. + + sp: integer + Stride length for `prepend`. + + N2: integer + Number of elements to `append`. + + a: ArrayLikeObject + Array containing values to append to the output array. + + sa: integer + Stride length for `append`. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + Returns + ------- + out: ArrayLikeObject + 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 ]; + > {{alias}}( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ) + [ 0.0, -3.0, 4.0, 3.0 ] + + // Using `N` and stride parameters: + > x = [ 2.0, 4.0, 6.0, 8.0, 10.0 ]; + > p = [ 1.0 ]; + > a = [ 11.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 3, x, 2, 1, p, 1, 1, a, 1, out, 1 ) + [ 1.0, 4.0, 4.0, 11.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/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 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( x1.length, x1, 1, 1, p, 1, 1, a, 1, out, 1 ) + [ 1.0, 2.0, 2.0, 2.0, 11.0 ] + + +{{alias}}.ndarray( N, x, sx, ox, N1, p, sp, op, N2, a, sa, oa, out, so, oo ) + Calculates the differences between consecutive elements of a strided array + using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + N1: integer + Number of elements to `prepend`. + + p: ArrayLikeObject + Array containing values to prepend to the output array. + + sp: integer + Stride length for `prepend`. + + op: integer + Starting index for `prepend`. + + N2: integer + Number of elements to `append`. + + a: ArrayLikeObject + Array containing values to append to the output array. + + sa: integer + Stride length for `append`. + + oa: integer + Starting index for `append`. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + 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 ]; + > {{alias}}.ndarray( 3, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ) + [ 0.0, -3.0, 4.0, 3.0 ] + + // Advanced indexing: + > x = [ 1.0, -2.0, 2.0 ]; + > p = [ 0.0 ]; + > a = [ 3.0 ]; + > out = [ 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 2, x, 1, 1, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ) + [ 0.0, 4.0, 3.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/types/index.d.ts new file mode 100644 index 000000000000..9f978c0cc5db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/types/index.d.ts @@ -0,0 +1,135 @@ +/* +* @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 `gediff`. +*/ +interface Routine { + /** + * Calculates the differences between consecutive elements of a strided array. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @returns output array + * + * @example + * var 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, 0.0 ]; + * + * gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); + * + * console.log( out ); + * // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] + */ + ( N: number, x: Collection, strideX: number, N1: number, prepend: Collection, strideP: number, N2: number, append: Collection, strideA: number, out: Collection, strideOut: number ): Collection; + + /** + * Calculates the differences between consecutive elements of a strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param N1 - number of indexed elements of prepend + * @param prepend - prepend array + * @param strideP - stride length for `prepend` + * @param offsetP - starting index for `prepend` + * @param N2 - number of indexed elements of append + * @param append - append array + * @param strideA - stride length for `append` + * @param offsetA - starting index for `append` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var 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, 0.0 ]; + * + * gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); + * + * console.log( out ); + * // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] + */ + ndarray( N: 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 ): Collection; +} + +/** +* Calculates the differences between consecutive elements of a strided array. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length for `x` +* @param N1 - number of indexed elements of prepend +* @param prepend - prepend array +* @param strideP - stride length for `prepend` +* @param N2 - number of indexed elements of append +* @param append - append array +* @param strideA - stride length for `append` +* @param out - output array +* @param strideOut - stride length for `out` +* @returns output array +* +* @example +* var 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, 0.0 ]; +* +* gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +* +* console.log( out ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.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, 0.0 ]; +* +* gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +declare var gediff: Routine; + + +// EXPORTS // + +export = gediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/types/test.ts new file mode 100644 index 000000000000..c6c7e48b446d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/docs/types/test.ts @@ -0,0 +1,506 @@ +/* +* @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 gediff = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 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 = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( '10', x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( true, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( false, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( null, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( undefined, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( [], x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( {}, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( ( x: number ): number => x, x, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( 5, 10, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( 5, true, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( 5, false, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( 5, null, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( 5, undefined, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( 5, {}, 1, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, '10', 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, true, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, false, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, null, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, undefined, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, [], 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, {}, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, ( x: number ): number => x, 1, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, '10', p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, true, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, false, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, null, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, undefined, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, [], p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, {}, p, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, ( x: number ): number => x, p, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, 10, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, true, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, false, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, null, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, undefined, 1, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, {}, 1, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, p, '10', 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, true, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, false, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, null, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, undefined, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, [], 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, {}, 1, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, ( x: number ): number => x, 1, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, p, 1, '10', a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, true, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, false, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, null, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, undefined, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, [], a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, {}, a, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, ( x: number ): number => x, a, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, p, 1, 1, 10, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, true, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, false, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, null, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, undefined, 1, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, {}, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, p, 1, 1, a, '10', out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, true, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, false, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, null, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, undefined, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, [], out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, {}, out, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, ( x: number ): number => x, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, 10, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, true, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, false, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, null, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, undefined, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, '10' ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, true ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, false ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, null ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, undefined ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, [] ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, {} ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff(); // $ExpectError + gediff( x.length ); // $ExpectError + gediff( x.length, x ); // $ExpectError + gediff( x.length, x, 1 ); // $ExpectError + gediff( x.length, x, 1, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1 ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out ); // $ExpectError + gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 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 = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( '10', x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( true, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( false, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( null, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( undefined, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( [], x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( {}, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( ( x: number ): number => x, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( 5, 10, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( 5, true, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( 5, false, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( 5, null, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( 5, undefined, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( 5, {}, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, '10', 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, true, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, false, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, null, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, undefined, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, [], 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, {}, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, ( x: number ): number => x, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, '10', 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, true, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, false, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, null, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, undefined, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, [], 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, {}, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, ( x: number ): number => x, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, '10', p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, true, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, false, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, null, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, undefined, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, [], p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, {}, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, ( x: number ): number => x, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, 10, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, true, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, false, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, null, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, undefined, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, {}, 1, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, '10', 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, true, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, false, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, null, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, undefined, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, [], 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, {}, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, ( x: number ): number => x, 0, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, '10', 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, true, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, false, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, null, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, undefined, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, [], 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, {}, 1, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, ( x: number ): number => x, 1, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, '10', a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, true, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, false, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, null, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, undefined, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, [], a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, {}, a, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, ( x: number ): number => x, a, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, 10, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, true, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, false, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, null, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, undefined, 1, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, {}, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, '10', 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, true, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, false, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, null, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, undefined, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, [], 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, {}, 0, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, '10', out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, true, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, false, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, null, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, undefined, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, [], out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, {}, out, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a collection... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, 10, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, true, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, false, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, null, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, undefined, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourteenth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, '10', 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, true, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, false, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, null, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, undefined, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, [], 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, {}, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifteenth argument which is not a number... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, '10' ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, true ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, false ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, null ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, undefined ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, [] ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, {} ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + const p = [ 1.0 ]; + const a = [ 22.0 ]; + const out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gediff.ndarray(); // $ExpectError + gediff.ndarray( x.length ); // $ExpectError + gediff.ndarray( x.length, x ); // $ExpectError + gediff.ndarray( x.length, x, 1 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1 ); // $ExpectError + gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/examples/index.js new file mode 100644 index 000000000000..a0ef948aefeb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gediff = 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( 13 ); + +gediff( x.length, x, 1, 2, p, 1, 2, a, 1, out, 1 ); +console.log( 'Output', out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/accessors.js new file mode 100644 index 000000000000..8800e193c131 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/accessors.js @@ -0,0 +1,111 @@ +/** +* @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' ); + + +// MAIN // + +/** +* Calculates the differences between consecutive elements of a strided array using alternative indexing semantics and accessors. +* +* @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 {PositiveInteger} 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 {PositiveInteger} 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 +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; +* var p = [ 10.0, 15.0 ]; +* var a = [ 30.0, 35.0 ]; +* var o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gediff( 5, arraylike2object( toAccessorArray( x ) ), 1, 0, 2, arraylike2object( toAccessorArray( p ) ), 1, 0, 2, arraylike2object( toAccessorArray( a ) ), 1, 0, arraylike2object( toAccessorArray( o ) ), 1, 0 ); +* // o => [ 10.0, 15.0, 4.0, 4.0, 4.0, 4.0, 30.0, 35.0 ] +*/ +function gediff( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var xbuf; + var obuf; + var oset; + var xget; + var prev; + var curr; + var ix; + var io; + var i; + + xbuf = x.data; + obuf = out.data; + xget = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + // Copy `prepend` into output array: + gcopy.ndarray( N1, prepend.data, strideP, offsetP, obuf, strideOut, offsetOut ); + + // Compute differences of input array: + ix = offsetX; + io = offsetOut + ( N1 * strideOut ); + 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; + } + + // Copy `append` into output array: + gcopy.ndarray( N2, append.data, strideA, offsetA, obuf, strideOut, io ); + + return out; +} + + +// EXPORTS // + +module.exports = gediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/index.js new file mode 100644 index 000000000000..1775456dff9c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/index.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Calculate the differences between consecutive elements of a strided array. +* +* @module @stdlib/blas/ext/base/gediff +* +* @example +* var gediff = require( '@stdlib/blas/ext/base/gediff' ); +* +* 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, 0.0 ]; +* +* gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +* +* console.log( out ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +* +* @example +* var gediff = require( '@stdlib/blas/ext/base/gediff' ); +* +* 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, 0.0 ]; +* +* gediff.ndarray( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/main.js new file mode 100644 index 000000000000..f44437873932 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/main.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-params, max-len */ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Calculates the differences between consecutive elements of a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Collection} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Collection} append - append array +* @param {integer} strideA - stride length for `append` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @returns {Collection} 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, 0.0 ]; +* +* gediff( x.length, x, 1, 1, p, 1, 1, a, 1, out, 1 ); +* +* console.log( out ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +function gediff( N, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut ) { + var ox = stride2offset( N, strideX ); + var op = stride2offset( N1, strideP ); + var oa = stride2offset( N2, strideA ); + var oo = stride2offset( N + N1 + N2 - 1, strideOut ); + return ndarray( N, x, strideX, ox, N1, prepend, strideP, op, N2, append, strideA, oa, out, strideOut, oo ); +} + + +// EXPORTS // + +module.exports = gediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/ndarray.js new file mode 100644 index 000000000000..0ffe12294453 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/lib/ndarray.js @@ -0,0 +1,113 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Calculates the differences between consecutive elements of a strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {PositiveInteger} N1 - number of indexed elements of prepend +* @param {Collection} prepend - prepend array +* @param {integer} strideP - stride length for `prepend` +* @param {NonNegativeInteger} offsetP - starting index for `prepend` +* @param {PositiveInteger} N2 - number of indexed elements of append +* @param {Collection} append - append array +* @param {integer} strideA - stride length for `append` +* @param {NonNegativeInteger} offsetA - starting index for `append` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} 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, 0.0 ]; +* +* gediff( x.length, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 2.0, 3.0, 4.0, 5.0, 22.0 ] +*/ +function gediff( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) { + var total; + var prev; + var curr; + var ox; + var oo; + var op; + var oa; + var ix; + var io; + var i; + + total = N + N1 + N2; + if ( total <= 1 ) { + return out; + } + + ox = arraylike2object( x ); + oo = arraylike2object( out ); + op = arraylike2object( prepend ); + oa = arraylike2object( append ); + if ( ox.accessorProtocol || oo.accessorProtocol || op.accessorProtocol || oa.accessorProtocol ) { + accessors( N, ox, strideX, offsetX, N1, op, strideP, offsetP, N2, oa, strideA, offsetA, oo, strideOut, offsetOut ); + return oo.data; + } + + // Copy `prepend` into output array: + gcopy.ndarray( N1, prepend, strideP, offsetP, out, strideOut, offsetOut ); + + // Compute differences of input array: + ix = offsetX; + io = offsetOut + ( N1 * strideOut ); + prev = x[ ix ]; + for ( i = 1; i < N; i++ ) { + ix += strideX; + curr = x[ ix ]; + out[ io ] = curr - prev; + prev = curr; + io += strideOut; + } + + // Copy `append` into output array: + gcopy.ndarray( N2, append, strideA, offsetA, out, strideOut, io ); + + return out; +} + + +// EXPORTS // + +module.exports = gediff; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/package.json b/lib/node_modules/@stdlib/blas/ext/base/gediff/package.json new file mode 100644 index 000000000000..fc1f4806b055 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/gediff", + "version": "0.0.0", + "description": "Calculate the differences between consecutive elements 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", + "ndarray" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.js new file mode 100644 index 000000000000..744552ee19ae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/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 gediff = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gediff.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.main.js new file mode 100644 index 000000000000..7a5a6032eb33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.main.js @@ -0,0 +1,193 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gediff = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', function test( t ) { + t.strictEqual( gediff.length, 11, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a strided array', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0 ]; + a = [ 30.0, 35.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( x.length, x, 1, 2, p, 1, 2, a, 1, o, 1 ); + expected = [ 10.0, 15.0, 4.0, 4.0, 4.0, 4.0, 30.0, 35.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a strided array (accessors)', function test( t ) { + var expected; + var xbuf; + var pbuf; + var abuf; + var obuf; + var x; + var p; + var a; + var o; + + xbuf = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + pbuf = [ 10.0, 15.0 ]; + abuf = [ 30.0, 35.0 ]; + obuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + x = toAccessorArray( xbuf ); + p = toAccessorArray( pbuf ); + a = toAccessorArray( abuf ); + o = toAccessorArray( obuf ); + + gediff( x.length, x, 1, 2, p, 1, 2, a, 1, o, 1 ); + expected = [ 10.0, 15.0, 4.0, 4.0, 4.0, 4.0, 30.0, 35.0 ]; + t.deepEqual( obuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the sum of `N`, `N1` & `N2` parameter is less than or equal to `1`, the function returns `out` unchanged', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0 ]; + a = [ 30.0, 35.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 1, x, 1, 0, p, 1, 0, a, 1, o, 1 ); + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0, 25.0 ]; + a = [ 30.0, 35.0, 45.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 3, x, 2, 2, p, 2, 2, a, 2, o, 2 ); + expected = [ 10.0, 0.0, 25.0, 0.0, 8.0, 0.0, 8.0, 0.0, 30.0, 0.0, 45.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters (accessors)', function test( t ) { + var expected; + var obuf; + var x; + var p; + var a; + var o; + + x = toAccessorArray( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = toAccessorArray( [ 10.0, 15.0, 25.0 ] ); + a = toAccessorArray( [ 30.0, 35.0, 45.0 ] ); + obuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + o = toAccessorArray( obuf ); + + gediff( 3, x, 2, 2, p, 2, 2, a, 2, o, 2 ); + expected = [ 10.0, 0.0, 25.0, 0.0, 8.0, 0.0, 8.0, 0.0, 30.0, 0.0, 45.0 ]; + t.deepEqual( obuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0, 25.0 ]; + a = [ 30.0, 35.0, 45.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 3, x, -2, 2, p, -2, 2, a, -2, o, -2 ); + expected = [ 30.0, 0.0, 45.0, 0.0, -8.0, 0.0, -8.0, 0.0, 10.0, 0.0, 25.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters (accessors)', function test( t ) { + var expected; + var obuf; + var x; + var p; + var a; + var o; + + x = toAccessorArray( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = toAccessorArray( [ 10.0, 15.0, 25.0 ] ); + a = toAccessorArray( [ 30.0, 35.0, 45.0 ] ); + obuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + o = toAccessorArray( obuf ); + + gediff( 3, x, -2, 2, p, -2, 2, a, -2, o, -2 ); + expected = [ 30.0, 0.0, 45.0, 0.0, -8.0, 0.0, -8.0, 0.0, 10.0, 0.0, 25.0 ]; + t.deepEqual( obuf, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.ndarray.js new file mode 100644 index 000000000000..dd95a3bbbbfb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gediff/test/test.ndarray.js @@ -0,0 +1,207 @@ +/** +* @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 gediff = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gediff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', function test( t ) { + t.strictEqual( gediff.length, 15, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a strided array', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0 ]; + a = [ 30.0, 35.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( x.length, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0 ); + expected = [ 10.0, 15.0, 4.0, 4.0, 4.0, 4.0, 30.0, 35.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates differences between consecutive elements of a strided array (accessors)', function test( t ) { + var expected; + var obuf; + var x; + var p; + var a; + var o; + + x = toAccessorArray( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = toAccessorArray( [ 10.0, 15.0 ] ); + a = toAccessorArray( [ 30.0, 35.0 ] ); + obuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + o = toAccessorArray( obuf ); + + gediff( x.length, x, 1, 0, 2, p, 1, 0, 2, a, 1, 0, o, 1, 0 ); + expected = [ 10.0, 15.0, 4.0, 4.0, 4.0, 4.0, 30.0, 35.0 ]; + t.deepEqual( obuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the sum of `N`, `N1` & `N2` parameter is less than or equal to `1`, the function returns `out` unchanged', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0 ]; + a = [ 30.0, 35.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 1, x, 1, 0, 0, p, 1, 0, 0, a, 1, 0, o, 1, 0 ); + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0, 25.0 ]; + a = [ 30.0, 35.0, 45.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 3, x, 2, 0, 2, p, 2, 0, 2, a, 2, 0, o, 2, 0 ); + expected = [ 10.0, 0.0, 25.0, 0.0, 8.0, 0.0, 8.0, 0.0, 30.0, 0.0, 45.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0, 15.0, 25.0 ]; + a = [ 30.0, 35.0, 45.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 3, x, -2, 4, 2, p, -2, 2, 2, a, -2, 2, o, -2, 10 ); + expected = [ 30.0, 0.0, 45.0, 0.0, -8.0, 0.0, -8.0, 0.0, 10.0, 0.0, 25.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative stride parameters (accessors)', function test( t ) { + var expected; + var obuf; + var x; + var p; + var a; + var o; + + x = toAccessorArray( [ 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = toAccessorArray( [ 10.0, 15.0, 25.0 ] ); + a = toAccessorArray( [ 30.0, 35.0, 45.0 ] ); + obuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + o = toAccessorArray( obuf ); + + gediff( 3, x, -2, 4, 2, p, -2, 2, 2, a, -2, 2, o, -2, 10 ); + expected = [ 30.0, 0.0, 45.0, 0.0, -8.0, 0.0, -8.0, 0.0, 10.0, 0.0, 25.0 ]; + t.deepEqual( obuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports offset parameters', function test( t ) { + var expected; + var out; + var x; + var p; + var a; + var o; + + x = [ 0.0, 4.0, 8.0, 12.0, 16.0, 20.0 ]; + p = [ 10.0 ]; + a = [ 30.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gediff( 3, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, o, 1, 0 ); + expected = [ 10.0, 4.0, 4.0, 30.0, 0.0, 0.0 ]; + t.deepEqual( o, expected, 'returns expected value' ); + t.strictEqual( out, o, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports offset parameters (accessors)', function test( t ) { + var expected; + var obuf; + var x; + var p; + var a; + var o; + + x = toAccessorArray( [ 0.0, 4.0, 8.0, 12.0, 16.0, 20.0 ] ); + p = toAccessorArray( [ 10.0 ] ); + a = toAccessorArray( [ 30.0 ] ); + obuf = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + o = toAccessorArray( obuf ); + + gediff( 3, x, 1, 2, 1, p, 1, 0, 1, a, 1, 0, o, 1, 0 ); + expected = [ 10.0, 4.0, 4.0, 30.0, 0.0, 0.0 ]; + t.deepEqual( obuf, expected, 'returns expected value' ); + + t.end(); +});