Skip to content

Commit 8b80f9e

Browse files
chore: clean up
1 parent 09e86c6 commit 8b80f9e

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ element and another before the `/section` close. -->
179179
### Examples
180180
181181
```c
182-
#include "stdlib/stats/base/dists/chisquare/mean.h"
183-
#include "stdlib/constants/float64/eps.h"
184-
#include <stdlib.h>
185-
#include <stdio.h>
182+
static double random_uniform( const double min, const double max ) {
183+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
184+
return min + ( v*(max-min) );
185+
}
186186
187187
int main( void ) {
188188
double k;
189189
double y;
190190
int i;
191191
192192
for ( i = 0; i < 10; i++ ) {
193-
k = ( (double)rand() / (double)RAND_MAX ) * 20.0;
193+
k = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
194194
y = stdlib_base_dists_chisquare_mean( k );
195195
printf( "k: %1f, E(X;k): %lf\n", k, y );
196196
}

lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/benchmark/benchmark.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
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 Float64Array = require( '@stdlib/array/float64' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var EPS = require( '@stdlib/constants/float64/eps' );
2728
var pkg = require( './../package.json' ).name;
@@ -31,14 +32,20 @@ var mean = require( './../lib' );
3132
// MAIN //
3233

3334
bench( pkg, function benchmark( b ) {
35+
var len;
3436
var k;
3537
var y;
3638
var i;
3739

40+
len = 100;
41+
k = new Float64Array( len );
42+
for ( i = 0; i < len; i++ ) {
43+
k[ i ] = uniform( EPS, 20.0 );
44+
}
45+
3846
b.tic();
3947
for ( i = 0; i < b.iterations; i++ ) {
40-
k = ( randu()*20.0 ) + EPS;
41-
y = mean( k );
48+
y = mean( k[ i%100 ] );
4249
if ( isnan( y ) ) {
4350
b.fail( 'should not return NaN' );
4451
}

lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/benchmark/benchmark.native.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
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 Float64Array = require( '@stdlib/array/float64' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829
var EPS = require( '@stdlib/constants/float64/eps' );
@@ -40,14 +41,20 @@ var opts = {
4041
// MAIN //
4142

4243
bench( pkg+'::native', opts, function benchmark( b ) {
44+
var len;
4345
var k;
4446
var y;
4547
var i;
4648

49+
len = 100;
50+
k = new Float64Array( len );
51+
for ( i = 0; i < len; i++ ) {
52+
k[ i ] = uniform( EPS, 20.0 );
53+
}
54+
4755
b.tic();
4856
for ( i = 0; i < b.iterations; i++ ) {
49-
k = ( randu()*20.0 ) + EPS;
50-
y = mean( k );
57+
y = mean( k[ i%100 ] );
5158
if ( isnan( y ) ) {
5259
b.fail( 'should not return NaN' );
5360
}

lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,18 @@ static double random_uniform( const double min, const double max ) {
9494
*/
9595
static double benchmark( void ) {
9696
double elapsed;
97-
double k;
97+
double k[ 100 ];
9898
double y;
9999
double t;
100100
int i;
101101

102+
for ( i = 0; i < 100; i++ ) {
103+
k[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
104+
}
105+
102106
t = tic();
103107
for ( i = 0; i < ITERATIONS; i++ ) {
104-
k = ( ( (double)rand() / (double)RAND_MAX )*20.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
105-
y = stdlib_base_dists_chisquare_mean( k );
108+
y = stdlib_base_dists_chisquare_mean( k[ i%100 ] );
106109
if ( y != y ) {
107110
printf( "should not return NaN\n" );
108111
break;

lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/examples/c/example.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@
2121
#include <stdlib.h>
2222
#include <stdio.h>
2323

24+
static double random_uniform( const double min, const double max ) {
25+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
26+
return min + ( v*(max-min) );
27+
}
28+
2429
int main( void ) {
25-
double k;
30+
double k;
2631
double y;
2732
int i;
2833

2934
for ( i = 0; i < 10; i++ ) {
30-
k = ( (double)rand() / (double)RAND_MAX ) * 20.0;
31-
y = stdlib_base_dists_chisquare_mean( k );
32-
printf( "k: %1f, E(X;k): %lf\n", k, y );
35+
k = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
36+
y = stdlib_base_dists_chisquare_mean( k );
37+
printf( "k: %1f, E(X;k): %lf\n", k, y );
3338
}
3439
}

lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "stdlib/math/base/assert/is_nan.h"
2121

2222
/**
23-
* Returns the expected value of a chi-squared distribution.
23+
* Returns the expected value of a chi-squared distribution with degerees of freedom `k`.
2424
*
2525
* @param k degrees of freedom
2626
* @returns evaluated mean
@@ -42,7 +42,7 @@
4242
* // returns NaN
4343
*/
4444
double stdlib_base_dists_chisquare_mean( const double k ) {
45-
if ( stdlib_base_is_nan( k ) || k < 0.0 ) {
45+
if ( stdlib_base_is_nan( k ) || k < 0.0 ) {
4646
return 0.0 / 0.0;
4747
}
4848
return k;

0 commit comments

Comments
 (0)