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
62
-**strideMask**: index increment for `mask`.
63
63
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`,
64
+
The `N` and stride parameters determine which elements in the strided array 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
90
94
-
varN=floor( x0.length/2 );
95
-
96
-
var v =dnanmskrange( N, x1, 2, mask1, 2 );
91
+
var v =dnanmskrange( 4, x1, 2, mask1, 2 );
97
92
// returns 6.0
98
93
```
99
94
@@ -117,18 +112,16 @@ The function has the following additional parameters:
117
112
-**offsetX**: starting index for `x`.
118
113
-**offsetMask**: starting index for `mask`.
119
114
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
115
+
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 element in `x` starting from the second element
var dnanmskrange =require( '@stdlib/stats/base/dnanmskrange' );
161
154
162
155
var mask;
163
156
var x;
164
-
var i;
165
-
166
-
x =newFloat64Array( 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 );
157
+
158
+
functionrand() {
159
+
if ( bernoulli( 0.8 ) <1 ) {
160
+
returnNaN;
178
161
}
162
+
returnuniform( -50.0, 50.0 );
179
163
}
164
+
165
+
x =filledarrayBy( 10, 'float64', rand );
180
166
console.log( x );
167
+
168
+
mask =uint8Array( x.length, 0.2, {
169
+
'dtype':'uint8'
170
+
});
181
171
console.log( mask );
182
172
183
173
var v =dnanmskrange( x.length, x, 1, mask, 1 );
@@ -188,6 +178,143 @@ console.log( v );
188
178
189
179
<!-- /.examples -->
190
180
181
+
<!-- C interface documentation. -->
182
+
183
+
* * *
184
+
185
+
<sectionclass="c">
186
+
187
+
## C APIs
188
+
189
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
190
+
191
+
<sectionclass="intro">
192
+
193
+
</section>
194
+
195
+
<!-- /.intro -->
196
+
197
+
<!-- C usage documentation. -->
198
+
199
+
<sectionclass="usage">
200
+
201
+
### Usage
202
+
203
+
```c
204
+
#include"stdlib/stats/base/dnanmskrange.h"
205
+
```
206
+
207
+
#### stdlib_strided_dnanmskrange( N, \*X, strideX, \*Mask, strideMask )
208
+
209
+
Computes the [range][range] of a double-precision floating-point strided array according to a `mask`, ignoring `NaN` values.
double v = stdlib_strided_dnanmskrange( 5, x, 1, mask, 1 );
218
+
// returns 4.0
219
+
```
220
+
221
+
The function accepts the following arguments:
222
+
223
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
224
+
- **X**: `[in] double*` input array.
225
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
226
+
- **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.
227
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
#### stdlib_strided_dnanmskrange_ndarray( N, \*X, strideX, offsetX, \*Mask, strideMask, offsetMask )
234
+
235
+
Computes the [range][range] of a double-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.
248
+
- **X**: `[in] double*` input array.
249
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
250
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
251
+
- **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.
252
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
253
+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
0 commit comments