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.
60
-
-**strideMask**: index increment for `mask`.
60
+
-**strideMask**: stride length for `mask`.
61
61
62
-
The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the maximum value of every other element in `x`,
62
+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the maximum value of every other element in `x`,
@@ -115,18 +110,16 @@ The function has the following additional parameters:
115
110
-**offsetX**: starting index for `x`.
116
111
-**offsetMask**: starting index for `mask`.
117
112
118
-
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 maximum value for every other value in `x` starting from the second value
113
+
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 maximum value for every other element in `x` starting from the second element
var uniform =require( '@stdlib/random/array/uniform' );
148
+
var bernoulli =require( '@stdlib/random/array/bernoulli' );
158
149
var smskmax =require( '@stdlib/stats/base/smskmax' );
159
150
160
-
var mask;
161
-
var x;
162
-
var i;
163
-
164
-
x =newFloat32Array( 10 );
165
-
mask =newUint8Array( x.length );
166
-
for ( i =0; i <x.length; i++ ) {
167
-
if ( randu() <0.2 ) {
168
-
mask[ i ] =1;
169
-
} else {
170
-
mask[ i ] =0;
171
-
}
172
-
x[ i ] =round( (randu()*100.0) -50.0 );
173
-
}
151
+
var uniformOptions = {
152
+
'dtype':'float32'
153
+
};
154
+
var bernoulliOptions = {
155
+
'dtype':'uint8'
156
+
};
157
+
158
+
var x =uniform( 10, -50.0, 50.0, uniformOptions );
159
+
var mask =bernoulli( x.length, 0.2, bernoulliOptions );
174
160
console.log( x );
175
161
console.log( mask );
176
162
@@ -182,6 +168,125 @@ console.log( v );
182
168
183
169
<!-- /.examples -->
184
170
171
+
<!-- C usage documentation. -->
172
+
173
+
<sectionclass="usage">
174
+
175
+
### Usage
176
+
177
+
```c
178
+
#include"stdlib/stats/base/smskmax.h"
179
+
```
180
+
181
+
#### stdlib_strided_smskmax( N, \*X, strideX, \*Mask, strideMask )
182
+
183
+
Computes the maximum value of a single-precision floating-point strided array according to a mask.
184
+
185
+
```c
186
+
#include<stdint.h>
187
+
188
+
constfloat x[] = { 1.0f, -2.0f, 2.0f };
189
+
const uint8_t mask[] = { 0, 1, 0 };
190
+
191
+
float v = stdlib_strided_smskmax( 3, x, 1, mask, 1 );
192
+
// returns 2.0f
193
+
```
194
+
195
+
The function accepts the following arguments:
196
+
197
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
198
+
- **X**: `[in] float*` input array.
199
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
200
+
- **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.
201
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
- **N**: `[in] CBLAS_INT` number of indexed elements.
226
+
- **X**: `[in] float*` input array.
227
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
228
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
229
+
- **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.
230
+
- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`.
231
+
- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`.
0 commit comments