Skip to content

Commit c2f2f75

Browse files
chore: minor clean up
1 parent 962a19b commit c2f2f75

File tree

8 files changed

+103
-46
lines changed

8 files changed

+103
-46
lines changed

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

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

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

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

@@ -68,15 +68,17 @@ The function has the following parameters:
6868

6969
- **N**: number of indexed elements.
7070
- **x**: input [`Float32Array`][@stdlib/array/float32].
71-
- **stride**: index increment for `x`.
71+
- **strideX**: stride length for `x`.
7272

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`,
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`,
7474

7575
```javascript
7676
var Float32Array = require( '@stdlib/array/float32' );
77-
var floor = require( '@stdlib/math/base/special/floor' );
7877

7978
var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
79+
80+
var v = dsmean( 4, x, 2 );
81+
// returns 1.25
8082
```
8183

8284
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
@@ -88,6 +90,9 @@ var Float32Array = require( '@stdlib/array/float32' );
8890

8991
var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
9092
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
93+
94+
var v = dsmean( 4, x1, 2 );
95+
// returns 1.25
9196
```
9297

9398
#### dsmean.ndarray( N, x, strideX, offsetX )
@@ -98,6 +103,9 @@ Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-p
98103
var Float32Array = require( '@stdlib/array/float32' );
99104

100105
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
106+
107+
var v = dsmean.ndarray( x.length, x, 1, 0 );
108+
// returns ~0.33333
101109
```
102110

103111
The function has the following additional parameters:
@@ -110,6 +118,9 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
110118
var Float32Array = require( '@stdlib/array/float32' );
111119

112120
var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
121+
122+
var v = dsmean.ndarray( 4, x, 2, 1 );
123+
// returns 1.25
113124
```
114125

115126
</section>
@@ -171,7 +182,7 @@ console.log( v );
171182
Computes the arithmetic mean of a single-precision floating-point strided array `x` using extended accumulation and returning an extended precision result.
172183

173184
```c
174-
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
185+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
175186

176187
double v = stdlib_strided_dsmean( 4, x, 2 );
177188
// returns 1.25
@@ -192,7 +203,7 @@ double stdlib_strided_dsmean( const CBLAS_INT N, const double *X, const CBLAS_IN
192203
Computes the arithmetic mean of a single-precision floating-point strided array `x` using extended accumulation and alternative indexing semantics and returning an extended precision result.
193204

194205
```c
195-
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
206+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
196207

197208
double v = stdlib_strided_dsmean_ndarray( 4, x, 2, 0 );
198209
// returns 1.25
@@ -233,13 +244,13 @@ double stdlib_strided_dsmean_ndarray( const CBLAS_INT N, const double *X, const
233244

234245
int main( void ) {
235246
// Create a strided array:
236-
float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
247+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
237248

238249
// Specify the number of elements:
239250
const int N = 4;
240251

241252
// Specify the stride length:
242-
const int stride = 2;
253+
const int strideX = 2;
243254

244255
// Compute the arithmetic mean:
245256
double v = stdlib_strided_dsmean( N, x, strideX );

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,30 @@
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 dsmean = require( './../lib/dsmean.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+
* @private
39+
* @returns {number} random number or `NaN`
40+
*/
41+
function rand() {
42+
if ( bernoulli( 0.2 ) ) {
43+
return NaN;
44+
}
45+
return uniform( -10.0, 10.0 );
46+
}
47+
4048
/**
4149
* Creates a benchmark function.
4250
*
@@ -45,7 +53,7 @@ var options = {
4553
* @returns {Function} benchmark function
4654
*/
4755
function createBenchmark( len ) {
48-
var x = uniform( len, -10.0, 10.0, options );
56+
var x = filledarrayBy( len, 'float32', rand );
4957
return benchmark;
5058

5159
function benchmark( b ) {

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

Lines changed: 17 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,23 @@ var dsmean = tryRequire( resolve( __dirname, './../lib/dsmean.native.js' ) );
3537
var opts = {
3638
'skip': ( dsmean 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+
* @private
48+
* @returns {number} random number or `NaN`
49+
*/
50+
function rand() {
51+
if ( bernoulli( 0.2 ) ) {
52+
return NaN;
53+
}
54+
return uniform( -10.0, 10.0 );
55+
}
56+
4557
/**
4658
* Creates a benchmark function.
4759
*
@@ -50,7 +62,7 @@ var options = {
5062
* @returns {Function} benchmark function
5163
*/
5264
function createBenchmark( len ) {
53-
var x = uniform( len, -10.0, 10.0, options );
65+
var x = filledarrayBy( len, 'float32', rand );
5466
return benchmark;
5567

5668
function benchmark( b ) {

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,30 @@
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 dsmean = 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+
* @private
39+
* @returns {number} random number or `NaN`
40+
*/
41+
function rand() {
42+
if ( bernoulli( 0.2 ) ) {
43+
return NaN;
44+
}
45+
return uniform( -10.0, 10.0 );
46+
}
47+
4048
/**
4149
* Creates a benchmark function.
4250
*
@@ -45,7 +53,7 @@ var options = {
4553
* @returns {Function} benchmark function
4654
*/
4755
function createBenchmark( len ) {
48-
var x = uniform( len, -10.0, 10.0, options );
56+
var x = filledarrayBy( len, 'float32', rand );
4957
return benchmark;
5058

5159
function benchmark( b ) {

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

Lines changed: 17 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,23 @@ var dsmean = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3537
var opts = {
3638
'skip': ( dsmean 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+
* @private
48+
* @returns {number} random number or `NaN`
49+
*/
50+
function rand() {
51+
if ( bernoulli( 0.2 ) ) {
52+
return NaN;
53+
}
54+
return uniform( -10.0, 10.0 );
55+
}
56+
4557
/**
4658
* Creates a benchmark function.
4759
*
@@ -50,7 +62,7 @@ var options = {
5062
* @returns {Function} benchmark function
5163
*/
5264
function createBenchmark( len ) {
53-
var x = uniform( len, -10.0, 10.0, options );
65+
var x = filledarrayBy( len, 'float32', rand );
5466
return benchmark;
5567

5668
function benchmark( b ) {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
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 dsmean = 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+
x[ i ] = round( (randu()*100.0) - 50.0 );
32+
}
2733
console.log( x );
2834

2935
var v = dsmean( x.length, x, 1 );

lib/node_modules/@stdlib/stats/base/dsmean/src/addon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/stats/base/dsmean/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -24,10 +24,10 @@
2424
/**
2525
* Computes the arithmetic mean of a single-precision floating-point strided array using extended accumulation and returning an extended precision result.
2626
*
27-
* @param N number of indexed elements
28-
* @param X input array
29-
* @param stride stride length
30-
* @return output value
27+
* @param N number of indexed elements
28+
* @param X input array
29+
* @param strideX stride length
30+
* @return output value
3131
*/
3232
double API_SUFFIX(stdlib_strided_dsmean)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
3333
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );

0 commit comments

Comments
 (0)