Skip to content

Commit 578c6de

Browse files
chore: clean up
1 parent e7dd83f commit 578c6de

File tree

7 files changed

+61
-39
lines changed

7 files changed

+61
-39
lines changed

lib/node_modules/@stdlib/stats/base/dists/degenerate/logcdf/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_logcdf( x, mu )
144144

145-
Evaluates the logarithm of the cumulative distribution function (CDF) for a degneerate distribution with constant value of distribution `mu` at a value `x`.
145+
Evaluates the natural logarithm of the CDF of a degenerate distribution centered at `mu`.
146146

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

164152
The function accepts the following arguments:
@@ -194,15 +182,20 @@ double stdlib_base_dists_degenerate_logcdf( 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_logcdf( x, mu );
207200
printf( "x: %1f, µ: %1f, ln(F(x;µ)): %lf\n", x, mu , y );
208201
}

lib/node_modules/@stdlib/stats/base/dists/degenerate/logcdf/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 logcdf = require( './../lib' );
@@ -30,16 +31,25 @@ var logcdf = 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 = logcdf( x, mu );
52+
y = logcdf( 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 mylogcdf;
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
mylogcdf = logcdf.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 = mylogcdf( x );
84+
y = mylogcdf( x[ i%100 ] );
6985
if ( isnan( y ) ) {
7086
b.fail( 'should not return NaN' );
7187
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
var resolve = require( 'path' ).resolve;
2525
var bench = require( '@stdlib/bench' );
26-
var randu = require( '@stdlib/random/base/randu' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
27+
var Float64Array = require( '@stdlib/array/float64' );
2728
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2829
var tryRequire = require( '@stdlib/utils/try-require' );
2930
var pkg = require( './../package.json' ).name;

lib/node_modules/@stdlib/stats/base/dists/degenerate/logcdf/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( -100.0, 0.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 ) - 100.0;
103-
mu = ( ( (double)rand() / (double)RAND_MAX ) *100.0 ) - 50.0;
104-
y = stdlib_base_dists_degenerate_logcdf( x, mu );
111+
y = stdlib_base_dists_degenerate_logcdf( 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/logcdf/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_logcdf( x, mu );
3439
printf( "x: %1f, µ: %1f, ln(F(x;µ)): %lf\n", x, mu , y );
3540
}

lib/node_modules/@stdlib/stats/base/dists/degenerate/logcdf/include/stdlib/stats/base/dists/degenerate/logcdf.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 logarithm of the cumulative distribution function (LOGCDF) for a degneerate distribution with constant value of distribution `mu` at a value `x`.
30+
Evaluates the natural logarithm of the CDF of a degenerate distribution centered at `mu`.
3131
*/
3232
double stdlib_base_dists_degenerate_logcdf( const double x, const double mu );
3333

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "stdlib/constants/float64/ninf.h"
2222

2323
/**
24-
* Evaluates the logarithm of the cumulative distribution function (CDF) for a degneerate distribution with constant value of distribution `mu` at a value `x`.
24+
* Evaluates the natural logarithm of the CDF of a degenerate distribution centered at `mu`.
2525
*
2626
* @param x input value
2727
* @param mu constant value of distribution

0 commit comments

Comments
 (0)