Skip to content

Commit ae61cdf

Browse files
feat: ndarray-dnanmeanpn
1 parent 8785e54 commit ae61cdf

25 files changed

+428
-329
lines changed

lib/node_modules/@stdlib/stats/base/dsmeanpn/README.md

Lines changed: 129 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,33 @@ The [arithmetic mean][arithmetic-mean] is defined as
5151
var dsmeanpn = require( '@stdlib/stats/base/dsmeanpn' );
5252
```
5353

54-
#### dsmeanpn( N, x, stride )
54+
#### dsmeanpn( N, x, strideX )
5555

5656
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using a two-pass error correction algorithm with extended accumulation and returning an extended precision result.
5757

5858
```javascript
5959
var Float32Array = require( '@stdlib/array/float32' );
6060

6161
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
62-
var N = x.length;
6362

64-
var v = dsmeanpn( N, x, 1 );
63+
var v = dsmeanpn( x.length, x, 1 );
6564
// returns ~0.3333
6665
```
6766

6867
The function has the following parameters:
6968

7069
- **N**: number of indexed elements.
7170
- **x**: input [`Float32Array`][@stdlib/array/float32].
72-
- **stride**: index increment for `x`.
71+
- **strideX**: Stride Length for `x`.
7372

74-
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`,
7574

7675
```javascript
7776
var Float32Array = require( '@stdlib/array/float32' );
78-
var floor = require( '@stdlib/math/base/special/floor' );
7977

8078
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 );
8279

83-
var v = dsmeanpn( N, x, 2 );
80+
var v = dsmeanpn( 4, x, 2 );
8481
// returns 1.25
8582
```
8683

@@ -90,45 +87,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
9087

9188
```javascript
9289
var Float32Array = require( '@stdlib/array/float32' );
93-
var floor = require( '@stdlib/math/base/special/floor' );
9490

9591
var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
9692
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9793

98-
var N = floor( x0.length / 2 );
99-
100-
var v = dsmeanpn( N, x1, 2 );
94+
var v = dsmeanpn( 4, x1, 2 );
10195
// returns 1.25
10296
```
10397

104-
#### dsmeanpn.ndarray( N, x, stride, offset )
98+
#### dsmeanpn.ndarray( N, x, strideX, offsetX )
10599

106100
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using a two-pass error correction algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result.
107101

108102
```javascript
109103
var Float32Array = require( '@stdlib/array/float32' );
110104

111105
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
112-
var N = x.length;
113106

114-
var v = dsmeanpn.ndarray( N, x, 1, 0 );
107+
var v = dsmeanpn.ndarray( x.length, x, 1, 0 );
115108
// returns ~0.33333
116109
```
117110

118111
The function has the following additional parameters:
119112

120-
- **offset**: starting index for `x`.
113+
- **offsetX**: starting index for `x`.
121114

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
123116

124117
```javascript
125118
var Float32Array = require( '@stdlib/array/float32' );
126-
var floor = require( '@stdlib/math/base/special/floor' );
127119

128120
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 );
130121

131-
var v = dsmeanpn.ndarray( N, x, 2, 1 );
122+
var v = dsmeanpn.ndarray( 4, x, 2, 1 );
132123
// returns 1.25
133124
```
134125

@@ -141,7 +132,7 @@ var v = dsmeanpn.ndarray( N, x, 2, 1 );
141132
## Notes
142133

143134
- 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.
145136

146137
</section>
147138

@@ -176,6 +167,123 @@ console.log( v );
176167

177168
<!-- /.examples -->
178169

170+
<!-- C interface documentation. -->
171+
172+
* * *
173+
174+
<section class="c">
175+
176+
## C APIs
177+
178+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
179+
180+
<section class="intro">
181+
182+
</section>
183+
184+
<!-- /.intro -->
185+
186+
<!-- C usage documentation. -->
187+
188+
<section class="usage">
189+
190+
### Usage
191+
192+
```c
193+
#include "stdlib/stats/base/smax.h"
194+
```
195+
196+
#### stdlib_strided_dsmeanpn( N, \*X, strideX )
197+
198+
Computes the arithmetic mean value of a single-precision floating-point strided array.
199+
200+
```c
201+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
202+
203+
double v = stdlib_strided_dsmeanpn( 4, x, 2 );
204+
// returns 1.25
205+
```
206+
207+
The function accepts the following arguments:
208+
209+
- **N**: `[in] CBLAS_INT` number of indexed elements.
210+
- **X**: `[in] float*` input array.
211+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
212+
213+
```c
214+
double stdlib_strided_dsmeanpn( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
215+
```
216+
217+
#### stdlib_strided_dsmeanpn_ndarray( N, \*X, strideX, offsetX )
218+
219+
Computes the arithmetic value value of a single-precision floating-point strided array using alternative indexing semantics.
220+
221+
```c
222+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
223+
224+
double v = stdlib_strided_dsmeanpn_ndarray( 4, x, 2, 0 );
225+
// returns 1.25
226+
```
227+
228+
The function accepts the following arguments:
229+
230+
- **N**: `[in] CBLAS_INT` number of indexed elements.
231+
- **X**: `[in] float*` input array.
232+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
233+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
234+
235+
```c
236+
double stdlib_strided_dsmeanpn_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
237+
```
238+
239+
</section>
240+
241+
<!-- /.usage -->
242+
243+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
244+
245+
<section class="notes">
246+
247+
</section>
248+
249+
<!-- /.notes -->
250+
251+
<!-- C API usage examples. -->
252+
253+
<section class="examples">
254+
255+
### Examples
256+
257+
```c
258+
#include "stdlib/stats/base/dsmeanpn.h"
259+
#include <stdio.h>
260+
261+
int main( void ) {
262+
// Create a strided array:
263+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
264+
265+
// Specify the number of elements:
266+
const int N = 4;
267+
268+
// Specify the stride length:
269+
const int strideX = 2;
270+
271+
// Compute the arithmetic mean:
272+
double v = stdlib_strided_dsmeanpn( N, x, strideX );
273+
274+
// Print the result:
275+
printf( "mean: %lf\n", v );
276+
}
277+
```
278+
279+
</section>
280+
281+
<!-- /.examples -->
282+
283+
</section>
284+
285+
<!-- /.c -->
286+
179287
* * *
180288
181289
<section class="references">

lib/node_modules/@stdlib/stats/base/dsmeanpn/benchmark/benchmark.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float32Array = require( '@stdlib/array/float32' );
2827
var pkg = require( './../package.json' ).name;
2928
var dsmeanpn = require( './../lib/dsmeanpn.js' );
3029

3130

31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float32'
35+
};
36+
37+
3238
// FUNCTIONS //
3339

3440
/**
@@ -39,13 +45,7 @@ var dsmeanpn = require( './../lib/dsmeanpn.js' );
3945
* @returns {Function} benchmark function
4046
*/
4147
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float32Array( len );
46-
for ( i = 0; i < x.length; i++ ) {
47-
x[ i ] = ( randu()*20.0 ) - 10.0;
48-
}
48+
var x = uniform( len, -10.0, 10.0, options );
4949
return benchmark;
5050

5151
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsmeanpn/benchmark/benchmark.native.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
3029
var pkg = require( './../package.json' ).name;
3130

@@ -36,6 +35,9 @@ var dsmeanpn = tryRequire( resolve( __dirname, './../lib/dsmeanpn.native.js' ) )
3635
var opts = {
3736
'skip': ( dsmeanpn instanceof Error )
3837
};
38+
var options = {
39+
'dtype': 'float32'
40+
};
3941

4042

4143
// FUNCTIONS //
@@ -48,13 +50,7 @@ var opts = {
4850
* @returns {Function} benchmark function
4951
*/
5052
function createBenchmark( len ) {
51-
var x;
52-
var i;
53-
54-
x = new Float32Array( len );
55-
for ( i = 0; i < x.length; i++ ) {
56-
x[ i ] = ( randu()*20.0 ) - 10.0;
57-
}
53+
var x = uniform( len, -10.0, 10.0, options );
5854
return benchmark;
5955

6056
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsmeanpn/benchmark/benchmark.ndarray.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float32Array = require( '@stdlib/array/float32' );
2827
var pkg = require( './../package.json' ).name;
2928
var dsmeanpn = require( './../lib/ndarray.js' );
3029

@@ -39,13 +38,7 @@ var dsmeanpn = require( './../lib/ndarray.js' );
3938
* @returns {Function} benchmark function
4039
*/
4140
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float32Array( len );
46-
for ( i = 0; i < x.length; i++ ) {
47-
x[ i ] = ( randu()*20.0 ) - 10.0;
48-
}
41+
var x = uniform( len, -10.0, 10.0, options );
4942
return benchmark;
5043

5144
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsmeanpn/benchmark/benchmark.ndarray.native.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
3029
var pkg = require( './../package.json' ).name;
3130

@@ -36,6 +35,9 @@ var dsmeanpn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3635
var opts = {
3736
'skip': ( dsmeanpn instanceof Error )
3837
};
38+
var options = {
39+
'dtype': 'float32'
40+
};
3941

4042

4143
// FUNCTIONS //
@@ -48,13 +50,7 @@ var opts = {
4850
* @returns {Function} benchmark function
4951
*/
5052
function createBenchmark( len ) {
51-
var x;
52-
var i;
53-
54-
x = new Float32Array( len );
55-
for ( i = 0; i < x.length; i++ ) {
56-
x[ i ] = ( randu()*20.0 ) - 10.0;
57-
}
53+
var x = uniform( len, -10.0, 10.0, options );
5854
return benchmark;
5955

6056
function benchmark( b ) {

0 commit comments

Comments
 (0)