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`.
62
+
-**strideMask**: stride length 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`,
@@ -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 parameters support indexing semantics based on a 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' );
150
+
var bernoulli =require( '@stdlib/random/array/bernoulli' );
160
151
var smskrange =require( '@stdlib/stats/base/smskrange' );
161
152
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
-
x[ i ] =round( (randu()*100.0) -50.0 );
175
-
}
153
+
var uniformOptions = {
154
+
'dtype':'float32'
155
+
};
156
+
var bernoulliOptions = {
157
+
'dtype':'uint8'
158
+
};
159
+
160
+
var x =uniform( 10, -50.0, 50.0, uniformOptions );
161
+
var mask =bernoulli( x.length, 0.2, bernoulliOptions );
176
162
console.log( x );
177
163
console.log( mask );
178
164
@@ -184,6 +170,125 @@ console.log( v );
184
170
185
171
<!-- /.examples -->
186
172
173
+
<!-- C usage documentation. -->
174
+
175
+
<sectionclass="usage">
176
+
177
+
### Usage
178
+
179
+
```c
180
+
#include"stdlib/stats/base/smskrange.h"
181
+
```
182
+
183
+
#### stdlib_strided_smskrange( N, \*X, strideX, \*Mask, strideMask )
184
+
185
+
Computes the [range][range] of a single-precision floating-point strided array according to a mask.
186
+
187
+
```c
188
+
#include<stdint.h>
189
+
190
+
constfloat x[] = { 1.0f, -2.0f, 2.0f };
191
+
const uint8_t mask[] = { 0, 1, 0 };
192
+
193
+
float v = stdlib_strided_smskrange( 3, x, 1, mask, 1 );
194
+
// returns 1.0f
195
+
```
196
+
197
+
The function accepts the following arguments:
198
+
199
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
200
+
- **X**: `[in] float*` input array.
201
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
202
+
- **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.
203
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
- **N**: `[in] CBLAS_INT` number of indexed elements.
228
+
- **X**: `[in] float*` input array.
229
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
230
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
231
+
- **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.
232
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
233
+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
0 commit comments