Skip to content

Commit 8f955ba

Browse files
committed
Auto-generated commit
1 parent 0734cda commit 8f955ba

File tree

11 files changed

+858
-0
lines changed

11 files changed

+858
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`3e95cb4`](https://github.com/stdlib-js/stdlib/commit/3e95cb456bbeabe21ae465e1207a6f3e4ecaef6f) - add `stats/base/ndarray/snanmskmax` [(#8738)](https://github.com/stdlib-js/stdlib/pull/8738)
1314
- [`9fd602c`](https://github.com/stdlib-js/stdlib/commit/9fd602c0962f9c7f2bcb3783b1b65aa9b8c517bc) - add `stats/base/ndarray/nanrange-by` [(#8737)](https://github.com/stdlib-js/stdlib/pull/8737)
1415
- [`1708e83`](https://github.com/stdlib-js/stdlib/commit/1708e83cf99c01a7b8294b82d993bf52cf9bd311) - add `stats/base/ndarray/nanmskmin` [(#8734)](https://github.com/stdlib-js/stdlib/pull/8734)
1516
- [`8e2937d`](https://github.com/stdlib-js/stdlib/commit/8e2937d8b29d34d294c62b64257070312e7d336e) - add `stats/base/ndarray/nanmskmax` [(#8732)](https://github.com/stdlib-js/stdlib/pull/8732)
@@ -3497,6 +3498,7 @@ A total of 557 issues were closed in this release:
34973498

34983499
<details>
34993500

3501+
- [`3e95cb4`](https://github.com/stdlib-js/stdlib/commit/3e95cb456bbeabe21ae465e1207a6f3e4ecaef6f) - **feat:** add `stats/base/ndarray/snanmskmax` [(#8738)](https://github.com/stdlib-js/stdlib/pull/8738) _(by Kaustubh Patange)_
35003502
- [`9fd602c`](https://github.com/stdlib-js/stdlib/commit/9fd602c0962f9c7f2bcb3783b1b65aa9b8c517bc) - **feat:** add `stats/base/ndarray/nanrange-by` [(#8737)](https://github.com/stdlib-js/stdlib/pull/8737) _(by Sachin Pangal)_
35013503
- [`1708e83`](https://github.com/stdlib-js/stdlib/commit/1708e83cf99c01a7b8294b82d993bf52cf9bd311) - **feat:** add `stats/base/ndarray/nanmskmin` [(#8734)](https://github.com/stdlib-js/stdlib/pull/8734) _(by Kaustubh Patange, Athan Reines)_
35023504
- [`8e2937d`](https://github.com/stdlib-js/stdlib/commit/8e2937d8b29d34d294c62b64257070312e7d336e) - **feat:** add `stats/base/ndarray/nanmskmax` [(#8732)](https://github.com/stdlib-js/stdlib/pull/8732) _(by Kaustubh Patange)_

base/ndarray/snanmskmax/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# snanmskmax
22+
23+
> Calculate the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var snanmskmax = require( '@stdlib/stats/base/ndarray/snanmskmax' );
37+
```
38+
39+
#### snanmskmax( arrays )
40+
41+
Computes the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values.
42+
43+
```javascript
44+
var Float32Array = require( '@stdlib/array/float32' );
45+
var Uint8Array = require( '@stdlib/array/uint8' );
46+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
47+
48+
var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] );
49+
var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
50+
51+
var maskbuf = new Uint8Array( [ 0, 0, 1, 0 ] );
52+
var mask = new ndarray( 'uint8', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' );
53+
54+
var v = snanmskmax( [ x, mask ] );
55+
// returns 2.0
56+
```
57+
58+
The function has the following parameters:
59+
60+
- **arrays**: array-like object containing an input ndarray and a mask ndarray.
61+
62+
If a `mask` array element is `0`, the corresponding element in the input ndarray is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in the input ndarray is considered invalid/missing and **excluded** from computation.
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<section class="notes">
69+
70+
## Notes
71+
72+
- If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`.
73+
74+
</section>
75+
76+
<!-- /.notes -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var uniform = require( '@stdlib/random/array/uniform' );
86+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
87+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
88+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
89+
var snanmskmax = require( '@stdlib/stats/base/ndarray/snanmskmax' );
90+
91+
var xbuf = uniform( 10, -50.0, 50.0, {
92+
'dtype': 'float32'
93+
});
94+
var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
95+
console.log( ndarray2array( x ) );
96+
97+
var maskbuf = bernoulli( xbuf.length, 0.2, {
98+
'dtype': 'uint8'
99+
});
100+
var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' );
101+
console.log( ndarray2array( mask ) );
102+
103+
var v = snanmskmax( [ x, mask ] );
104+
console.log( v );
105+
```
106+
107+
</section>
108+
109+
<!-- /.examples -->
110+
111+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
112+
113+
<section class="related">
114+
115+
</section>
116+
117+
<!-- /.related -->
118+
119+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
120+
121+
<section class="links">
122+
123+
</section>
124+
125+
<!-- /.links -->
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
29+
var pkg = require( './../package.json' ).name;
30+
var snanmskmax = require( './../lib' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float32'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} len - array length
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( len ) {
50+
var mask;
51+
var mbuf;
52+
var xbuf;
53+
var x;
54+
55+
xbuf = uniform( len, -100.0, 100.0, options );
56+
x = new ndarray( 'float32', xbuf, [ len ], [ 1 ], 0, 'row-major' );
57+
58+
mbuf = bernoulli( len, 0.2, {
59+
'dtype': 'uint8'
60+
});
61+
mask = new ndarray( 'uint8', mbuf, [ len ], [ 1 ], 0, 'row-major' );
62+
63+
return benchmark;
64+
65+
function benchmark( b ) {
66+
var v;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
xbuf[ i%len ] = i;
72+
v = snanmskmax( [ x, mask ] );
73+
if ( isnanf( v ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnanf( v ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var len;
96+
var min;
97+
var max;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
len = pow( 10, i );
106+
f = createBenchmark( len );
107+
bench( pkg+':len='+len, f );
108+
}
109+
}
110+
111+
main();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
{{alias}}( arrays )
3+
Computes the maximum value of a one-dimensional single-precision floating-
4+
point ndarray according to a mask.
5+
6+
If provided an empty ndarray or a mask with all elements set to `1`, the
7+
function returns `NaN`.
8+
9+
Parameters
10+
----------
11+
arrays: ArrayLikeObject<ndarray>
12+
Array-like object containing an input ndarray and a mask ndarray.
13+
14+
Returns
15+
-------
16+
out: number
17+
Maximum value.
18+
19+
Examples
20+
--------
21+
> var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 4.0, 2.0 ] );
22+
> var dt = 'float32';
23+
> var sh = [ xbuf.length ];
24+
> var sx = [ 1 ];
25+
> var ox = 0;
26+
> var ord = 'row-major';
27+
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
28+
> var mbuf = new {{alias:@stdlib/array/uint8}}( [ 0, 0, 1, 0 ] );
29+
> var mask = new {{alias:@stdlib/ndarray/ctor}}( 'uint8', mbuf, sh, sx, ox, ord );
30+
> {{alias}}( [ x, mask ] )
31+
2.0
32+
33+
See Also
34+
--------
35+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { float32ndarray, uint8ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Computes the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values.
27+
*
28+
* @param arrays - array-like object containing an input ndarray and a mask ndarray
29+
* @returns maximum value
30+
*
31+
* @example
32+
* var Float32Array = require( '@stdlib/array/float32' );
33+
* var Uint8Array = require( '@stdlib/array/uint8' );
34+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
35+
*
36+
* var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] );
37+
* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
38+
*
39+
* var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] );
40+
* var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' );
41+
*
42+
* var v = snanmskmax( [ x, mask ] );
43+
* // returns 2.0
44+
*/
45+
declare function snanmskmax( arrays: [ float32ndarray, uint8ndarray ] ): number;
46+
47+
48+
// EXPORTS //
49+
50+
export = snanmskmax;

0 commit comments

Comments
 (0)