Skip to content
Closed
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
65 changes: 27 additions & 38 deletions lib/node_modules/@stdlib/stats/base/nanmskmin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2020 The Stdlib Authors.
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.
Expand Down Expand Up @@ -52,20 +52,18 @@ The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideX**: index increment for `x`.
- **strideX**: stride length for `x`.
- **mask**: mask [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and **excluded** from computation.
- **strideMask**: index increment for `mask`.
- **strideMask**: stride length for `mask`.

The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the minimum value of every other element in `x`,
The `N` and `stride` parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the minimum value of every other element in `x`,

```javascript
var floor = require( '@stdlib/math/base/special/floor' );

var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, -5.0, -6.0 ];
var mask = [ 0, 0, 0, 0, 0, 0, 1, 1 ];
var N = floor( x.length / 2 );

var v = nanmskmin( N, x, 2, mask, 2 );

var v = nanmskmin( 4, x, 2, mask, 2 );
// returns -7.0
```

Expand All @@ -76,17 +74,16 @@ Note that indexing is relative to the first index. To introduce offsets, use [`t
```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );
var floor = require( '@stdlib/math/base/special/floor' );


var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var N = floor( x0.length / 2 );

var v = nanmskmin( N, x1, 2, mask1, 2 );
var v = nanmskmin( 4, x1, 2, mask1, 2 );
// returns -2.0
```

Expand All @@ -107,16 +104,15 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetMask**: starting index for `mask`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the minimum value for every other value in `x` starting from the second value
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset
indexing semantics based on
starting indices. For example, to calculate the minimum value for every other value in `x` starting from the second value

```javascript
var floor = require( '@stdlib/math/base/special/floor' );

var x = [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, -5.0, -6.0 ];
var mask = [ 0, 0, 0, 0, 0, 0, 1, 1 ];
var N = floor( x.length / 2 );

var v = nanmskmin.ndarray( N, x, 2, 1, mask, 2, 1 );
var v = nanmskmin.ndarray( 4, x, 2, 1, mask, 2, 1 );
// returns -2.0
```

Expand All @@ -130,6 +126,8 @@ var v = nanmskmin.ndarray( N, x, 2, 1, mask, 2, 1 );

- If `N <= 0`, both functions return `NaN`.
- Depending on the environment, the typed versions ([`dnanmskmin`][@stdlib/stats/base/dnanmskmin], [`snanmskmin`][@stdlib/stats/base/snanmskmin], etc.) are likely to be significantly more performant.
- 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]).


</section>

Expand All @@ -142,31 +140,18 @@ var v = nanmskmin.ndarray( N, x, 2, 1, mask, 2, 1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );
var uniform = require( '@stdlib/random/array/uniform' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var nanmskmin = require( '@stdlib/stats/base/nanmskmin' );

var mask;
var x;
var i;

x = new Float64Array( 10 );
mask = new Uint8Array( x.length );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
mask[ i ] = 1;
} else {
mask[ i ] = 0;
}
if ( randu() < 0.1 ) {
x[ i ] = NaN;
} else {
x[ i ] = round( (randu()*100.0) - 50.0 );
}
}
var x = uniform( 10, -50.0, 50.0, {
'dtype': 'float64'
});
console.log( x );

var mask = bernoulli( x.length, 0.2, {
'dtype': 'uint8'
});
console.log( mask );

var v = nanmskmin( x.length, x, 1, mask, 1 );
Expand Down Expand Up @@ -201,6 +186,10 @@ console.log( v );

[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array


[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor


[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

<!-- <related-links> -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* 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.
Expand All @@ -21,13 +21,21 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var nanmskmin = require( './../lib/nanmskmin.js' );


// VARIABLES //

var options = {
'dtype': 'generic'
};


// FUNCTIONS //

/**
Expand All @@ -38,20 +46,8 @@ var nanmskmin = require( './../lib/nanmskmin.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var mask;
var x;
var i;

x = [];
mask = [];
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
mask.push( 1 );
} else {
mask.push( 0 );
}
x.push( ( randu()*20.0 ) - 10.0 );
}
var mask = bernoulli( len, 0.2, options );
var x = uniform( len, -10.0, 10.0, options );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* 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.
Expand All @@ -21,13 +21,21 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var nanmskmin = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
'dtype': 'generic'
};


// FUNCTIONS //

/**
Expand All @@ -38,20 +46,8 @@ var nanmskmin = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var mask;
var x;
var i;

x = [];
mask = [];
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
mask.push( 1 );
} else {
mask.push( 0 );
}
x.push( ( randu()*20.0 ) - 10.0 );
}
var mask = bernoulli( len, 0.2, options );
var x = uniform( len, -10.0, 10.0, options );
return benchmark;

function benchmark( b ) {
Expand Down
24 changes: 10 additions & 14 deletions lib/node_modules/@stdlib/stats/base/nanmskmin/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the minimum value of a strided array according to a mask and
ignoring `NaN` values.

The `N` and `stride` parameters determine which elements are accessed at
runtime.
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 offsets, use a typed
array views.
Expand All @@ -26,13 +26,13 @@
Input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

mask: Array<number>|TypedArray
Mask array.

strideMask: integer
Index increment for `mask`.
Stride length for `mask`.

Returns
-------
Expand All @@ -47,20 +47,17 @@
> {{alias}}( x.length, x, 1, mask, 1 )
-2.0

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, -4.0 ];
> mask = [ 0, 0, 0, 0, 0, 0, 1 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, x, 2, mask, 2 )
> {{alias}}( 3, x, 2, mask, 2 )
-2.0

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, -4.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var mask0 = new {{alias:@stdlib/array/uint8}}( [ 0, 0, 0, 0, 0, 0, 1 ] );
> var mask1 = new {{alias:@stdlib/array/uint8}}( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> {{alias}}( N, x1, 2, mask1, 2 )
>{{alias}}( 3, x1, 2, mask1, 2 )
-2.0

{{alias}}.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask )
Expand All @@ -80,7 +77,7 @@
Input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

offsetX: integer
Starting index for `x`.
Expand All @@ -89,7 +86,7 @@
Mask array.

strideMask: integer
Index increment for `mask`.
Stride length for `mask`.

offsetMask: integer
Starting index for `mask`.
Expand All @@ -110,8 +107,7 @@
// Using offset parameter:
> x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, -4.0 ];
> mask = [ 0, 0, 0, 0, 0, 0, 1 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, x, 2, 1, mask, 2, 1 )
> {{alias}}.ndarray( 3, x, 2, 1, mask, 2, 1 )
-2.0

See Also
Expand Down
Loading
Loading