Skip to content

Commit 876aac6

Browse files
authored
bench: update random value generation
PR-URL: #6330 Reviewed-by: Athan Reines <[email protected]>
1 parent 83ae24b commit 876aac6

File tree

10 files changed

+55
-49
lines changed

10 files changed

+55
-49
lines changed

lib/node_modules/@stdlib/math/base/special/gamma-delta-ratio/benchmark/benchmark.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var gamma = require( '@stdlib/math/base/special/gamma' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pkg = require( './../package.json' ).name;
2828
var gammaDeltaRatio = require( './../lib' );
@@ -36,11 +36,12 @@ bench( pkg, function benchmark( b ) {
3636
var y;
3737
var i;
3838

39+
z = uniform( 100, 0.0, 100.0 );
40+
delta = uniform( 100, 0.0, 100.0 );
41+
3942
b.tic();
4043
for ( i = 0; i < b.iterations; i++ ) {
41-
z = randu()*100.0;
42-
delta = randu()*100.0;
43-
y = gammaDeltaRatio( z, delta );
44+
y = gammaDeltaRatio( z[ i%z.length ], delta[ i%delta.length ] );
4445
if ( isnan( y ) ) {
4546
b.fail( 'should not return NaN' );
4647
}
@@ -59,11 +60,12 @@ bench( pkg+'::naive', function benchmark( b ) {
5960
var y;
6061
var i;
6162

63+
z = uniform( 100, 0.0, 100.0 );
64+
delta = uniform( 100, 0.0, 100.0 );
65+
6266
b.tic();
6367
for ( i = 0; i < b.iterations; i++ ) {
64-
z = randu()*100.0;
65-
delta = randu()*100.0;
66-
y = gamma( z ) / gamma( z + delta );
68+
y = gamma( z[ i%z.length ] ) / gamma( z[ i%z.length ] + delta[ i%delta.length ] );
6769
if ( isnan( y ) ) {
6870
b.fail( 'should not return NaN' );
6971
}

lib/node_modules/@stdlib/math/base/special/gamma-delta-ratio/benchmark/benchmark.native.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
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/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4444
var y;
4545
var i;
4646

47+
z = uniform( 100, 0.0, 100.0 );
48+
delta = uniform( 100, 0.0, 100.0 );
49+
4750
b.tic();
4851
for ( i = 0; i < b.iterations; i++ ) {
49-
z = randu() * 100.0;
50-
delta = randu() * 100.0;
51-
y = gammaDeltaRatio( z, delta );
52+
y = gammaDeltaRatio( z[ i%z.length ], delta[ i%delta.length ] );
5253
if ( isnan( y ) ) {
5354
b.fail( 'should not return NaN' );
5455
}

lib/node_modules/@stdlib/math/base/special/gamma-delta-ratio/benchmark/c/native/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double delta;
95-
double z;
94+
double delta[ 100 ];
95+
double z[ 100 ];
9696
double y;
9797
double t;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
z[ i ] = ( rand_double() * 100.0 );
102+
delta[ i ] = ( rand_double() * 100.0 );
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
z = ( rand_double() * 100.0 );
103-
delta = ( rand_double() * 100.0 );
104-
y = stdlib_base_gamma_delta_ratio( z, delta );
107+
y = stdlib_base_gamma_delta_ratio( z[ i%100 ], delta[ i%100 ] );
105108
if ( y != y ) {
106109
printf( "should not return NaN\n" );
107110
break;

lib/node_modules/@stdlib/math/base/special/gamma-delta-ratio/test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ tape( 'the function returns `NaN` if provided `NaN` for either parameter', funct
4949
var v;
5050

5151
v = gammaDeltaRatio( NaN, 5.0 );
52-
t.equal( isnan( v ), true, 'returns NaN' );
52+
t.equal( isnan( v ), true, 'returns expected value' );
5353

5454
v = gammaDeltaRatio( 1.0, NaN );
55-
t.equal( isnan( v ), true, 'returns NaN' );
55+
t.equal( isnan( v ), true, 'returns expected value' );
5656

5757
v = gammaDeltaRatio( NaN, NaN );
58-
t.equal( isnan( v ), true, 'returns NaN' );
58+
t.equal( isnan( v ), true, 'returns expected value' );
5959

6060
t.end();
6161
});
@@ -64,10 +64,10 @@ tape( 'the function returns `0` for very large `z` and negligible `delta`', func
6464
var v;
6565

6666
v = gammaDeltaRatio( 1.0e100, 20.7 );
67-
t.equal( v, 0.0, 'returns 0' );
67+
t.equal( v, 0.0, 'returns expected value' );
6868

6969
v = gammaDeltaRatio( 1.0e120, 100.1 );
70-
t.equal( v, 0.0, 'returns 0' );
70+
t.equal( v, 0.0, 'returns expected value' );
7171

7272
t.end();
7373
});

lib/node_modules/@stdlib/math/base/special/gamma-delta-ratio/test/test.native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ tape( 'the function returns `0` for very large `z` and negligible `delta`', opts
7373
var v;
7474

7575
v = gammaDeltaRatio( 1.0e100, 20.7 );
76-
t.equal( v, 0.0, 'returns 0' );
76+
t.equal( v, 0.0, 'returns expected value' );
7777

7878
v = gammaDeltaRatio( 1.0e120, 100.1 );
79-
t.equal( v, 0.0, 'returns 0' );
79+
t.equal( v, 0.0, 'returns expected value' );
8080

8181
t.end();
8282
});

lib/node_modules/@stdlib/math/base/special/gamma/benchmark/benchmark.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/array/uniform' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pkg = require( './../package.json' ).name;
2727
var gammaBoost = require( './../lib/boost/gamma.js' );
@@ -35,7 +35,7 @@ bench( pkg, function benchmark( b ) {
3535
var y;
3636
var i;
3737

38-
x = randu( 100, 0.0, 171.0 );
38+
x = uniform( 100, 0.0, 171.0 );
3939

4040
b.tic();
4141
for ( i = 0; i < b.iterations; i++ ) {
@@ -57,7 +57,7 @@ bench( pkg+'::boost', function benchmark( b ) {
5757
var y;
5858
var i;
5959

60-
x = randu( 100, 0.0, 171.0 );
60+
x = uniform( 100, 0.0, 171.0 );
6161

6262
b.tic();
6363
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/math/base/special/gamma/benchmark/benchmark.native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/array/uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,7 +43,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = randu( 100, 0.0, 171.0 );
46+
x = uniform( 100, 0.0, 171.0 );
4747

4848
b.tic();
4949
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/math/base/special/gamma/test/test.boost.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,32 @@ tape( 'if provided a negative integer, the function returns `NaN`', function tes
5252

5353
for ( i = 0; i < values.length; i++ ) {
5454
v = gamma( values[ i ] );
55-
t.equal( isnan( v ), true, 'returns NaN when provided ' + values[ i ] );
55+
t.equal( isnan( v ), true, 'returns expected value when provided ' + values[ i ] );
5656
}
5757
t.end();
5858
});
5959

6060
tape( 'if provided negative infinity, the function returns `NaN`', function test( t ) {
6161
var v = gamma( NINF );
62-
t.equal( isnan( v ), true, 'returns NaN when provided negative infinity' );
62+
t.equal( isnan( v ), true, 'returns expected value' );
6363
t.end();
6464
});
6565

6666
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
6767
var v = gamma( NaN );
68-
t.equal( isnan( v ), true, 'returns NaN when provided a NaN' );
68+
t.equal( isnan( v ), true, 'returns expected value' );
6969
t.end();
7070
});
7171

7272
tape( 'if provided `-0`, the function returns negative infinity', function test( t ) {
7373
var v = gamma( -0.0 );
74-
t.equal( v, NINF, 'returns -infinity' );
74+
t.equal( v, NINF, 'returns expected value' );
7575
t.end();
7676
});
7777

7878
tape( 'if provided `+0`, the function returns positive infinity', function test( t ) {
7979
var v = gamma( 0.0 );
80-
t.equal( v, PINF, 'returns +infinity' );
80+
t.equal( v, PINF, 'returns expected value' );
8181
t.end();
8282
});
8383

@@ -88,7 +88,7 @@ tape( 'if `x >= 171.63...`, the function returns positive infinity', function te
8888

8989
for ( i = 0; i < values.length; i++ ) {
9090
v = gamma( values[ i ] );
91-
t.equal( v, PINF, 'returns +infinity when provided ' + values[ i ] );
91+
t.equal( v, PINF, 'returns expected value when provided ' + values[ i ] );
9292
}
9393
t.end();
9494
});
@@ -100,7 +100,7 @@ tape( 'if `x <= -170.65`, the function returns zero', function test( t ) {
100100

101101
for ( i = 0; i < values.length; i++ ) {
102102
v = gamma( values[ i ] );
103-
t.equal( v, 0, 'returns 0 when provided ' + values[ i ] );
103+
t.equal( v, 0, 'returns expected value when provided ' + values[ i ] );
104104
}
105105
t.end();
106106
});

lib/node_modules/@stdlib/math/base/special/gamma/test/test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,32 @@ tape( 'if provided a negative integer, the function returns `NaN`', function tes
5353

5454
for ( i = 0; i < values.length; i++ ) {
5555
v = gamma( values[ i ] );
56-
t.equal( isnan( v ), true, 'returns NaN when provided ' + values[ i ] );
56+
t.equal( isnan( v ), true, 'returns expected value when provided ' + values[ i ] );
5757
}
5858
t.end();
5959
});
6060

6161
tape( 'if provided negative infinity, the function returns `NaN`', function test( t ) {
6262
var v = gamma( NINF );
63-
t.equal( isnan( v ), true, 'returns NaN when provided negative infinity' );
63+
t.equal( isnan( v ), true, 'returns expected value' );
6464
t.end();
6565
});
6666

6767
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
6868
var v = gamma( NaN );
69-
t.equal( isnan( v ), true, 'returns NaN when provided a NaN' );
69+
t.equal( isnan( v ), true, 'returns expected value' );
7070
t.end();
7171
});
7272

7373
tape( 'if provided `-0`, the function returns negative infinity', function test( t ) {
7474
var v = gamma( -0.0 );
75-
t.equal( v, NINF, 'returns -infinity' );
75+
t.equal( v, NINF, 'returns expected value' );
7676
t.end();
7777
});
7878

7979
tape( 'if provided `+0`, the function returns positive infinity', function test( t ) {
8080
var v = gamma( 0.0 );
81-
t.equal( v, PINF, 'returns +infinity' );
81+
t.equal( v, PINF, 'returns expected value' );
8282
t.end();
8383
});
8484

@@ -89,7 +89,7 @@ tape( 'if `x > 171.6144...`, the function returns positive infinity', function t
8989

9090
for ( i = 0; i < values.length; i++ ) {
9191
v = gamma( values[ i ] );
92-
t.equal( v, PINF, 'returns +infinity when provided ' + values[ i ] );
92+
t.equal( v, PINF, 'returns expected value when provided ' + values[ i ] );
9393
}
9494
t.end();
9595
});
@@ -101,7 +101,7 @@ tape( 'if `x < -170.56749...`, the function returns zero', function test( t ) {
101101

102102
for ( i = 0; i < values.length; i++ ) {
103103
v = gamma( values[ i ] );
104-
t.equal( v, 0.0, 'returns 0 when provided ' + values[ i ] );
104+
t.equal( v, 0.0, 'returns expected value when provided ' + values[ i ] );
105105
}
106106
t.end();
107107
});

lib/node_modules/@stdlib/math/base/special/gamma/test/test.native.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,32 @@ tape( 'if provided a negative integer, the function returns `NaN`', opts, functi
6262

6363
for ( i = 0; i < values.length; i++ ) {
6464
v = gamma( values[ i ] );
65-
t.equal( isnan( v ), true, 'returns NaN when provided ' + values[ i ] );
65+
t.equal( isnan( v ), true, 'returns expected value when provided ' + values[ i ] );
6666
}
6767
t.end();
6868
});
6969

7070
tape( 'if provided negative infinity, the function returns `NaN`', opts, function test( t ) {
7171
var v = gamma( NINF );
72-
t.equal( isnan( v ), true, 'returns expected value when provided negative infinity' );
72+
t.equal( isnan( v ), true, 'returns expected value' );
7373
t.end();
7474
});
7575

7676
tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
7777
var v = gamma( NaN );
78-
t.equal( isnan( v ), true, 'returns expected value when provided a NaN' );
78+
t.equal( isnan( v ), true, 'returns expected value' );
7979
t.end();
8080
});
8181

8282
tape( 'if provided `-0`, the function returns negative infinity', opts, function test( t ) {
8383
var v = gamma( -0.0 );
84-
t.equal( v, NINF, 'returns -infinity' );
84+
t.equal( v, NINF, 'returns expected value' );
8585
t.end();
8686
});
8787

8888
tape( 'if provided `+0`, the function returns positive infinity', opts, function test( t ) {
8989
var v = gamma( 0.0 );
90-
t.equal( v, PINF, 'returns +infinity' );
90+
t.equal( v, PINF, 'returns expected value' );
9191
t.end();
9292
});
9393

@@ -98,7 +98,7 @@ tape( 'if `x > 171.6144...`, the function returns positive infinity', opts, func
9898

9999
for ( i = 0; i < values.length; i++ ) {
100100
v = gamma( values[ i ] );
101-
t.equal( v, PINF, 'returns +infinity when provided ' + values[ i ] );
101+
t.equal( v, PINF, 'returns expected value when provided ' + values[ i ] );
102102
}
103103
t.end();
104104
});
@@ -110,7 +110,7 @@ tape( 'if `x < -170.56749...`, the function returns zero', opts, function test(
110110

111111
for ( i = 0; i < values.length; i++ ) {
112112
v = gamma( values[ i ] );
113-
t.equal( v, 0.0, 'returns 0 when provided ' + values[ i ] );
113+
t.equal( v, 0.0, 'returns expected value when provided ' + values[ i ] );
114114
}
115115
t.end();
116116
});

0 commit comments

Comments
 (0)