Skip to content

Commit 27e23e1

Browse files
feat: updating files
1 parent 54f1fbe commit 27e23e1

File tree

9 files changed

+261
-96
lines changed

9 files changed

+261
-96
lines changed

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

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

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

5656
Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array `x`, using Welford's algorithm and ignoring `NaN` values.
5757

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

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

64-
var v = dnanmeanwd( N, x, 1 );
63+
var v = dnanmeanwd( 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 [`Float64Array`][@stdlib/array/float64].
72-
- **stride**: index increment for `x`.
71+
- **strideX**: index increment 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 stride 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 Float64Array = require( '@stdlib/array/float64' );
7877
var floor = require( '@stdlib/math/base/special/floor' );
7978

8079
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ] );
81-
var N = floor( x.length / 2 );
8280

83-
var v = dnanmeanwd( N, x, 2 );
81+
var v = dnanmeanwd( 5, x, 2 );
8482
// returns 1.25
8583
```
8684

@@ -95,40 +93,35 @@ var floor = require( '@stdlib/math/base/special/floor' );
9593
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
9694
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9795

98-
var N = floor( x0.length / 2 );
99-
100-
var v = dnanmeanwd( N, x1, 2 );
96+
var v = dnanmeanwd( 5, x1, 2 );
10197
// returns 1.25
10298
```
10399

104-
#### dnanmeanwd.ndarray( N, x, stride, offset )
100+
#### dnanmeanwd.ndarray( N, x, strideX, offsetX )
105101

106102
Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics.
107103

108104
```javascript
109105
var Float64Array = require( '@stdlib/array/float64' );
110106

111107
var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
112-
var N = x.length;
113108

114-
var v = dnanmeanwd.ndarray( N, x, 1, 0 );
109+
var v = dnanmeanwd.ndarray( x.length, x, 1, 0 );
115110
// returns ~0.33333
116111
```
117112

118113
The function has the following additional parameters:
119114

120-
- **offset**: starting index for `x`.
115+
- **offsetX**: starting index for `x`.
121116

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
117+
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
123118

124119
```javascript
125120
var Float64Array = require( '@stdlib/array/float64' );
126-
var floor = require( '@stdlib/math/base/special/floor' );
127121

128122
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
129-
var N = floor( x.length / 2 );
130123

131-
var v = dnanmeanwd.ndarray( N, x, 2, 1 );
124+
var v = dnanmeanwd.ndarray( 5, x, 2, 1 );
132125
// returns 1.25
133126
```
134127

@@ -180,6 +173,121 @@ console.log( v );
180173

181174
<!-- /.examples -->
182175

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

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
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' );
27-
var Float64Array = require( '@stdlib/array/float64' );
2829
var pkg = require( './../package.json' ).name;
2930
var dnanmeanwd = require( './../lib/dnanmeanwd.js' );
3031

3132

3233
// FUNCTIONS //
3334

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+
3447
/**
3548
* Creates a benchmark function.
3649
*
@@ -39,17 +52,7 @@ var dnanmeanwd = require( './../lib/dnanmeanwd.js' );
3952
* @returns {Function} benchmark function
4053
*/
4154
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float64Array( len );
46-
for ( i = 0; i < x.length; i++ ) {
47-
if ( randu() < 0.2 ) {
48-
x[ i ] = NaN;
49-
} else {
50-
x[ i ] = ( randu()*20.0 ) - 10.0;
51-
}
52-
}
55+
var x = filledarrayBy( len, 'float64', rand );
5356
return benchmark;
5457

5558
function benchmark( b ) {

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
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/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' );
28-
var Float64Array = require( '@stdlib/array/float64' );
2930
var tryRequire = require( '@stdlib/utils/try-require' );
3031
var pkg = require( './../package.json' ).name;
3132

@@ -40,6 +41,18 @@ var opts = {
4041

4142
// FUNCTIONS //
4243

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+
4356
/**
4457
* Creates a benchmark function.
4558
*
@@ -48,17 +61,7 @@ var opts = {
4861
* @returns {Function} benchmark function
4962
*/
5063
function createBenchmark( len ) {
51-
var x;
52-
var i;
53-
54-
x = new Float64Array( len );
55-
for ( i = 0; i < x.length; i++ ) {
56-
if ( randu() < 0.2 ) {
57-
x[ i ] = NaN;
58-
} else {
59-
x[ i ] = ( randu()*20.0 ) - 10.0;
60-
}
61-
}
64+
var x = filledarrayBy( len, 'float64', rand );
6265
return benchmark;
6366

6467
function benchmark( b ) {

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
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' );
27-
var Float64Array = require( '@stdlib/array/float64' );
2829
var pkg = require( './../package.json' ).name;
2930
var dnanmeanwd = require( './../lib/ndarray.js' );
3031

3132

3233
// FUNCTIONS //
3334

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+
3447
/**
3548
* Creates a benchmark function.
3649
*
@@ -39,17 +52,7 @@ var dnanmeanwd = require( './../lib/ndarray.js' );
3952
* @returns {Function} benchmark function
4053
*/
4154
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float64Array( len );
46-
for ( i = 0; i < x.length; i++ ) {
47-
if ( randu() < 0.2 ) {
48-
x[ i ] = NaN;
49-
} else {
50-
x[ i ] = ( randu()*20.0 ) - 10.0;
51-
}
52-
}
55+
var x = filledarrayBy( len, 'float64', rand );
5356
return benchmark;
5457

5558
function benchmark( b ) {

0 commit comments

Comments
 (0)