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
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
73
+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
var floor =require( '@stdlib/math/base/special/floor' );
94
90
95
-
var x0 =newFloat32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
91
+
var x0 =newFloat32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
96
92
var x1 =newFloat32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
97
93
98
-
varN=floor( x0.length/2 );
99
-
100
-
var v =snanmean( N, x1, 2 );
94
+
var v =snanmean( 5, x1, 2 );
101
95
// returns 1.25
102
96
```
103
97
104
-
#### snanmean.ndarray( N, x, stride, offset )
98
+
#### snanmean.ndarray( N, x, strideX, offsetX )
105
99
106
100
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
var x =newFloat32Array( [ 1.0, -2.0, NaN, 2.0 ] );
112
-
varN=x.length;
113
106
114
-
var v =snanmean.ndarray( N, x, 1, 0 );
107
+
var v =snanmean.ndarray( x.length, x, 1, 0 );
115
108
// returns ~0.33333
116
109
```
117
110
118
111
The function has the following additional parameters:
119
112
120
-
-**offset**: starting index for `x`.
113
+
-**offsetX**: starting index.
114
+
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 [arithmetic mean][arithmetic-mean] for every other element in `x` starting from the second element
121
116
122
-
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 [arithmetic mean][arithmetic-mean] for every other value in `x` starting from the second value
var snanmean =require( '@stdlib/stats/base/snanmean' );
161
154
162
-
var x;
163
-
var i;
164
-
165
-
x =newFloat32Array( 10 );
166
-
for ( i =0; i <x.length; i++ ) {
167
-
if ( randu() <0.2 ) {
168
-
x[ i ] =NaN;
169
-
} else {
170
-
x[ i ] =round( (randu()*100.0) -50.0 );
155
+
functionrand() {
156
+
if ( bernoulli( 0.8 ) <1 ) {
157
+
returnNaN;
171
158
}
159
+
returnuniform( -50.0, 50.0 );
172
160
}
161
+
162
+
var x =filledarrayBy( 10, 'float32', rand );
173
163
console.log( x );
174
164
175
165
var v =snanmean( x.length, x, 1 );
@@ -180,6 +170,123 @@ console.log( v );
180
170
181
171
<!-- /.examples -->
182
172
173
+
<!-- C interface documentation. -->
174
+
175
+
* * *
176
+
177
+
<sectionclass="c">
178
+
179
+
## C APIs
180
+
181
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
182
+
183
+
<sectionclass="intro">
184
+
185
+
</section>
186
+
187
+
<!-- /.intro -->
188
+
189
+
<!-- C usage documentation. -->
190
+
191
+
<sectionclass="usage">
192
+
193
+
### Usage
194
+
195
+
```c
196
+
#include"stdlib/stats/base/snanmean.h"
197
+
```
198
+
199
+
#### stdlib_strided_snanmean( N, \*X, strideX )
200
+
201
+
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array, ignoring `NaN` values.
202
+
203
+
```c
204
+
constfloat x[] = { 1.0f, 2.0f, 3.0f, 0.0f/0.0f };
205
+
206
+
float v = stdlib_strided_snanmean( 4, x, 1 );
207
+
// returns 2.0f
208
+
```
209
+
210
+
The function accepts the following arguments:
211
+
212
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
#### stdlib_strided_snanmean_ndarray( N, \*X, strideX, offsetX )
221
+
222
+
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
223
+
224
+
```c
225
+
constfloat x[] = { 1.0f, 2.0f, 3.0f, 0.0f/0.0f };
226
+
227
+
float v = stdlib_strided_snanmean_ndarray( 4, x, 1, 0 );
228
+
// returns 2.0f
229
+
```
230
+
231
+
The function accepts the following arguments:
232
+
233
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
0 commit comments