Skip to content

Commit e6880de

Browse files
chore: clean up
1 parent d293e07 commit e6880de

File tree

7 files changed

+73
-42
lines changed

7 files changed

+73
-42
lines changed

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/README.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,11 @@ for ( i = 0; i < 100; i++ ) {
142142

143143
#### stdlib_base_dists_degenerate_cdf( x, mu )
144144

145-
Evaluates the cumulative distribution function (CDF) for an degenerate distribution.
145+
Evaluates the cumulative distribution function (CDF) for an degenerate distribution centered at `mu`.
146146

147147
```c
148148
double y = stdlib_base_dists_degenerate_cdf( 2.0, 3.0 );
149149
// returns ~0.0
150-
151-
y = stdlib_base_dists_degenerate_cdf( 4.0, 3.0 );
152-
// returns ~1.0
153-
154-
y = stdlib_base_dists_degenerate_cdf( 3.0, 3.0 );
155-
// returns ~1.0
156-
157-
y = stdlib_base_dists_degenerate_cdf( NaN, 0.0 );
158-
// returns NaN
159-
160-
y = stdlib_base_dists_degenerate_cdf( 0.0, NaN );
161-
// returns NaN
162150
```
163151

164152
The function accepts the following arguments:
@@ -194,15 +182,20 @@ double stdlib_base_dists_degenerate_cdf( const double x, const double mu );
194182
#include <stdlib.h>
195183
#include <stdio.h>
196184
185+
static double random_uniform( const double min, const double max ) {
186+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
187+
return min + ( v*(max-min) );
188+
}
189+
197190
int main( void ) {
198191
double mu;
199192
double x;
200193
double y;
201194
int i;
202195
203-
for ( i = 0; i < 25; i++ ) {
204-
x = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 );
205-
mu = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 );
196+
for ( i = 0; i < 10; i++ ) {
197+
x = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
198+
mu = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
206199
y = stdlib_base_dists_degenerate_cdf( x, mu );
207200
printf( "x: %1f, µ: %1f, F(x;µ): %lf\n", x, mu , y );
208201
}

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/benchmark/benchmark.js

Lines changed: 22 additions & 6 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 pkg = require( './../package.json' ).name;
2728
var cdf = require( './../lib' );
@@ -30,16 +31,25 @@ var cdf = require( './../lib' );
3031
// MAIN //
3132

3233
bench( pkg, function benchmark( b ) {
34+
var len;
3335
var mu;
3436
var x;
3537
var y;
3638
var i;
3739

40+
len = 100;
41+
x = new Float64Array( len );
42+
for ( i = 0; i < len; i++ ) {
43+
x[ i ] = uniform( -100.0, 0.0 );
44+
}
45+
mu = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
mu[ i ] = uniform( -50.0, 50.0 );
48+
}
49+
3850
b.tic();
3951
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu()*100.0 ) - 100;
41-
mu = ( randu()*100.0 ) - 50.0;
42-
y = cdf( x, mu );
52+
y = cdf( x[ i%100 ], mu[ i%100 ] );
4353
if ( isnan( y ) ) {
4454
b.fail( 'should not return NaN' );
4555
}
@@ -54,6 +64,7 @@ bench( pkg, function benchmark( b ) {
5464

5565
bench( pkg+':factory', function benchmark( b ) {
5666
var mycdf;
67+
var len;
5768
var mu;
5869
var x;
5970
var y;
@@ -62,10 +73,15 @@ bench( pkg+':factory', function benchmark( b ) {
6273
mu = 40.0;
6374
mycdf = cdf.factory( mu );
6475

76+
len = 100;
77+
x = new Float64Array( len );
78+
for ( i = 0; i < len; i++ ) {
79+
x[ i ] = uniform( 0.0, 100.0 );
80+
}
81+
6582
b.tic();
6683
for ( i = 0; i < b.iterations; i++ ) {
67-
x = ( randu()*100.0 );
68-
y = mycdf( x );
84+
y = mycdf( x[ i%100 ] );
6985
if ( isnan( y ) ) {
7086
b.fail( 'should not return NaN' );
7187
}

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/benchmark/benchmark.native.js

Lines changed: 14 additions & 4 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 pkg = require( './../package.json' ).name;
@@ -39,16 +40,25 @@ var opts = {
3940
// MAIN //
4041

4142
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var len;
4244
var mu;
4345
var x;
4446
var y;
4547
var i;
4648

49+
len = 100;
50+
x = new Float64Array( len );
51+
for ( i = 0; i < len; i++ ) {
52+
x[ i ] = uniform( -100.0, 0.0 );
53+
}
54+
mu = new Float64Array( len );
55+
for ( i = 0; i < len; i++ ) {
56+
mu[ i ] = uniform( -50.0, 50.0 );
57+
}
58+
4759
b.tic();
4860
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*100.0 ) - 100;
50-
mu = ( randu()*100.0 ) - 50.0;
51-
y = cdf( x, mu );
61+
y = cdf( x[ i%100 ], mu[ i%100 ] );
5262
if ( isnan( y ) ) {
5363
b.fail( 'should not return NaN' );
5464
}

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/benchmark/c/benchmark.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ static double tic( void ) {
7575
}
7676

7777
/**
78-
* Generates a random number on the interval [0,1).
78+
* Generates a random number on the interval [min,max).
7979
*
80-
* @return random number
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
8183
*/
82-
static double rand_double( void ) {
83-
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
static double random_uniform( const double min, const double max ) {
85+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
86+
return min + ( v*(max-min) );
8587
}
8688

8789
/**
@@ -91,17 +93,22 @@ static double rand_double( void ) {
9193
*/
9294
static double benchmark( void ) {
9395
double elapsed;
94-
double mu;
95-
double x;
96+
double mu[ 100 ];
97+
double x[ 100 ];
9698
double y;
9799
double t;
98100
int i;
99101

102+
for ( i = 0; i < 100; i++ ) {
103+
x[ i ] = random_uniform( -1.0, 99.0 );
104+
}
105+
for ( i = 0; i < 100; i++ ) {
106+
mu[ i ] = random_uniform( -50.0, 50.0 );
107+
}
108+
100109
t = tic();
101110
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( ( (double)rand() / (double)RAND_MAX )*100.0 ) - 1.0;
103-
mu = ( ( (double)rand() / (double)RAND_MAX )* 100.0 ) - 50.0;
104-
y = stdlib_base_dists_degenerate_cdf( x, mu );
111+
y = stdlib_base_dists_degenerate_cdf( x[ i%100 ], mu[ i%100 ] );
105112
if ( y != y ) {
106113
printf( "should not return NaN\n" );
107114
break;

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/examples/c/example.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@
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 ) {
2530
double mu;
26-
double x;
31+
double x;
2732
double y;
2833
int i;
2934

30-
for ( i = 0; i < 25; i++ ) {
31-
x = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 );
32-
mu = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 );
35+
for ( i = 0; i < 10; i++ ) {
36+
x = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
37+
mu = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
3338
y = stdlib_base_dists_degenerate_cdf( x, mu );
3439
printf( "x: %1f, µ: %1f, F(x;µ): %lf\n", x, mu , y );
3540
}

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/include/stdlib/stats/base/dists/degenerate/cdf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
Evaluates the cumulative distribution function (CDF) for a degenerate distribution with constant value of distribution `mu` at a value `x`.
30+
Evaluates the cumulative distribution function (CDF) for an degenerate distribution centered at `mu`.
3131
*/
3232
double stdlib_base_dists_degenerate_cdf( const double x, const double mu );
3333

lib/node_modules/@stdlib/stats/base/dists/degenerate/cdf/src/main.c

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

2222
/**
23-
* Evaluates the cumulative distribution function (CDF) for a degenerate distribution with constant value of distribution `mu` at a value `x`.
23+
* Evaluates the cumulative distribution function (CDF) for an degenerate distribution centered at `mu`.
2424
*
2525
* @param x input value
2626
* @param mu constant value of distribution

0 commit comments

Comments
 (0)