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 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 =sdsmean( N, x1, 2 );
94
+
var v =sdsmean( 4, x1, 2 );
101
95
// returns 1.25
102
96
```
103
97
104
-
#### sdsmean.ndarray( N, x, stride, offset )
98
+
#### sdsmean.ndarray( N, x, strideX, offsetX )
105
99
106
100
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics.
The function has the following additional parameters:
119
112
120
-
-**offset**: starting index for `x`.
113
+
-**offsetX**: starting index for `x`.
121
114
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
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
var discreteUniform =require( '@stdlib/random/array/discrete-uniform' );
160
149
var sdsmean =require( '@stdlib/stats/base/sdsmean' );
161
150
162
-
var x;
163
-
var i;
164
-
165
-
x =newFloat32Array( 10 );
166
-
for ( i =0; i <x.length; i++ ) {
167
-
x[ i ] =round( (randu()*100.0) -50.0 );
168
-
}
151
+
var x =discreteUniform( 10, -50, 50, {
152
+
'dtype':'float32'
153
+
});
169
154
console.log( x );
170
155
171
156
var v =sdsmean( x.length, x, 1 );
@@ -176,6 +161,123 @@ console.log( v );
176
161
177
162
<!-- /.examples -->
178
163
164
+
<!-- C interface documentation. -->
165
+
166
+
* * *
167
+
168
+
<sectionclass="c">
169
+
170
+
## C APIs
171
+
172
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
173
+
174
+
<sectionclass="intro">
175
+
176
+
</section>
177
+
178
+
<!-- /.intro -->
179
+
180
+
<!-- C usage documentation. -->
181
+
182
+
<sectionclass="usage">
183
+
184
+
### Usage
185
+
186
+
```c
187
+
#include"stdlib/stats/base/sdsmean.h"
188
+
```
189
+
190
+
#### stdlib_strided_sdsmean( N, \*X, strideX )
191
+
192
+
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using extended accumulation.
193
+
194
+
```c
195
+
constfloat x[] = { 1.0f, 2.0f, 3.0f };
196
+
197
+
float v = stdlib_strided_sdsmean( 3, x, 1 );
198
+
// returns 2.0f
199
+
```
200
+
201
+
The function accepts the following arguments:
202
+
203
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
204
+
- **X**: `[in] float*` input array.
205
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_sdsmean_ndarray( N, \*X, strideX, offsetX )
212
+
213
+
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics.
214
+
215
+
```c
216
+
constfloat x[] = { 1.0f, 2.0f, 3.0f };
217
+
218
+
float v = stdlib_strided_sdsmean_ndarray( 3, x, 1, 0 );
219
+
// returns 2.0f
220
+
```
221
+
222
+
The function accepts the following arguments:
223
+
224
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
225
+
- **X**: `[in] float*` input array.
226
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
227
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments