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
Licensed under the Apache License, Version 2.0 (the "License");
8
8
you may not use this file except in compliance with the License.
@@ -51,36 +51,33 @@ The [arithmetic mean][arithmetic-mean] is defined as
51
51
var dsmean = require( '@stdlib/stats/base/dsmean' );
52
52
```
53
53
54
-
#### dsmean( N, x, stride )
54
+
#### dsmean( N, x, strideX )
55
55
56
56
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using extended accumulation and returning an extended precision result.
57
57
58
58
```javascript
59
59
var Float32Array = require( '@stdlib/array/float32' );
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 `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
75
74
76
75
```javascript
77
76
var Float32Array = require( '@stdlib/array/float32' );
78
-
var floor = require( '@stdlib/math/base/special/floor' );
79
77
80
78
var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
81
-
var N = floor( x.length / 2 );
82
79
83
-
var v = dsmean( N, x, 2 );
80
+
var v = dsmean( 4, x, 2 );
84
81
// returns 1.25
85
82
```
86
83
@@ -90,45 +87,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
90
87
91
88
```javascript
92
89
var Float32Array = require( '@stdlib/array/float32' );
93
-
var floor = require( '@stdlib/math/base/special/floor' );
94
90
95
91
var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
96
92
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
97
93
98
-
var N = floor( x0.length / 2 );
99
-
100
-
var v = dsmean( N, x1, 2 );
94
+
var v = dsmean( 4, x1, 2 );
101
95
// returns 1.25
102
96
```
103
97
104
-
#### dsmean.ndarray( N, x, stride, offset )
98
+
#### dsmean.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 and returning an extended precision result.
107
101
108
102
```javascript
109
103
var Float32Array = require( '@stdlib/array/float32' );
110
104
111
105
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
112
-
var N = x.length;
113
106
114
-
var v = dsmean.ndarray( N, x, 1, 0 );
107
+
var v = dsmean.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 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
123
116
124
117
```javascript
125
118
var Float32Array = require( '@stdlib/array/float32' );
126
-
var floor = require( '@stdlib/math/base/special/floor' );
127
119
128
120
var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
129
-
var N = floor( x.length / 2 );
130
121
131
-
var v = dsmean.ndarray( N, x, 2, 1 );
122
+
var v = dsmean.ndarray( 4, x, 2, 1 );
132
123
// returns 1.25
133
124
```
134
125
@@ -141,7 +132,7 @@ var v = dsmean.ndarray( N, x, 2, 1 );
141
132
## Notes
142
133
143
134
- If `N <= 0`, both functions return `NaN`.
144
-
- Accumulated intermediate values are stored as double-precision floating-point numbers.
135
+
- Accumulated intermediate values are stored as double-precision floating-point numbers.
145
136
146
137
</section>
147
138
@@ -154,18 +145,12 @@ var v = dsmean.ndarray( N, x, 2, 1 );
154
145
<!-- eslint no-undef: "error" -->
155
146
156
147
```javascript
157
-
var randu = require( '@stdlib/random/base/randu' );
158
-
var round = require( '@stdlib/math/base/special/round' );
159
-
var Float32Array = require( '@stdlib/array/float32' );
148
+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
160
149
var dsmean = require( '@stdlib/stats/base/dsmean' );
161
150
162
-
var x;
163
-
var i;
164
-
165
-
x = new Float32Array( 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 = dsmean( x.length, x, 1 );
@@ -176,6 +161,107 @@ console.log( v );
176
161
177
162
<!-- /.examples -->
178
163
164
+
<!-- C usage documentation. -->
165
+
166
+
<section class="usage">
167
+
168
+
### Usage
169
+
170
+
```c
171
+
#include "stdlib/stats/base/dsmean.h"
172
+
```
173
+
174
+
#### stdlib_strided_dsmean( N, \*X, strideX )
175
+
176
+
Computes the arithmetic mean of a single-precision floating-point strided array using extended accumulation and returning an extended precision result.
#### stdlib_strided_dsmean_ndarray( N, \*X, strideX, offsetX )
196
+
197
+
Computes the arithmetic mean of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics and returning an extended precision result.
0 commit comments