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
@@ -61,18 +61,16 @@ The function has the following parameters:
61
61
-**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 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
-
94
-
varN=floor( x0.length/2 );
95
-
96
-
var v =dmskrange( N, x1, 2, mask1, 2 );
90
+
var v =dmskrange( 4, x1, 2, mask1, 2 );
97
91
// returns 6.0
98
92
```
99
93
@@ -117,18 +111,16 @@ The function has the following additional parameters:
117
111
-**offsetX**: starting index for `x`.
118
112
-**offsetMask**: starting index for `mask`.
119
113
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
114
+
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 [range][range] for every other element in `x` starting from the second element
var uniform =require( '@stdlib/random/array/uniform' );
149
+
var bernoulli =require( '@stdlib/random/array/bernoulli' );
160
150
var dmskrange =require( '@stdlib/stats/base/dmskrange' );
161
151
162
-
var mask;
163
-
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
-
x[ i ] =round( (randu()*100.0) -50.0 );
175
-
}
152
+
var uniformOptions = {
153
+
'dtype':'float64'
154
+
};
155
+
var bernoulliOptions = {
156
+
'dtype':'uint8'
157
+
};
158
+
159
+
var x =uniform( 10, -50.0, 50.0, uniformOptions );
160
+
var mask =bernoulli( x.length, 0.2, bernoulliOptions );
176
161
console.log( x );
177
162
console.log( mask );
178
163
@@ -184,6 +169,125 @@ console.log( v );
184
169
185
170
<!-- /.examples -->
186
171
172
+
<!-- C usage documentation. -->
173
+
174
+
<sectionclass="usage">
175
+
176
+
### Usage
177
+
178
+
```c
179
+
#include"stdlib/stats/base/dmskrange.h"
180
+
```
181
+
182
+
#### stdlib_strided_dmskrange( N, \*X, strideX, \*Mask, strideMask )
183
+
184
+
Computes the [range][range] of a double-precision floating-point strided array according to a mask.
185
+
186
+
```c
187
+
#include<stdint.h>
188
+
189
+
constdouble x[] = { 1.0, -2.0, 2.0 };
190
+
const uint8_t mask[] = { 0, 1, 0 };
191
+
192
+
double v = stdlib_strided_dmskrange( 3, x, 1, mask, 1 );
193
+
// returns 1.0
194
+
```
195
+
196
+
The function accepts the following arguments:
197
+
198
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
199
+
- **X**: `[in] double*` input array.
200
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
201
+
- **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.
202
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
- **N**: `[in] CBLAS_INT` number of indexed elements.
227
+
- **X**: `[in] double*` input array.
228
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
229
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
230
+
- **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.
231
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
232
+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
0 commit comments