Skip to content

Commit 27ba79f

Browse files
fix: stuff from code review
1 parent a85ec92 commit 27ba79f

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ double stdlib_base_dists_betaprime_mean( const double alpha, const double beta )
192192
193193
<!-- /.usage -->
194194
195-
<!-- C API usage notes. Make sure to keep an empty line after the `section`
195+
<!-- C API usage notes. Make sure to keep an empty line after the `section`
196196
element and another before the `/section` close. -->
197197
198198
<section class="notes">
@@ -208,10 +208,15 @@ element and another before the `/section` close. -->
208208
### Examples
209209
210210
```c
211-
#include "stdlib/stats/base/dists/betaprime/mean.h"
212211
#include "stdlib/constants/float64/eps.h"
213-
#include <stdlib.h>
212+
#include "stdlib/stats/base/dists/betaprime/mean.h"
214213
#include <stdio.h>
214+
#include <stdlib.h>
215+
216+
static double random_uniform( const double min, const double max ) {
217+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
218+
return min + ( v * ( max - min ) );
219+
}
215220
216221
int main( void ) {
217222
double alpha;
@@ -220,9 +225,9 @@ int main( void ) {
220225
int i;
221226
222227
for ( i = 0; i < 10; i++ ) {
223-
alpha = ( ( (double)rand() / (double)RAND_MAX )*10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
224-
beta = ( ( (double)rand() / (double)RAND_MAX )*10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
225-
y = stdlib_base_dists_betaprime_mean( x, alpha, beta );
228+
alpha = ( random_uniform( -10.0, 10.0 ) * 10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
229+
beta = ( random_uniform( -20.0, 0.0 ) * 10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
230+
y = stdlib_base_dists_betaprime_mean( alpha, beta );
226231
printf( "α: %1f, β: %1f, E(X;α,β): %lf\n", alpha, beta, y );
227232
}
228233
}

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/stats/base/dists/betaprime/mean.h"
19+
#include <sys/time.h>
2020
#include "stdlib/constants/float64/eps.h"
21-
#include <stdlib.h>
22-
#include <stdio.h>
21+
#include "stdlib/stats/base/dists/betaprime/mean.h"
2322
#include <math.h>
23+
#include <stdio.h>
24+
#include <stdlib.h>
2425
#include <time.h>
25-
#include <sys/time.h>
2626

2727
#define NAME "betaprime-mean"
2828
#define ITERATIONS 1000000
@@ -72,7 +72,7 @@ static void print_results( double elapsed ) {
7272
static double tic( void ) {
7373
struct timeval now;
7474
gettimeofday( &now, NULL );
75-
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
75+
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
7676
}
7777

7878
/**
@@ -83,8 +83,8 @@ static double tic( void ) {
8383
* @return random number
8484
*/
8585
static double random_uniform( const double min, const double max ) {
86-
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
87-
return min + ( v*(max-min) );
86+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
87+
return min + ( v * ( max - min ) );
8888
}
8989

9090
/**
@@ -95,16 +95,22 @@ static double random_uniform( const double min, const double max ) {
9595
static double benchmark( void ) {
9696
double elapsed;
9797
double alpha;
98-
double beta;
98+
double beta;
9999
double y;
100100
double t;
101101
int i;
102102

103+
for ( i = 0; i < 100; i++ ) {
104+
alpha = random_uniform( -10.0, 10.0 );
105+
beta = random_uniform( -20.0, 0.0 );
106+
y = random_uniform( alpha, beta + 40.0 );
107+
}
108+
103109
t = tic();
104110
for ( i = 0; i < ITERATIONS; i++ ) {
105-
alpha = ( ( (double)rand() / (double)RAND_MAX )*10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
106-
beta = ( ( (double)rand() / (double)RAND_MAX )*10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
107-
y = stdlib_base_dists_betaprime_mean( alpha, beta );
111+
alpha = ( ( (double)rand() / (double)RAND_MAX ) * 10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
112+
beta = ( ( (double)rand() / (double)RAND_MAX ) * 10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
113+
y = stdlib_base_dists_betaprime_mean( alpha, beta );
108114
if ( y != y ) {
109115
printf( "should not return NaN\n" );
110116
break;
@@ -124,15 +130,15 @@ int main( void ) {
124130
double elapsed;
125131
int i;
126132

127-
// Use the current time to seed the random number generator:
133+
// Use the current time to seed the random number generator:
128134
srand( time( NULL ) );
129135

130136
print_version();
131137
for ( i = 0; i < REPEATS; i++ ) {
132138
printf( "# c::%s\n", NAME );
133139
elapsed = benchmark();
134140
print_results( elapsed );
135-
printf( "ok %d benchmark finished\n", i+1 );
141+
printf( "ok %d benchmark finished\n", i + 1 );
136142
}
137143
print_summary( REPEATS, REPEATS );
138144
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,26 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/stats/base/dists/betaprime/mean.h"
2019
#include "stdlib/constants/float64/eps.h"
21-
#include <stdlib.h>
20+
#include "stdlib/stats/base/dists/betaprime/mean.h"
2221
#include <stdio.h>
22+
#include <stdlib.h>
23+
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+
}
2328

2429
int main( void ) {
25-
double alpha;
26-
double beta;
30+
double alpha;
31+
double beta;
2732
double y;
2833
int i;
2934

3035
for ( i = 0; i < 10; i++ ) {
31-
alpha = ( ( (double)rand() / (double)RAND_MAX )*10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
32-
beta = ( ( (double)rand() / (double)RAND_MAX )*10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
33-
y = stdlib_base_dists_betaprime_mean( alpha, beta );
34-
printf( "α: %1f, β: %1f, E(X;α,β): %lf\n", alpha, beta, y );
36+
alpha = ( random_uniform( -10.0, 10.0 ) * 10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
37+
beta = ( random_uniform( -20.0, 0.0 ) * 10.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
38+
y = stdlib_base_dists_betaprime_mean( alpha, beta );
39+
printf( "α: %1f, β: %1f, E(X;α,β): %lf\n", alpha, beta, y );
3540
}
3641
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "stdlib/stats/base/dists/betaprime/mean.h"
1920

2021
/**
2122
* Evaluates the mean for a beta prime distribution with first shape parameter `alpha` and second shape parameter `beta`.
2223
*
23-
* @param x input value
24+
* @private
25+
* @param x input value
2426
* @param alpha first shape parameter
25-
* @param beta second shape parameter
26-
* @returns evaluated logPDF
27+
* @param beta second shape parameter
28+
* @returns evaluated logPDF
2729
*
2830
* @example
2931
* double y = stdlib_base_dists_betaprime_mean( 1.0, 2.0 );
3032
* // returns ~1.0
3133
*/
3234
double stdlib_base_dists_betaprime_mean( double alpha, const double beta ) {
33-
if ( alpha <= 0.0 || beta <= 1.0 ) {
35+
if ( alpha <= 0.0 || beta <= 1.0 ) {
3436
return 0.0 / 0.0;
3537
}
3638
return alpha / ( beta - 1.0 );

0 commit comments

Comments
 (0)