Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions lib/node_modules/@stdlib/stats/incr/nanminmaxabs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!--

@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.

-->

# incrnanminmaxabs

> Compute minimum and maximum absolute values incrementally, ignoring `NaN` values.

<section class="usage">

## Usage

```javascript
var incrnanminmaxabs = require( '@stdlib/stats/incr/nanminmaxabs' );
```

#### incrnanminmaxabs( \[out] )

Returns an accumulator `function` which incrementally computes minimum and maximum absolute values, ignoring `NaN` values.

```javascript
var accumulator = incrnanminmaxabs();
```

By default, the returned accumulator `function` returns the minimum and maximum absolute values as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var accumulator = incrnanminmaxabs( new Float64Array( 2 ) );
```

#### accumulator( \[x] )

If provided an input value `x`, the accumulator function returns updated minimum and maximum absolute values. If not provided an input value `x`, the accumulator function returns the current minimum and maximum absolute values.

```javascript
var accumulator = incrnanminmaxabs();

var mm = accumulator();
// returns null

mm = accumulator( 2.0 );
// returns [ 2.0, 2.0 ]

mm = accumulator( NaN );
// returns [ 2.0, 2.0 ]

mm = accumulator( 1.0 );
// returns [ 1.0, 2.0 ]

mm = accumulator( 3.0 );
// returns [ 1.0, 3.0 ]

mm = accumulator( -7.0 );
// returns [ 1.0, 7.0 ]

mm = accumulator();
// returns [ 1.0, 7.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Input values are **not** type checked. If provided `NaN`, the value is **ignored** and does **not** affect the accumulated result. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var incrnanminmaxabs = require( '@stdlib/stats/incr/nanminmaxabs' );

// Initialize an accumulator:
var accumulator = incrnanminmaxabs();

// For each simulated datum, update the minimum and maximum absolute values...
var i;
for ( i = 0; i < 100; i++ ) {
accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -50.0, 50.0 ) );
}
console.log( accumulator() );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/base/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var incrnanminmaxabs = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var f;
var i;
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
f = incrnanminmaxabs();
if ( typeof f !== 'function' ) {
b.fail( 'should return a function' );
}
}
b.toc();
if ( typeof f !== 'function' ) {
b.fail( 'should return a function' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::accumulator', pkg ), function benchmark( b ) {
var acc;
var x;
var v;
var i;

acc = incrnanminmaxabs();

x = new Float64Array( b.iterations );
for ( i = 0; i < b.iterations; i++ ) {
if ( ( i & 7 ) === 7 ) {
x[ i ] = NaN;
} else {
x[ i ] = uniform( -100.0, 100.0 );
}
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = acc( x[ i ] );
if ( v !== null && v.length !== 2 ) {
b.fail( 'should contain two elements' );
}
}
b.toc();
if ( v[ 0 ] !== v[ 0 ] || v[ 1 ] !== v[ 1 ] ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
40 changes: 40 additions & 0 deletions lib/node_modules/@stdlib/stats/incr/nanminmaxabs/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

{{alias}}( [out] )
Returns an accumulator function which incrementally computes a minimum and
maximum absolute value, ignoring `NaN` values.

If provided a value, the accumulator function returns an updated minimum
and maximum. If not provided a value, the accumulator function returns the
current minimum and maximum.

Any `NaN` values provided to the accumulator are ignored, and do not
affect the accumulated result.

Parameters
----------
out: Array|TypedArray (optional)
Output array.

Returns
-------
acc: Function
Accumulator function.

Examples
--------
> var accumulator = {{alias}}();
> var mm = accumulator()
null
> mm = accumulator( 2.0 );
> mm = accumulator( -5.0 )
[ 2.0, 5.0 ]
> mm = accumulator( NaN )
[ 2.0, 5.0 ]
> mm = accumulator( 3.0 )
[ 2.0, 5.0 ]
> mm = accumulator()
[ 2.0, 5.0 ]

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { ArrayLike } from '@stdlib/types/array';

/**
* If provided a value, the accumulator function returns updated minimum and maximum absolute values. If not provided a value, the accumulator function returns the current minimum and maximum absolute values.
*
* ## Notes
*
* - If provided `NaN`, the value is ignored and does not affect the accumulated result.
*
* @param x - input value
* @returns output array or null
*/
type accumulator = ( x?: number ) => ArrayLike<number> | null;

/**
* Returns an accumulator function which incrementally computes minimum and maximum absolute values, ignoring `NaN` values.
*
* @param out - output array
* @returns accumulator function
*
* @example
* var accumulator = incrnanminmaxabs();
*
* var mm = accumulator();
* // returns null
*
* mm = accumulator( 2.0 );
* // returns [ 2.0, 2.0 ]
*
* mm = accumulator( NaN );
* // returns [ 2.0, 2.0 ]
*
* mm = accumulator( -5.0 );
* // returns [ 2.0, 5.0 ]
*
* mm = accumulator( 3.0 );
* // returns [ 2.0, 5.0 ]
*
* mm = accumulator();
* // returns [ 2.0, 5.0 ]
*/
declare function incrnanminmaxabs( out?: ArrayLike<number> ): accumulator;


// EXPORTS //

export = incrnanminmaxabs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* @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 incrnanminmaxabs = require( './index' );


// TESTS //

// The function returns an accumulator function...
{
incrnanminmaxabs(); // $ExpectType accumulator
const out = [ 0.0, 0.0 ];
incrnanminmaxabs( out ); // $ExpectType accumulator
}

// The compiler throws an error if the function is provided an argument that is not an array-like object of numbers...
{
incrnanminmaxabs( '5' ); // $ExpectError
incrnanminmaxabs( 5 ); // $ExpectError
incrnanminmaxabs( true ); // $ExpectError
incrnanminmaxabs( false ); // $ExpectError
incrnanminmaxabs( null ); // $ExpectError
incrnanminmaxabs( {} ); // $ExpectError
incrnanminmaxabs( ( x: number ): number => x ); // $ExpectError
}

// The function returns an accumulator function which returns an accumulated result...
{
const acc = incrnanminmaxabs();

acc(); // $ExpectType ArrayLike<number> | null
acc( 3.14 ); // $ExpectType ArrayLike<number> | null
}

// The compiler throws an error if the returned accumulator function is provided invalid arguments...
{
const acc = incrnanminmaxabs();

acc( '5' ); // $ExpectError
acc( true ); // $ExpectError
acc( false ); // $ExpectError
acc( null ); // $ExpectError
acc( [] ); // $ExpectError
acc( {} ); // $ExpectError
acc( ( x: number ): number => x ); // $ExpectError
}
Loading
Loading