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
-**mask**: mask [`Uint8Array`][@stdlib/array/uint8]. 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.
62
-
-**strideMask**: index increment for `mask`.
64
+
-**strideMask**: stride length for `mask`.
63
65
64
-
The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the [range][range] of every other element in `x`,
66
+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the [range][range] of every other element in `x`,
var mask1 =newUint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
93
92
94
-
varN=floor( x0.length/2 );
95
-
96
-
var v =snanmskrange( N, x1, 2, mask1, 2 );
93
+
var v =snanmskrange( 4, x1, 2, mask1, 2 );
97
94
// returns 6.0
98
95
```
99
96
@@ -117,18 +114,16 @@ The function has the following additional parameters:
117
114
-**offsetX**: starting index for `x`.
118
115
-**offsetMask**: starting index for `mask`.
119
116
120
-
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 [range][range] for every other value in `x` starting from the second value
117
+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the [range][range] for every other element in `x` starting from the second element
var uniform =require( '@stdlib/random/base/uniform' );
152
+
var bernoulli =require( '@stdlib/random/base/bernoulli' );
153
+
var filledarrayBy =require( '@stdlib/array/filled-by' );
160
154
var snanmskrange =require( '@stdlib/stats/base/snanmskrange' );
161
155
162
-
var mask;
163
-
var x;
164
-
var i;
165
-
166
-
x =newFloat32Array( 10 );
167
-
mask =newUint8Array( x.length );
168
-
for ( i =0; i <x.length; i++ ) {
169
-
if ( randu() <0.2 ) {
170
-
mask[ i ] =1;
171
-
} else {
172
-
mask[ i ] =0;
173
-
}
174
-
if ( randu() <0.1 ) {
175
-
x[ i ] =NaN;
176
-
} else {
177
-
x[ i ] =round( (randu()*100.0) -50.0 );
156
+
functionrand() {
157
+
if ( bernoulli( 0.8 ) <1 ) {
158
+
returnNaN;
178
159
}
160
+
returnuniform( -50.0, 50.0 );
179
161
}
162
+
163
+
var x =filledarrayBy( 10, 'float32', rand );
180
164
console.log( x );
165
+
166
+
var mask =filledarrayBy( x.length, 'uint8', bernoulli.factory( 0.2 ) );
181
167
console.log( mask );
182
168
183
169
var v =snanmskrange( x.length, x, 1, mask, 1 );
@@ -188,6 +174,145 @@ console.log( v );
188
174
189
175
<!-- /.examples -->
190
176
177
+
<!-- C interface documentation. -->
178
+
179
+
* * *
180
+
181
+
<sectionclass="c">
182
+
183
+
## C APIs
184
+
185
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
186
+
187
+
<sectionclass="intro">
188
+
189
+
</section>
190
+
191
+
<!-- /.intro -->
192
+
193
+
<!-- C usage documentation. -->
194
+
195
+
<sectionclass="usage">
196
+
197
+
### Usage
198
+
199
+
```c
200
+
#include"stdlib/stats/base/snanmskrange.h"
201
+
```
202
+
203
+
#### stdlib_strided_snanmskrange( N, \*X, strideX, \*Mask, strideMask )
204
+
205
+
Computes the [range][range] of a single-precision floating-point strided array according to a `mask`, ignoring `NaN` values.
float v = stdlib_strided_snanmskrange( 5, x, 1, mask, 1 );
214
+
// returns 4.0f
215
+
```
216
+
217
+
The function accepts the following arguments:
218
+
219
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
220
+
- **X**: `[in] float*` input array.
221
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
222
+
- **Mask**: `[in] uint8_t*` mask 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.
223
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
#### stdlib_strided_snanmskrange_ndarray( N, \*X, strideX, offsetX, \*Mask, strideMask, offsetMask )
230
+
231
+
Computes the [range][range] of a single-precision floating-point strided array according to a `mask`, ignoring `NaN` values and using alternative indexing semantics.
- **N**: `[in] CBLAS_INT` number of indexed elements.
246
+
- **X**: `[in] float*` input array.
247
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
248
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
249
+
- **Mask**: `[in] uint8_t*` mask 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.
250
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
251
+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
0 commit comments