diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/README.md new file mode 100644 index 000000000000..ec9d1ca837f7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/README.md @@ -0,0 +1,222 @@ + + +# snancusumkbn + +> Calculate the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. + +
+ +
+ + + +
+ +## Usage + +```javascript +var snancusumkbn = require( '@stdlib/blas/ext/base/snancusumkbn' ); +``` + +#### snancusumkbn( N, sum, x, strideX, y, strideY ) + +Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, NaN, 2.0 ] ); +var y = new Float32Array( x.length ); + +snancusumkbn( x.length, 0.0, x, 1, y, 1 ); +// y => [ 1.0, 1.0, 3.0 ] + +x = new Float32Array( [ 1.0, -2.0, NaN ] ); +y = new Float32Array( x.length ); + +snancusumkbn( x.length, 10.0, x, 1, y, 1 ); +// y => [ 11.0, 9.0, 9.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **sum**: initial sum. +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. +- **y**: output [`Float32Array`][@stdlib/array/float32]. +- **strideY**: stride length for `y`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element: + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var x = new Float32Array( [ 1.0, 2.0, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] ); +var y = new Float32Array( x.length ); + +var v = snancusumkbn( 4, 0.0, x, 2, y, 1 ); +// y => [ 1.0, 1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +// Initial arrays... +var x0 = new Float32Array( [ 2.0, 1.0, 2.0, NaN, -2.0, NaN, 3.0, 4.0 ] ); +var y0 = new Float32Array( x0.length ); + +// Create offset views... +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +snancusumkbn( 4, 0.0, x1, -2, y1, 1 ); +// y0 => [ 0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 5.0, 0.0 ] +``` + +#### snancusumkbn.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) + +Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values and alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, NaN, 2.0 ] ); +var y = new Float32Array( 3 ); + +snancusumkbn.ndarray( 3, 0.0, x, 1, 0, y, 1, 0 ); +// y => [ 1.0, 1.0, 3.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative sum of every other element starting from the second element and to store in the last `N` elements of `y` starting from the last element: + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 1.0, NaN, -2.0, NaN, 2.0, 3.0, 4.0 ] ); +var y = new Float32Array( x.length ); + +snancusumkbn.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); +// y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `y` unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var snancusumkbn = require( '@stdlib/blas/ext/base/snancusumkbn' ); + +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( 0, 100 ); + } + return NaN; +} + +function constant() { + return 0.0; +} + +var x = filledarrayBy( 10, 'float32', rand ); +console.log( x ); + +var y = filledarrayBy( 10, 'float32', constant ); +console.log( y ); + +snancusumkbn( x.length, 0.0, x, 1, y, -1 ); +console.log( y ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/benchmark/benchmark.js new file mode 100644 index 000000000000..95bedf99c427 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/benchmark/benchmark.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var snancusumkbn = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); + } + return NaN; +} + +function constant() { + return 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filledarrayBy( len, options.dtype, rand ); + var y = filledarrayBy( len, options.dtype, constant ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + for ( i = 0; i < len; i++ ) { + y[ i ] = 0.0; + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 1.0; + v = snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + if ( isnanf( v[ i % len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( v[ i % len ] ) ) { + 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( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..084918a56a66 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/benchmark/benchmark.ndarray.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var scusumkbn = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); + } + return NaN; +} + +function constant() { + return 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filledarrayBy( len, options.dtype, rand ); + var y = filledarrayBy( len, options.dtype, constant ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + for ( i = 0; i < len; i++ ) { + y[ i ] = 0.0; + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 1.0; + v = scusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + if ( isnanf( v[ i % len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( v[ i % len ] ) ) { + 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( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/repl.txt new file mode 100644 index 000000000000..8e0aabf0e32b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/repl.txt @@ -0,0 +1,120 @@ + +{{alias}}( N, sum, x, strideX, y, strideY ) + Computes the cumulative sum of single-precision floating-point strided array + elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. + + 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 `y` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + sum: number + Initial sum. + + x: Float32Array + Input array. + + strideX: integer + Stride length for `x`. + + y: Float32Array + Output array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, NaN, 2.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( x.length ); + > {{alias}}( x.length, 0.0, x, 1, y, 1 ) + [ 1.0, 1.0, 3.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, NaN, 2.0, -1.0 ] ); + > y = new {{alias:@stdlib/array/float32}}( x.length ); + > {{alias}}( 3, 0.0, x, 2, y, 2 ) + [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, NaN, -1.0 ] ); + > var y0 = new {{alias:@stdlib/array/float32}}( x0.length ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + > {{alias}}( 3, 0.0, x1, 2, y1, 1 ) + [ -2.0, 0.0, -1.0 ] + > y0 + [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] + + +{{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) + Computes the cumulative sum of single-precision floating-point strided array + elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values + and 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. + + sum: number + Initial sum. + + x: Float32Array + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Float32Array + Output array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, NaN, 2.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( x.length ); + > {{alias}}.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ) + [ 1.0, 1.0, 3.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, NaN, 5.0, -1.0 ] ); + > y = new {{alias:@stdlib/array/float32}}( x.length ); + > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + [ 0.0, 0.0, 0.0, -3.0, -2.0, -2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/types/index.d.ts new file mode 100644 index 000000000000..10a4433b583f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/types/index.d.ts @@ -0,0 +1,106 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `snancusumkbn`. +*/ +interface Routine { + /** + * Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. + * + * @param N - number of indexed elements + * @param sum - initial sum + * @param x - input array + * @param strideX - stride length for `x` + * @param y - output array + * @param strideY - stride length for `y` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, NaN, 2.0 ] ); + * var y = new Float32Array( x.length ); + * + * snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + * // y => [ 1.0, 1.0, 3.0 ] + */ + ( N: number, sum: number, x: Float32Array, strideX: number, y: Float32Array, strideY: number ): Float32Array; + + /** + * Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param sum - initial sum + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param y - output array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, NaN, 2.0 ] ); + * var y = new Float32Array( x.length ); + * + * snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); + * // y => [ 1.0, 1.0, 3.0 ] + */ + ndarray( N: number, sum: number, x: Float32Array, strideX: number, offsetX: number, y: Float32Array, strideY: number, offsetY: number ): Float32Array; +} + +/** +* Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. +* +* @param N - number of indexed elements +* @param sum - initial sum +* @param x - input array +* @param strideX - stride length for `x` +* @param y - output array +* @param strideY - stride length for `y` +* @returns output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, NaN, 2.0 ] ); +* var y = new Float32Array( x.length ); +* +* snancusumkbn( x.length, 0.0, x, 1, y, 1 ); +* // y => [ 1.0, 1.0, 1.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, NaN ] ); +* var y = new Float32Array( x.length ); +* +* snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); +* // y => [ 1.0, -1.0, -1.0 ] +*/ +declare var snancusumkbn: Routine; + + +// EXPORTS // + +export = snancusumkbn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/types/test.ts new file mode 100644 index 000000000000..b82675285da1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/docs/types/test.ts @@ -0,0 +1,280 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 snancusumkbn = require( './index' ); + + +// TESTS // + +// The function returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn( x.length, 0.0, x, 1, y, 1 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn( '10', 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( true, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( false, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( null, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( undefined, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( [], 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( {}, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( ( x: number ): number => x, 0.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn( x.length, '10', 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, true, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, false, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, null, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, undefined, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, [], 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, {}, 0.0, x, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, ( x: number ): number => x, 0.0, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn( x.length, 0.0, 10, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, '10', 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, true, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, false, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, null, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, undefined, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, [ '1' ], 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, {}, 1, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn( x.length, 0.0, x, '10', y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, true, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, false, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, null, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, undefined, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, [], y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, {}, y, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + snancusumkbn( x.length, 0.0, x, 1, 10, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, '10', 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, true, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, false, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, null, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, undefined, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, [ '1' ], 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, {}, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn( x.length, 0.0, x, 1, y, '10' ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, true ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, false ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, null ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, undefined ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, [] ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, {} ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn(); // $ExpectError + snancusumkbn( x.length ); // $ExpectError + snancusumkbn( x.length, 0.0 ); // $ExpectError + snancusumkbn( x.length, 0.0, x ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1 ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y ); // $ExpectError + snancusumkbn( x.length, 0.0, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( '10', 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( true, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( false, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( null, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( undefined, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( [], 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( {}, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( ( x: number ): number => x, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, '10', 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, true, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, false, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, null, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, undefined, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, [], 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, {}, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, ( x: number ): number => x, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, 10, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, '10', 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, true, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, false, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, null, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, undefined, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, [ '1' ], 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, {}, 1, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, x, '10', 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, true, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, false, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, null, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, undefined, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, [], 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, {}, 0, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, x, 1, '10', y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, true, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, false, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, null, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, undefined, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, [], y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, {}, y, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, 10, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, '10', 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, true, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, false, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, null, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, undefined, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, {}, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, '10', 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, true, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, false, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, null, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, undefined, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, [], 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, {}, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, '10' ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, true ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, false ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, null ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, undefined ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, [] ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, {} ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + snancusumkbn.ndarray(); // $ExpectError + snancusumkbn.ndarray( x.length ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1 ); // $ExpectError + snancusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/examples/index.js new file mode 100644 index 000000000000..faa342d71a4e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/examples/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/base/discrete-uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var snancusumkbn = require( './../lib' ); + +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( 0, 100 ); + } + return NaN; +} + +function constant() { + return 0.0; +} + +var x = filledarrayBy( 10, 'float32', rand ); +console.log( x ); + +var y = filledarrayBy( 10, 'float32', constant ); +console.log( y ); + +snancusumkbn( x.length, 0.0, x, 1, y, -1 ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/index.js new file mode 100644 index 000000000000..58f099485659 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Compute the sum of strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. +* +* @module @stdlib/blas/ext/base/snancusumkbn +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var snancusumkbn = require( '@stdlib/blas/ext/base/snancusumkbn' ); +* +* var x = new Float32Array( [ 1.0, NaN, 2.0 ] ); +* var y = new Float32Array( x.length ); +* +* snancusumkbn( x.length, 0.0, x, 1, y, 1 ); +* // y => [ 1.0, 1.0, 3.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var snancusumkbn = require( '@stdlib/blas/ext/base/snancusumkbn' ); +* +* var x = new Float32Array( [ 2.0, 1.0, NaN, -2.0, NaN, NaN, 3.0, 4.0 ] ); +* var y = new Float32Array( x.length ); +* +* snancusumkbn.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 ); +* // y => [ 1.0, -1.0, -1.0, 3.0, 0.0, 0.0, 0.0, 0.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/snancusumkbn/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/main.js new file mode 100644 index 000000000000..1227a8d9c990 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/main.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} sum - initial sum +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {Float32Array} y - output array +* @param {integer} strideY - stride length for `y` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, NaN ] ); +* var y = new Float32Array( x.length ); +* +* var v = snancusumkbn( x.length, 0.0, x, 1, y, 1 ); +* // returns [ 1.0, -1.0, -1.0 ] +*/ +function snancusumkbn( N, sum, x, strideX, y, strideY ) { + ndarray( N, sum, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len + return y; +} + + +// EXPORTS // + +module.exports = snancusumkbn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/ndarray.js new file mode 100644 index 000000000000..a0ae905a7c18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/lib/ndarray.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var absf = require( '@stdlib/math/base/special/absf' ); + + +// MAIN // + +/** +* Computes the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} sum - initial sum +* @param {Float32Array} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Float32Array} y - output array +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, NaN, NaN ] ); +* var y = new Float32Array( x.length ); +* +* var v = snancusumkbn( 4, 0.0, x, 2, 1, y, 1, 0 ); +* // returns [ 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] +*/ +function snancusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { + var ix; + var iy; + var s; + var v; + var t; + var c; + var i; + + if ( N <= 0 ) { + return y; + } + ix = offsetX; + iy = offsetY; + s = sum; + c = 0.0; + for ( i = 0; i < N; i++ ) { + v = x[ ix ]; + if ( isnanf( v ) ) { + y[ iy ] = float64ToFloat32( s + c ); + ix += strideX; + iy += strideY; + continue; + } + t = float64ToFloat32( s + v ); + if ( absf( s ) >= absf( v ) ) { + c = float64ToFloat32( c + float64ToFloat32( float64ToFloat32( s - t ) + v ) ); // eslint-disable-line max-len + } else { + c = float64ToFloat32( c + float64ToFloat32( float64ToFloat32( v - t ) + s ) ); // eslint-disable-line max-len + } + s = t; + y[ iy ] = float64ToFloat32( s + c ); + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = snancusumkbn; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/package.json b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/package.json new file mode 100644 index 000000000000..79095d7c76c4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/package.json @@ -0,0 +1,81 @@ +{ + "name": "@stdlib/blas/ext/base/snancusumkbn", + "version": "0.0.0", + "description": "Calculate the cumulative sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm, ignoring `NaN` values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "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", + "statistics", + "stats", + "mathematics", + "math", + "blas", + "extended", + "sum", + "total", + "summation", + "cumulative", + "accumulate", + "compensated", + "kahan", + "kbn", + "strided", + "strided array", + "typed", + "array", + "float32", + "float", + "single", + "float32array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.js new file mode 100644 index 000000000000..740f1e9b8545 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 snancusumkbn = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof snancusumkbn, '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 snancusumkbn.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.main.js new file mode 100644 index 000000000000..b6f89b736232 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.main.js @@ -0,0 +1,327 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var snancusumkbn = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof snancusumkbn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( snancusumkbn.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the cumulative sum (ignoring NaN values)', function test( t ) { + var expected; + var x; + var y; + var i; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, NaN ] ); + y = new Float32Array( x.length ); + + snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + expected = new Float32Array([ + 1.0, + 3.0, + 6.0, + 10.0, + 10.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0, NaN, 4.0, 5.0 ] ); + y = new Float32Array( x.length ); + + snancusumkbn( x.length, 10.0, x, 1, y, 1 ); + expected = new Float32Array([ + 11.0, + 13.0, + 13.0, + 17.0, + 22.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + y = new Float32Array( x.length ); + snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + + expected = new Float32Array([ + 0.0, + 0.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, NaN, 3.0, NaN ] ); + y = new Float32Array( x.length ); + snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + + expected = new Float32Array([ + 1.0, + 1.0, + 4.0, + 4.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 1.0e38, NaN, -1.0e38 ] ); + y = new Float32Array( x.length ); + snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + + expected = new Float32Array([ + 1.0, + 1.0e38, + 1.0e38, + 1.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( 1e3 ); + y = new Float32Array( x.length ); + expected = new Float32Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i + 1; + if ( i === 0 ) { + expected[ i ] += x[ i ]; + } else { + expected[ i ] += expected[ i-1 ] + x[ i ]; + } + } + snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = snancusumkbn( x.length, 0.0, x, 1, y, 1 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + snancusumkbn( -1, 0.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + snancusumkbn( 0, 0.0, x, 1, y, 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + NaN, + NaN // 3 + ]); + y = new Float32Array([ + 0.0, // 0 + 0.0, // 1 + 0.0, // 2 + 0.0, // 3 + 0.0, + 0.0, + 0.0 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, 2, y, 1 ); + + expected = new Float32Array( [ 1.0, 4.0, 9.0, 9.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 5.0, // 2 + NaN, // 3 + NaN, + 3.0, + 4.0 + ]); + y = new Float32Array([ + 0.0, // 0 + 0.0, + 0.0, // 1 + 0.0, + 0.0, // 2 + 0.0, + 0.0 // 3 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, 1, y, 2 ); + + expected = new Float32Array( [ 1.0, 0.0, 3.0, 0.0, 8.0, 0.0, 8.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 3 + 1.0, + NaN, // 2 + 2.0, + NaN, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float32Array([ + 0.0, // 3 + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 0.0, + 0.0 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, -2, y, -1 ); + + expected = new Float32Array( [ 6.0, 5.0, 5.0, 5.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + NaN, + NaN, // 1 + NaN, + 5.0, // 2 + 6.0 + ]); + y = new Float32Array([ + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 0.0, + 0.0, + 0.0 + ]); + N = 3; + + snancusumkbn( N, 0.0, x, 2, y, -1 ); + + expected = new Float32Array( [ 6.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var y0; + var x1; + var y1; + var N; + + // Initial arrays... + x0 = new Float32Array([ + 1.0, + NaN, // 2 + NaN, + 4.0, // 1 + 5.0, + 6.0 // 0 + ]); + y0 = new Float32Array([ + 0.0, + 0.0, + 0.0, + 0.0, // 0 + 0.0, // 1 + 0.0 // 2 + ]); + + // Create offset views... + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element + + N = 3; + + snancusumkbn( N, 0.0, x1, -2, y1, 1 ); + expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 10.0 ] ); + + t.deepEqual( y0, expected, 'deep equal' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.ndarray.js new file mode 100644 index 000000000000..addfd7394158 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/snancusumkbn/test/test.ndarray.js @@ -0,0 +1,360 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var snancusumkbn = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof snancusumkbn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( snancusumkbn.length, 8, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the cumulative sum (ignoring NaN values)', function test( t ) { + var expected; + var x; + var y; + var i; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, NaN ] ); + y = new Float32Array( x.length ); + + snancusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + expected = new Float32Array([ + 1.0, + 3.0, + 6.0, + 10.0, + 10.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 2.0, NaN, 4.0, 5.0 ] ); + y = new Float32Array( x.length ); + + snancusumkbn( x.length, 10.0, x, 1, 0, y, 1, 0 ); + expected = new Float32Array([ + 11.0, + 13.0, + 13.0, + 17.0, + 22.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + y = new Float32Array( x.length ); + snancusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + + expected = new Float32Array([ + 0.0, + 0.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, NaN, 3.0, NaN ] ); + y = new Float32Array( x.length ); + snancusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + + expected = new Float32Array([ + 1.0, + 1.0, + 4.0, + 4.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( [ 1.0, 1.0e38, NaN, -1.0e38 ] ); + y = new Float32Array( x.length ); + snancusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + + expected = new Float32Array([ + 1.0, + 1.0e38, + 1.0e38, + 1.0 + ]); + t.deepEqual( y, expected, 'returns expected value' ); + + x = new Float32Array( 1e3 ); + y = new Float32Array( x.length ); + expected = new Float32Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i + 1; + if ( i === 0 ) { + expected[ i ] += x[ i ]; + } else { + expected[ i ] += expected[ i-1 ] + x[ i ]; + } + } + snancusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = snancusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var x; + var y; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + expected = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + snancusumkbn( -1, 0.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + snancusumkbn( 0, 0.0, x, 1, 0, y, 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + NaN, + NaN // 3 + ]); + y = new Float32Array([ + 0.0, // 0 + 0.0, // 1 + 0.0, // 2 + 0.0, // 3 + 0.0, + 0.0, + 0.0 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, 2, 0, y, 1, 0 ); + + expected = new Float32Array( [ 1.0, 4.0, 9.0, 9.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + 2.0, // 1 + 5.0, // 2 + NaN, // 3 + NaN, + 3.0, + 4.0 + ]); + y = new Float32Array([ + 0.0, // 0 + 0.0, + 0.0, // 1 + 0.0, + 0.0, // 2 + 0.0, + 0.0 // 3 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, 1, 0, y, 2, 0 ); + + expected = new Float32Array( [ 1.0, 0.0, 3.0, 0.0, 8.0, 0.0, 8.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 3 + 1.0, + NaN, // 2 + 2.0, + NaN, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float32Array([ + 0.0, // 3 + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 0.0, + 0.0 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, -2, x.length-1, y, -1, 3 ); + + expected = new Float32Array( [ 6.0, 5.0, 5.0, 5.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var N; + var x; + var y; + + x = new Float32Array([ + 2.0, + NaN, // 0 + 2.0, + -2.0, // 1 + -2.0, + NaN, // 2 + 3.0, + 4.0 // 3 + ]); + y = new Float32Array([ + 0.0, // 0 + 0.0, // 1 + 0.0, // 2 + 0.0, // 3 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); + + expected = new Float32Array( [ 0.0, -2.0, -2.0, 2.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var expected; + var N; + var x; + var y; + + x = new Float32Array([ + NaN, // 0 + NaN, // 1 + 2.0, // 2 + -2.0, // 3 + -2.0, + 2.0, + 3.0, + 4.0 + ]); + y = new Float32Array([ + 0.0, + 0.0, // 0 + 0.0, + 0.0, // 1 + 0.0, + 0.0, // 2 + 0.0, + 0.0 // 3 + ]); + N = 4; + + snancusumkbn( N, 0.0, x, 1, 0, y, 2, 1 ); + + expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var x; + var y; + var N; + + x = new Float32Array([ + 1.0, // 0 + NaN, + NaN, // 1 + NaN, + 5.0, // 2 + 6.0 + ]); + y = new Float32Array([ + 0.0, // 2 + 0.0, // 1 + 0.0, // 0 + 0.0, + 0.0, + 0.0 + ]); + N = 3; + + snancusumkbn( N, 0.0, x, 2, 0, y, -1, 2 ); + + expected = new Float32Array( [ 6.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( y, expected, 'returns expected value' ); + t.end(); +});