Skip to content

Commit 30b1229

Browse files
chore: minor clean up
1 parent 9783f82 commit 30b1229

File tree

18 files changed

+163
-68
lines changed

18 files changed

+163
-68
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var Float32Array = require( '@stdlib/array/float32' );
7777

7878
var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ] );
7979

80-
var v = dsnanmeanpn( 5, x, 2 );
80+
var v = dsnanmeanpn( 4, x, 2 );
8181
// returns 1.25
8282
```
8383

@@ -90,6 +90,9 @@ var Float32Array = require( '@stdlib/array/float32' );
9090

9191
var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
9292
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
93+
94+
var v = dsnanmeanpn( 4, x1, 2 );
95+
// returns 1.25
9396
```
9497

9598
#### dsnanmeanpn.ndarray( N, x, strideX, offsetX )
@@ -107,14 +110,17 @@ var v = dsnanmeanpn.ndarray( x.length, x, 1, 0 );
107110

108111
The function has the following additional parameters:
109112

110-
- **offset**: starting index for `x`.
113+
- **offsetX**: starting index for `x`.
111114

112115
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
113116

114117
```javascript
115118
var Float32Array = require( '@stdlib/array/float32' );
116119

117120
var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
121+
122+
var v = dsnanmeanpn.ndarray( 4, x, 2, 1 );
123+
// returns 1.25
118124
```
119125

120126
</section>
@@ -178,12 +184,12 @@ console.log( v );
178184

179185
#### stdlib_strided_dsnanmeanpn( N, \*X, strideX )
180186

181-
Calculate the Arithmetic Mean value of a double-precision floating-point strided array, ignoring `NaN` values.
187+
Calculate the arithmetic mean of a single-precision floating-point strided array `x` , ignoring `NaN` values, using a two-pass error correction algorithm with extended accumulation, and returning an extended precision result.
182188

183189
```c
184190
const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 3.0f, 0.0f/0.0f, 4.0f, 5.0f, 6.0f, 0.0f/0.0f, 7.0f, 8.0f, 0.0f/0.0f };
185191

186-
double v = stdlib_strided_dsnanmeanpn( 5, x, 2 );
192+
double v = stdlib_strided_dsnanmeanpn( 6, x, 2 );
187193
// returns 1.25
188194
```
189195
@@ -199,12 +205,12 @@ double stdlib_strided_dsnanmeanpn( const CBLAS_INT N, const float *X, const CBLA
199205

200206
#### stdlib_strided_dsnanmeanpn_ndarray( N, \*X, strideX, offsetX )
201207

202-
Computes the Arithmetic Mean value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
208+
Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using a two-pass error correction algorithm with extended accumulation and alternative indexing semantics.
203209

204210
```c
205211
const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 3.0f, 0.0f/0.0f, 4.0f, 5.0f, 6.0f, 0.0f/0.0f, 7.0f, 8.0f, 0.0f/0.0f };
206212

207-
double v = stdlib_strided_dsnanmeanpn_ndarray( 5, x, 2, 0 );
213+
double v = stdlib_strided_dsnanmeanpn_ndarray( 6, x, 2, 0 );
208214
// returns 1.25
209215
```
210216
@@ -243,7 +249,7 @@ double stdlib_strided_dsnanmeanpn_ndarray( const CBLAS_INT N, const float *X, co
243249

244250
int main( void ) {
245251
// Create a strided array:
246-
const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 3.0f, 0.0f/0.0f, 4.0f, 5.0f, 6.0f, 0 0f/0.0f, 7.0f, 8.0f, 0.0f/0.0f };
252+
const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 3.0f, 0.0f/0.0f, 4.0f, 5.0f, 6.0f, 0.0f/0.0f, 7.0f, 8.0f, 0.0f/0.0f };
247253

248254
// Specify the number of elements:
249255
const int N = 6;

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/array/uniform' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
2830
var dsnanmeanpn = require( './../lib/dsnanmeanpn.js' );
2931

3032

31-
// VARIABLES //
32-
33-
var options = {
34-
'dtype': 'float32'
35-
};
36-
37-
3833
// FUNCTIONS //
3934

35+
/**
36+
* Returns a random value or `NaN`.
37+
*
38+
* @returns {number} random number or `NaN`
39+
*/
40+
function rand() {
41+
if ( bernoulli( 0.2 ) ) {
42+
return NaN;
43+
}
44+
return uniform( -10.0, 10.0 );
45+
}
46+
4047
/**
4148
* Creates a benchmark function.
4249
*
@@ -45,7 +52,7 @@ var options = {
4552
* @returns {Function} benchmark function
4653
*/
4754
function createBenchmark( len ) {
48-
var x = uniform( len, -10.0, 10.0, options );
55+
var x = filledarrayBy( len, 'float32', rand );
4956
return benchmark;
5057

5158
function benchmark( b ) {

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var uniform = require( '@stdlib/random/array/uniform' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
27+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2628
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2729
var pow = require( '@stdlib/math/base/special/pow' );
2830
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -35,13 +37,22 @@ var dsnanmeanpn = tryRequire( resolve( __dirname, './../lib/dsnanmeanpn.native.j
3537
var opts = {
3638
'skip': ( dsnanmeanpn instanceof Error )
3739
};
38-
var options = {
39-
'dtype': 'float32'
40-
};
4140

4241

4342
// FUNCTIONS //
4443

44+
/**
45+
* Returns a random value or `NaN`.
46+
*
47+
* @returns {number} random number or `NaN`
48+
*/
49+
function rand() {
50+
if ( bernoulli( 0.2 ) ) {
51+
return NaN;
52+
}
53+
return uniform( -10.0, 10.0 );
54+
}
55+
4556
/**
4657
* Creates a benchmark function.
4758
*
@@ -50,7 +61,7 @@ var options = {
5061
* @returns {Function} benchmark function
5162
*/
5263
function createBenchmark( len ) {
53-
var x = uniform( len, -10.0, 10.0, options );
64+
var x = filledarrayBy( len, 'float32', rand );
5465
return benchmark;
5566

5667
function benchmark( b ) {

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/array/uniform' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
2830
var dsnanmeanpn = require( './../lib/ndarray.js' );
2931

3032

31-
// VARIABLES //
32-
33-
var options = {
34-
'dtype': 'float32'
35-
};
36-
37-
3833
// FUNCTIONS //
3934

35+
/**
36+
* Returns a random value or `NaN`.
37+
*
38+
* @returns {number} random number or `NaN`
39+
*/
40+
function rand() {
41+
if ( bernoulli( 0.2 ) ) {
42+
return NaN;
43+
}
44+
return uniform( -10.0, 10.0 );
45+
}
46+
4047
/**
4148
* Creates a benchmark function.
4249
*
@@ -45,7 +52,7 @@ var options = {
4552
* @returns {Function} benchmark function
4653
*/
4754
function createBenchmark( len ) {
48-
var x = uniform( len, -10.0, 10.0, options );
55+
var x = filledarrayBy( len, 'float32', rand );
4956
return benchmark;
5057

5158
function benchmark( b ) {

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var uniform = require( '@stdlib/random/array/uniform' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
27+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2628
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2729
var pow = require( '@stdlib/math/base/special/pow' );
2830
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -35,13 +37,22 @@ var dsnanmeanpn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' )
3537
var opts = {
3638
'skip': ( dsnanmeanpn instanceof Error )
3739
};
38-
var options = {
39-
'dtype': 'float32'
40-
};
4140

4241

4342
// FUNCTIONS //
4443

44+
/**
45+
* Returns a random value or `NaN`.
46+
*
47+
* @returns {number} random number or `NaN`
48+
*/
49+
function rand() {
50+
if ( bernoulli( 0.2 ) ) {
51+
return NaN;
52+
}
53+
return uniform( -10.0, 10.0 );
54+
}
55+
4556
/**
4657
* Creates a benchmark function.
4758
*
@@ -50,7 +61,7 @@ var options = {
5061
* @returns {Function} benchmark function
5162
*/
5263
function createBenchmark( len ) {
53-
var x = uniform( len, -10.0, 10.0, options );
64+
var x = filledarrayBy( len, 'float32', rand );
5465
return benchmark;
5566

5667
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsnanmeanpn/benchmark/c/benchmark.length.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ static float rand_float( void ) {
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
9999
float x[ len ];
100-
float v;
100+
double v;
101101
double t;
102102
int i;
103103

104104
for ( i = 0; i < len; i++ ) {
105105
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
106106
}
107-
v = 0.0f;
107+
v = 0.0;
108108
t = tic();
109109
for ( i = 0; i < iterations; i++ ) {
110110
// cppcheck-suppress uninitvar
@@ -131,14 +131,14 @@ static double benchmark1( int iterations, int len ) {
131131
static double benchmark2( int iterations, int len ) {
132132
double elapsed;
133133
float x[ len ];
134-
float v;
134+
double v;
135135
double t;
136136
int i;
137137

138138
for ( i = 0; i < len; i++ ) {
139139
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
140140
}
141-
v = 0.0f;
141+
v = 0.0;
142142
t = tic();
143143
for ( i = 0; i < iterations; i++ ) {
144144
// cppcheck-suppress uninitvar

lib/node_modules/@stdlib/stats/base/dsnanmeanpn/docs/repl.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
array, ignoring `NaN` values, using a two-pass error correction algorithm
55
with extended accumulation, and returning an extended precision result.
66

7-
The `N` and stride parameters determine which elements in `x` are accessed
8-
at runtime.
7+
The `N` and stride parameters determine which elements in the strided array
8+
are accessed at runtime.
99

1010
Indexing is relative to the first index. To introduce an offset, use a typed
1111
array view.
@@ -23,7 +23,7 @@
2323
Input array.
2424

2525
strideX: integer
26-
Stride Length.
26+
Stride length.
2727

2828
Returns
2929
-------
@@ -37,16 +37,14 @@
3737
> {{alias}}( x.length, x, 1 )
3838
~0.3333
3939

40-
// Using `N` and `stride` parameters:
40+
// Using `N` and stride parameters:
4141
> x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ] );
4242
> {{alias}}( 3, x, 2 )
4343
~0.3333
4444

4545
// Using view offsets:
4646
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] );
4747
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
48-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
49-
> stride = 2;
5048
> {{alias}}( 3, x1, 2 )
5149
~-0.3333
5250

@@ -69,7 +67,7 @@
6967
Input array.
7068

7169
strideX: integer
72-
Stride Length.
70+
Stride length.
7371

7472
offsetX: integer
7573
Starting index.

lib/node_modules/@stdlib/stats/base/dsnanmeanpn/examples/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@
1818

1919
'use strict';
2020

21-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
21+
var randu = require( '@stdlib/random/base/randu' );
22+
var round = require( '@stdlib/math/base/special/round' );
23+
var Float32Array = require( '@stdlib/array/float32' );
2224
var dsnanmeanpn = require( './../lib' );
2325

24-
var x = discreteUniform( 10, -50, 50, {
25-
'dtype': 'float32'
26-
});
26+
var x;
27+
var i;
28+
29+
x = new Float32Array( 10 );
30+
for ( i = 0; i < x.length; i++ ) {
31+
if ( randu() < 0.2 ) {
32+
x[ i ] = NaN;
33+
} else {
34+
x[ i ] = round( (randu()*100.0) - 50.0 );
35+
}
36+
}
2737
console.log( x );
2838

2939
var v = dsnanmeanpn( x.length, x, 1 );

lib/node_modules/@stdlib/stats/base/dsnanmeanpn/include/stdlib/stats/base/dsnanmeanpn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434
double API_SUFFIX(stdlib_strided_dsnanmeanpn)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
3535

3636
/**
37-
* Computes the arithmetic mean value of a single-precision floating-point strided array using alternative indexing semantics.
37+
* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using a two-pass error correction algorithm with extended accumulation and alternative indexing semantics.
3838
*/
3939
double API_SUFFIX(stdlib_strided_dsnanmeanpn_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
4040

lib/node_modules/@stdlib/stats/base/dsnanmeanpn/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
4040
*
41-
* var v = dsnanmeanpn.ndarray( 5, x, 2, 1 );
41+
* var v = dsnanmeanpn.ndarray( 4, x, 2, 1 );
4242
* // returns 1.25
4343
*/
4444

0 commit comments

Comments
 (0)