You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/stats/base/nanmskmin/README.md
+85-44Lines changed: 85 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
@license Apache-2.0
4
4
5
-
Copyright (c) 2025 The Stdlib Authors.
5
+
Copyright (c) 2020 The Stdlib Authors.
6
6
7
7
Licensed under the Apache License, Version 2.0 (the "License");
8
8
you may not use this file except in compliance with the License.
@@ -33,52 +33,81 @@ limitations under the License.
33
33
## Usage
34
34
35
35
```javascript
36
-
var nanmskmin =require("@stdlib/stats/base/nanmskmin");
36
+
var nanmskmin =require('@stdlib/stats/base/nanmskmin');
37
37
```
38
38
39
39
#### nanmskmin( N, x, strideX, mask, strideMask )
40
40
41
-
Computes the minimum value of a strided array `x`according to a `mask`, ignoring `NaN` values.
41
+
Computes the minimum value of a strided array according to a `mask`, ignoring `NaN` values.
42
42
43
43
```javascript
44
-
var x = [1.0, -2.0, -4.0, 2.0, NaN];
45
-
var mask = [0, 0, 1, 0, 0];
44
+
var x = [1.0, -2.0, -4.0, 2.0, NaN];
45
+
var mask = [0, 0, 1, 0, 0];
46
46
47
-
var v =nanmskmin(x.length, x, 1, mask, 1);
47
+
var v =nanmskmin(x.length, x, 1, mask, 1);
48
48
// returns -2.0
49
49
```
50
50
51
51
The function has the following parameters:
52
52
53
-
-**N**: number of indexed elements.
54
-
-**x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
55
-
-**strideX**: stride length for `x`.
56
-
-**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.
57
-
-**strideMask**: stride length for `mask`.
53
+
-**N**: number of indexed elements.
54
+
-**x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
55
+
-**strideX**: stride length for `x`.
56
+
-**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.
57
+
-**strideMask**: stride length for `mask`.
58
58
59
-
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`,
59
+
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`,
60
60
61
61
```javascript
62
-
var x = [1.0, 2.0, -7.0, -2.0, 4.0, 3.0, -5.0, -6.0];
63
-
var mask = [0, 0, 0, 0, 0, 0, 1, 1];
62
+
var x = [1.0, 2.0, -7.0, -2.0, 4.0, 3.0, -5.0, -6.0, NaN, NaN];
63
+
var mask = [0, 0, 0, 0, 0, 0, 1, 1, 0, 0];
64
64
65
-
var v =nanmskmin(4, x, 2, mask, 2);
65
+
var v =nanmskmin(5, x, 2, mask, 2);
66
66
// returns -7.0
67
67
```
68
68
69
69
Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views.
var mask1 =newUint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
82
+
83
+
var v =nanmskmin( 5, x1, 2, mask1, 2 );
84
+
// returns -2.0
85
+
```
86
+
87
+
#### nanmskmin.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask )
88
+
89
+
Computes the minimum value of a strided array according to a `mask`, ignoring `NaN` values and using alternative indexing semantics.
90
+
71
91
```javascript
72
-
varFloat64Array=require("@stdlib/array/float64");
73
-
varUint8Array=require("@stdlib/array/uint8");
92
+
var x = [ 1.0, -2.0, -4.0, 2.0, NaN ];
93
+
var mask = [ 0, 0, 1, 0, 0 ];
94
+
95
+
var v =nanmskmin.ndarray( x.length, x, 1, 0, mask, 1, 0 );
96
+
// returns -2.0
97
+
```
98
+
99
+
The function has the following additional parameters:
100
+
101
+
-**offsetX**: starting index for `x`.
102
+
-**offsetMask**: starting index for `mask`.
74
103
75
-
var x0 =newFloat64Array([2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0]);
76
-
var x1 =newFloat64Array(x0.buffer, x0.BYTES_PER_ELEMENT*1);
104
+
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 minimum value for every other element in `x` starting from the second element
77
105
78
-
var mask0 =newUint8Array([0, 0, 0, 0, 0, 0, 1, 1]);
79
-
var mask1 =newUint8Array(mask0.buffer, mask0.BYTES_PER_ELEMENT*1);
106
+
```javascript
107
+
var x = [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, -5.0, -6.0, NaN, NaN ];
108
+
var mask = [ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ];
80
109
81
-
var v =nanmskmin(4, x1, 2, mask1, 2);
110
+
var v =nanmskmin.ndarray( 5, x, 2, 1, mask, 2, 1);
82
111
// returns -2.0
83
112
```
84
113
@@ -90,9 +119,9 @@ var v = nanmskmin(4, x1, 2, mask1, 2);
90
119
91
120
## Notes
92
121
93
-
- If `N <= 0`, both functions return `NaN`.
94
-
- Depending on the environment, the typed versions ([`dnanmskmin`][@stdlib/stats/strided/dnanmskmin], [`snanmskmin`][@stdlib/stats/strided/snanmskmin], etc.) are likely to be significantly more performant.
95
-
- 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]).
122
+
-If `N <= 0`, both functions return `NaN`.
123
+
-Depending on the environment, the typed versions ([`dnanmskmin`][@stdlib/stats/strided/dnanmskmin], [`snanmskmin`][@stdlib/stats/strided/snanmskmin], etc.) are likely to be significantly more performant.
124
+
-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]).
96
125
97
126
</section>
98
127
@@ -102,32 +131,40 @@ var v = nanmskmin(4, x1, 2, mask1, 2);
102
131
103
132
## Examples
104
133
134
+
<!-- eslint no-undef: "error" -->
135
+
105
136
```javascript
106
-
var uniform =require("@stdlib/random/array/uniform");
107
-
var bernoulli =require("@stdlib/random/array/bernoulli");
108
-
var nanmskmin =require("@stdlib/stats/base/nanmskmin");
109
-
110
-
var x =uniform(10, -50.0, 50.0, {
111
-
dtype:"float64",
112
-
});
113
-
console.log(x);
114
-
115
-
var mask =bernoulli(x.length, 0.2, {
116
-
dtype:"uint8",
117
-
});
118
-
console.log(mask);
119
-
120
-
var v =nanmskmin(x.length, x, 1, mask, 1);
121
-
console.log(v);
137
+
var uniform =require( '@stdlib/random/base/uniform' );
138
+
var bernoulli =require( '@stdlib/random/base/bernoulli' );
139
+
var filledarrayBy =require( '@stdlib/array/filled-by' );
140
+
var nanmskmin =require( '@stdlib/stats/base/nanmskmin' );
141
+
142
+
functionrand() {
143
+
if ( bernoulli( 0.8 ) <1 ) {
144
+
returnNaN;
145
+
}
146
+
returnuniform( -50.0, 50.0 );
147
+
}
148
+
149
+
var x =filledarrayBy( 10, 'float64', rand );
150
+
console.log( x );
151
+
152
+
var mask =filledarrayBy( x.length, 'uint8', bernoulli.factory( 0.2 ) );
153
+
console.log( mask );
154
+
155
+
var v =nanmskmin( x.length, x, 1, mask, 1 );
156
+
console.log( v );
122
157
```
123
158
124
159
</section>
125
160
126
161
<!-- /.examples -->
127
162
163
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
164
+
128
165
<sectionclass="related">
129
166
130
-
---
167
+
* * *
131
168
132
169
## See Also
133
170
@@ -141,14 +178,16 @@ console.log(v);
141
178
142
179
<!-- /.related -->
143
180
181
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
0 commit comments