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
@@ -51,36 +51,33 @@ The [arithmetic mean][arithmetic-mean] is defined as
51
51
var dmeankbn2 =require( '@stdlib/stats/base/dmeankbn2' );
52
52
```
53
53
54
-
#### dmeankbn2( N, x, stride )
54
+
#### dmeankbn2( N, x, strideX )
55
55
56
56
Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array `x` using a second-order iterative Kahan–Babuška algorithm.
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 =newFloat64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
97
93
98
-
varN=floor( x0.length/2 );
99
-
100
-
var v =dmeankbn2( N, x1, 2 );
94
+
var v =dmeankbn2( 4, x1, 2 );
101
95
// returns 1.25
102
96
```
103
97
104
-
#### dmeankbn2.ndarray( N, x, stride, offset )
98
+
#### dmeankbn2.ndarray( N, x, strideX, offsetX )
105
99
106
100
Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm 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' );
159
148
var dmeankbn2 =require( '@stdlib/stats/base/dmeankbn2' );
160
149
161
-
var x;
162
-
var i;
163
-
164
-
x =newFloat64Array( 10 );
165
-
for ( i =0; i <x.length; i++ ) {
166
-
x[ i ] =round( (randu()*100.0) -50.0 );
167
-
}
150
+
var x =discreteUniform( 10, -50, 50, {
151
+
'dtype':'float64'
152
+
});
168
153
console.log( x );
169
154
170
155
var v =dmeankbn2( x.length, x, 1 );
@@ -175,6 +160,107 @@ console.log( v );
175
160
176
161
<!-- /.examples -->
177
162
163
+
<!-- C usage documentation. -->
164
+
165
+
<sectionclass="usage">
166
+
167
+
### Usage
168
+
169
+
```c
170
+
#include"stdlib/stats/base/dmeankbn2.h"
171
+
```
172
+
173
+
#### stdlib_strided_dmeankbn2( N, \*X, strideX )
174
+
175
+
Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm.
176
+
177
+
```c
178
+
constdouble x[] = { 1.0, -2.0, 2.0 };
179
+
180
+
double v = stdlib_strided_dmeankbn2( 3, x, 1 );
181
+
// returns ~0.3333
182
+
```
183
+
184
+
The function accepts the following arguments:
185
+
186
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
187
+
- **X**: `[in] double*` input array.
188
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_dmeankbn2_ndarray( N, \*X, strideX, offsetX )
195
+
196
+
Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
197
+
198
+
```c
199
+
constdouble x[] = { 1.0, -2.0, 2.0 };
200
+
201
+
double v = stdlib_strided_dmeankbn2_ndarray( 3, x, 1, 0 );
202
+
// returns ~0.3333
203
+
```
204
+
205
+
The function accepts the following arguments:
206
+
207
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
208
+
- **X**: `[in] double*` input array.
209
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
210
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments