From b303abc77cdbbba9cc826eaf247063532868b89a Mon Sep 17 00:00:00 2001 From: Partha Das Date: Sun, 5 Apr 2026 18:11:01 +0600 Subject: [PATCH] feat: add stats/strided/nancumax --- .../@stdlib/stats/strided/nancumax/README.md | 185 +++++++++++++ .../strided/nancumax/benchmark/benchmark.js | 112 ++++++++ .../nancumax/benchmark/benchmark.ndarray.js | 112 ++++++++ .../stats/strided/nancumax/docs/repl.txt | 110 ++++++++ .../strided/nancumax/docs/types/index.d.ts | 109 ++++++++ .../stats/strided/nancumax/docs/types/test.ts | 247 ++++++++++++++++++ .../stats/strided/nancumax/examples/index.js | 41 +++ .../stats/strided/nancumax/lib/accessors.js | 99 +++++++ .../stats/strided/nancumax/lib/index.js | 59 +++++ .../stats/strided/nancumax/lib/main.js | 53 ++++ .../stats/strided/nancumax/lib/ndarray.js | 88 +++++++ .../stats/strided/nancumax/package.json | 71 +++++ .../stats/strided/nancumax/test/test.js | 38 +++ .../stats/strided/nancumax/test/test.main.js | 224 ++++++++++++++++ .../strided/nancumax/test/test.ndarray.js | 223 ++++++++++++++++ 15 files changed, 1771 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/nancumax/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/README.md b/lib/node_modules/@stdlib/stats/strided/nancumax/README.md new file mode 100644 index 000000000000..6e64fc0b1e0c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/README.md @@ -0,0 +1,185 @@ + + +# nancumax + +> Calculate the cumulative maximum of a strided array, ignoring `NaN` values. + +
+ +
+ + + +
+ +## Usage + +```javascript +var nancumax = require( '@stdlib/stats/strided/nancumax' ); +``` + +#### nancumax( N, x, strideX, y, strideY ) + +Computes the cumulative maximum of a strided array `x`, ignoring `NaN` values. + +```javascript +var x = [ 1.0, -2.0, NaN, 2.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0 ]; + +var v = nancumax( x.length, x, 1, y, 1 ); +// returns [ 1.0, 1.0, 1.0, 2.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **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 maximum of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ]; +var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +var v = nancumax( 5, x, 2, y, 1 ); +// returns [ 1.0, 2.0, 2.0, 4.0, 4.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' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, NaN, NaN, 4.0 ] ); +var y0 = new Float64Array( 4 ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*0 ); + +var v = nancumax( 4, x1, 2, y1, 1 ); +// returns [ 1.0, 1.0, 1.0, 4.0 ] +``` + +#### nancumax.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Computes the cumulative maximum of a strided array, ignoring `NaN` values and using alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, NaN, 2.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0 ]; + +var v = nancumax.ndarray( x.length, x, 1, 0, y, 1, 0 ); +// returns [ 1.0, 1.0, 1.0, 2.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 a starting index. For example, to calculate the cumulative maximum for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, NaN, NaN, 2.0, 3.0, 4.0 ]; +var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +var v = nancumax.ndarray( 5, x, 2, 1, y, 1, 0 ); +// returns [ 1.0, 1.0, 1.0, 2.0, 4.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the output array unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var zeros = require( '@stdlib/array/zeros' ); +var nancumax = require( '@stdlib/stats/strided/nancumax' ); + +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +var x = filledarrayBy( 10, 'float64', rand ); +console.log( x ); + +var y = zeros( 10, 'float64' ); +console.log( y ); + +var v = nancumax( x.length, x, 1, y, 1 ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.js new file mode 100644 index 000000000000..47f1c60ac2f6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var nancumax = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filledarrayBy( len, 'generic', rand ); + var y = zeros( len, 'generic' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = nancumax( x.length, x, 1, y, 1 ); + if ( isnan( v[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ 0 ] ) ) { + 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/stats/strided/nancumax/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..cec56a702aad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.ndarray.js @@ -0,0 +1,112 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var nancumax = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filledarrayBy( len, 'generic', rand ); + var y = zeros( len, 'generic' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = nancumax( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( v[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ 0 ] ) ) { + 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/stats/strided/nancumax/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/nancumax/docs/repl.txt new file mode 100644 index 000000000000..2de2967556ca --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/docs/repl.txt @@ -0,0 +1,110 @@ + +{{alias}}( N, x, strideX, y, strideY ) + Computes the cumulative maximum of a strided array, ignoring `NaN` values. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns the output array unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + y: Array|TypedArray + Output array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, NaN, 2.0 ]; + > var y = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( x.length, x, 1, y, 1 ) + [ 1.0, 1.0, 1.0, 2.0 ] + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ]; + > y = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 4, x, 2, y, 1 ) + [ -2, 1, 2, 2 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( 4 ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*0 ); + > {{alias}}( 4, x1, 2, y1, 1 ) + [ -2.0, 2.0, 2.0, 2.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Computes the cumulative maximum of a strided array, ignoring `NaN` values + and using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Array|TypedArray + Output array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + out: Array|TypedArray + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, NaN, 2.0 ]; + > var y = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + [ 1.0, 1.0, 1.0, 2.0 ] + + // Using offset parameter: + > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ]; + > var y = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 4, x, 2, 1, y, 1, 0 ) + [ -2.0, 2.0, 2.0, 2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/index.d.ts new file mode 100644 index 000000000000..82ebbfba6dee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/index.d.ts @@ -0,0 +1,109 @@ +/* +* @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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `nancumax`. +*/ +interface Routine { + /** + * Computes the cumulative maximum of a strided array, ignoring `NaN` values. + * + * @param N - number of indexed elements + * @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 x = [ 1.0, -2.0, NaN, 2.0 ]; + * var y = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * var v = nancumax( x.length, x, 1, y, 1 ); + * // returns [ 1.0, 1.0, 1.0, 2.0 ] + */ + ( N: number, x: InputArray, strideX: number, y: OutputArray, strideY: number ): OutputArray; + + /** + * Computes the cumulative maximum of a strided array, ignoring `NaN` values and 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 y - output array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @returns output array + * + * @example + * var x = [ 1.0, -2.0, NaN, 2.0 ]; + * var y = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * var v = nancumax.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * // returns [ 1.0, 1.0, 1.0, 2.0 ] + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, y: OutputArray, strideY: number, offsetY: number ): OutputArray; +} + +/** +* Computes the cumulative maximum of a strided array, ignoring `NaN` values. +* +* @param N - number of indexed elements +* @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 x = [ 1.0, -2.0, NaN, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* var v = nancumax( x.length, x, 1, y, 1 ); +* // returns [ 1.0, 1.0, 1.0, 2.0 ] +* +* @example +* var x = [ 1.0, -2.0, NaN, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* var v = nancumax.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns [ 1.0, 1.0, 1.0, 2.0 ] +*/ +declare var nancumax: Routine; + + +// EXPORTS // + +export = nancumax; diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/test.ts new file mode 100644 index 000000000000..2f8b17088124 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/test.ts @@ -0,0 +1,247 @@ +/* +* @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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import nancumax = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax( x.length, x, 1, y, 1 ); // $ExpectType OutputArray + nancumax( x.length, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax( '10', x, 1, y, 1 ); // $ExpectError + nancumax( true, x, 1, y, 1 ); // $ExpectError + nancumax( false, x, 1, y, 1 ); // $ExpectError + nancumax( null, x, 1, y, 1 ); // $ExpectError + nancumax( undefined, x, 1, y, 1 ); // $ExpectError + nancumax( [], x, 1, y, 1 ); // $ExpectError + nancumax( {}, x, 1, y, 1 ); // $ExpectError + nancumax( ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax( x.length, 10, 1, y, 1 ); // $ExpectError + nancumax( x.length, '10', 1, y, 1 ); // $ExpectError + nancumax( x.length, true, 1, y, 1 ); // $ExpectError + nancumax( x.length, false, 1, y, 1 ); // $ExpectError + nancumax( x.length, null, 1, y, 1 ); // $ExpectError + nancumax( x.length, undefined, 1, y, 1 ); // $ExpectError + nancumax( x.length, {}, 1, y, 1 ); // $ExpectError + nancumax( x.length, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax( x.length, x, '10', y, 1 ); // $ExpectError + nancumax( x.length, x, true, y, 1 ); // $ExpectError + nancumax( x.length, x, false, y, 1 ); // $ExpectError + nancumax( x.length, x, null, y, 1 ); // $ExpectError + nancumax( x.length, x, undefined, y, 1 ); // $ExpectError + nancumax( x.length, x, [], y, 1 ); // $ExpectError + nancumax( x.length, x, {}, y, 1 ); // $ExpectError + nancumax( x.length, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + nancumax( x.length, x, 1, 10, 1 ); // $ExpectError + nancumax( x.length, x, 1, '10', 1 ); // $ExpectError + nancumax( x.length, x, 1, true, 1 ); // $ExpectError + nancumax( x.length, x, 1, false, 1 ); // $ExpectError + nancumax( x.length, x, 1, null, 1 ); // $ExpectError + nancumax( x.length, x, 1, undefined, 1 ); // $ExpectError + nancumax( x.length, x, 1, {}, 1 ); // $ExpectError + nancumax( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax( x.length, x, 1, y, '10' ); // $ExpectError + nancumax( x.length, x, 1, y, true ); // $ExpectError + nancumax( x.length, x, 1, y, false ); // $ExpectError + nancumax( x.length, x, 1, y, null ); // $ExpectError + nancumax( x.length, x, 1, y, undefined ); // $ExpectError + nancumax( x.length, x, 1, y, [] ); // $ExpectError + nancumax( x.length, x, 1, y, {} ); // $ExpectError + nancumax( x.length, 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 Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax(); // $ExpectError + nancumax( x.length ); // $ExpectError + nancumax( x.length, x ); // $ExpectError + nancumax( x.length, x, 1 ); // $ExpectError + nancumax( x.length, x, 1, y ); // $ExpectError + nancumax( x.length, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns an array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType OutputArray + nancumax.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType OutputArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( '10', x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( [], x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( ( x: number ): number => x, 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 numeric array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( x.length, 10, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, '10', 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, ( x: number ): number => 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 number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( x.length, x, '10', 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, undefined, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, [], 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, ( x: number ): number => x, 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 Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( x.length, x, 1, '10', y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, undefined, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, [], y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + nancumax.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( x.length, x, 1, 0, y, '10', 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, undefined, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, [], 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray( x.length, x, 1, 0, y, 1, '10' ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, undefined ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, [] ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError + nancumax.ndarray( x.length, 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 Float64Array( 10 ); + const y = new Float64Array( 10 ); + + nancumax.ndarray(); // $ExpectError + nancumax.ndarray( x.length ); // $ExpectError + nancumax.ndarray( x.length, x ); // $ExpectError + nancumax.ndarray( x.length, x, 1 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + nancumax.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/examples/index.js b/lib/node_modules/@stdlib/stats/strided/nancumax/examples/index.js new file mode 100644 index 000000000000..c73867718c3c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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 uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var zeros = require( '@stdlib/array/zeros' ); +var nancumax = require( './../lib' ); + +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +var x = filledarrayBy( 10, 'float64', rand ); +console.log( x ); + +var y = zeros( 10, 'float64' ); +console.log( y ); + +var v = nancumax( x.length, x, 1, y, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/accessors.js new file mode 100644 index 000000000000..0f8848c4e227 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/accessors.js @@ -0,0 +1,99 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); + + +// MAIN // + +/** +* Computes the cumulative maximum of a strided array, ignoring `NaN` values. +* +* @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 +* @param {NonNegativeInteger} offsetX - starting index +* @param {Object} y - output array object +* @param {Collection} y.data - output array data +* @param {Array} y.accessors - array element accessors +* @param {integer} strideY - stride length +* @param {NonNegativeInteger} offsetY - starting index +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, NaN, 4.0 ] ); +* var y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* var v = nancumax( 6, arraylike2object( x ), 1, 0, arraylike2object( y ), 1, 0 ); +* // returns +*/ +function nancumax( N, x, strideX, offsetX, y, strideY, offsetY ) { + var xbuf; + var ybuf; + var xget; + var yset; + var max; + var ix; + var iy; + var v; + var i; + + // Cache references to array data: + xbuf = x.data; + ybuf = y.data; + + // Cache references to element accessors: + xget = x.accessors[ 0 ]; + yset = y.accessors[ 1 ]; + + if ( N <= 0 ) { + return y; + } + ix = offsetX; + iy = offsetY; + max = -Infinity; + + for ( i = 0; i < N; i++ ) { + v = xget( xbuf, ix ); + if ( isnan( v ) === false ) { + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + yset( ybuf, iy, max ); + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = nancumax; diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/lib/index.js b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/index.js new file mode 100644 index 000000000000..537f878d8d62 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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'; + +/** +* Compute the cumulative maximum of a strided array, ignoring `NaN` values. +* +* @module @stdlib/stats/strided/nancumax +* +* @example +* var nancumax = require( '@stdlib/stats/strided/nancumax' ); +* +* var x = [ 1.0, -2.0, NaN, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* var v = nancumax( x.length, x, 1, y, 1 ); +* // returns [ 1.0, 1.0, 1.0, 2.0 ] +* +* @example +* var nancumax = require( '@stdlib/stats/strided/nancumax' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, NaN, 2.0, 3.0, 4.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* var v = nancumax.ndarray( 4, x, 2, 1, y, 1, 0 ); +* // returns [ 1.0, 1.0, 2.0, 4.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/stats/strided/nancumax/lib/main.js b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/main.js new file mode 100644 index 000000000000..78f9edacb8f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/main.js @@ -0,0 +1,53 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the cumulative maximum of a strided array, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NumericArray} y - output array +* @param {integer} strideY - stride length +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, -2.0, NaN, 2.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* var v = nancumax( x.length, x, 1, y, 1 ); +* // returns [ 1.0, 1.0, 1.0, 2.0 ] +*/ +function nancumax( N, x, strideX, y, strideY ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); +} + + +// EXPORTS // + +module.exports = nancumax; diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/ndarray.js new file mode 100644 index 000000000000..0f217880b9dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/lib/ndarray.js @@ -0,0 +1,88 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the cumulative maximum of a strided array, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {NumericArray} y - output array +* @param {integer} strideY - stride length +* @param {NonNegativeInteger} offsetY - starting index +* @returns {NumericArray} output array +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, NaN, 4.0 ]; +* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* var v = nancumax( 6, x, 1, 0, y, 1, 0 ); +* // returns [ 2.0, 2.0, 2.0, 2.0, 2.0, 4.0 ] +*/ +function nancumax( N, x, strideX, offsetX, y, strideY, offsetY ) { + var max; + var ix; + var iy; + var ox; + var oy; + var v; + var i; + + if ( N <= 0 ) { + return y; + } + ox = arraylike2object( x ); + oy = arraylike2object( y ); + if ( ox.accessorProtocol || oy.accessorProtocol ) { + return accessors( N, ox, strideX, offsetX, oy, strideY, offsetY ); + } + ix = offsetX; + iy = offsetY; + max = -Infinity; + + for ( i = 0; i < N; i++ ) { + v = x[ ix ]; + if ( isnan( v ) === false ) { + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + y[ iy ] = max; + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = nancumax; diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/package.json b/lib/node_modules/@stdlib/stats/strided/nancumax/package.json new file mode 100644 index 000000000000..70f19bc0f255 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/strided/nancumax", + "version": "0.0.0", + "description": "Calculate the cumulative maximum of a strided array, 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", + "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", + "maximum", + "max", + "range", + "extremes", + "domain", + "extent", + "accumulate", + "cumulative", + "strided", + "strided array", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.js b/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.js new file mode 100644 index 000000000000..13ee5e11cb7d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/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 nancumax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nancumax, '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 nancumax.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.main.js new file mode 100644 index 000000000000..f21b0b56c072 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.main.js @@ -0,0 +1,224 @@ +/** +* @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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var nancumax = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nancumax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( nancumax.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the cumulative maximum of a strided array', function test( t ) { + var x; + var y; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, x, 1, y, 1 ); + t.deepEqual( v, [ 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0 ], 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + y = [ 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, x, 1, y, 1 ); + t.deepEqual( v, [ -4.0, -4.0, -4.0 ], 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, x, 1, y, 1 ); + t.strictEqual( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum of a strided array (accessors)', function test( t ) { + var x; + var y; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + y = [ 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + + 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 x; + var y; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 0, x, 1, y, 1 ); + t.deepEqual( v, [ 0.0, 0.0, 0.0, 0.0, 0.0 ], 'returns expected value' ); + + v = nancumax( -1, x, 1, y, 1 ); + t.deepEqual( v, [ 0.0, 0.0, 0.0, 0.0, 0.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var y; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, x, 2, y, 1 ); + t.deepEqual( v, [ 1.0, 2.0, 2.0, 4.0, 4.0 ], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var y; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var y; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, x, -2, y, -1 ); + t.deepEqual( v, [ 4.0, 4.0, 4.0, 4.0, 4.0 ], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var y; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, toAccessorArray( x ), -2, toAccessorArray( y ), -1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var y0; + var y1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + NaN, + NaN // 4 + ]); + y0 = new Float64Array( 6 ); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + + v = nancumax( 5, x1, 2, y1, 1 ); + t.deepEqual( v, [ 1.0, 1.0, 2.0, 4.0, 4.0 ], 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.ndarray.js new file mode 100644 index 000000000000..37ffb0ea23e2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/nancumax/test/test.ndarray.js @@ -0,0 +1,223 @@ +/** +* @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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var nancumax = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nancumax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( nancumax.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the cumulative maximum of a strided array', function test( t ) { + var x; + var y; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, x, 1, y, 1 ); + t.deepEqual( v, [ 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0 ], 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + y = [ 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, x, 1, y, 1 ); + t.deepEqual( v, [ -4.0, -4.0, -4.0 ], 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, x, 1, y, 1 ); + t.strictEqual( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum of a strided array (accessors)', function test( t ) { + var x; + var y; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + y = [ 0.0, 0.0, 0.0 ]; + v = nancumax( x.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + + 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 x; + var y; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 0, x, 1, y, 1 ); + t.deepEqual( v, [ 0.0, 0.0, 0.0, 0.0, 0.0 ], 'returns expected value' ); + + v = nancumax( -1, x, 1, y, 1 ); + t.deepEqual( v, [ 0.0, 0.0, 0.0, 0.0, 0.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var y; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, x, 2, y, 1 ); + t.deepEqual( v, [ 1.0, 2.0, 2.0, 4.0, 4.0 ], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var y; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var y; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, x, -2, y, -1 ); + t.deepEqual( v, [ 4.0, 4.0, 4.0, 4.0, 4.0 ], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var y; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = nancumax( 5, toAccessorArray( x ), -2, toAccessorArray( y ), -1 ); + t.strictEqual( typeof v, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var y0; + var y1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + NaN, + NaN // 4 + ]); + y0 = new Float64Array( 6 ); + x1 = x0.subarray( 1 ); + y1 = y0.subarray( 1 ); + + v = nancumax( 5, x1, 2, y1, 1 ); + t.deepEqual( v, [ 1.0, 1.0, 2.0, 4.0, 4.0 ], 'returns expected value' ); + t.end(); +});