Skip to content

Commit 9ba3f82

Browse files
authored
chore: update random value generation and test messages
PR-URL: #6343 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 90d0d11 commit 9ba3f82

File tree

13 files changed

+112
-84
lines changed

13 files changed

+112
-84
lines changed

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

Lines changed: 29 additions & 22 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/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var EPS = require( '@stdlib/constants/float64/eps' );
2727
var pkg = require( './../package.json' ).name;
@@ -36,11 +36,12 @@ bench( pkg, function benchmark( b ) {
3636
var z;
3737
var i;
3838

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

63+
x = uniform( 100, 0.0, 1000.0 );
64+
y = uniform( 100, EPS, 1000.0 );
65+
6266
b.tic();
6367
for ( i = 0; i < b.iterations; i++ ) {
64-
x = ( randu()*1000.0 ) - 0.0;
65-
y = ( randu()*1000.0 ) + EPS;
66-
z = gammainc( x, y, true );
68+
z = gammainc( x[ i%x.length ], y[ i%y.length ], true );
6769
if ( isnan( z ) ) {
6870
b.fail( 'should not return NaN' );
6971
}
@@ -82,11 +84,12 @@ bench( pkg+':regularized=false', function benchmark( b ) {
8284
var z;
8385
var i;
8486

87+
x = uniform( 100, 0.0, 1000.0 );
88+
y = uniform( 100, EPS, 1000.0 );
89+
8590
b.tic();
8691
for ( i = 0; i < b.iterations; i++ ) {
87-
x = ( randu()*1000.0 ) - 0.0;
88-
y = ( randu()*1000.0 ) + EPS;
89-
z = gammainc( x, y, false );
92+
z = gammainc( x[ i%x.length ], y[ i%y.length ], false );
9093
if ( isnan( z ) ) {
9194
b.fail( 'should not return NaN' );
9295
}
@@ -105,11 +108,12 @@ bench( pkg+':regularized=true,upper=true', function benchmark( b ) {
105108
var z;
106109
var i;
107110

111+
x = uniform( 100, 0.0, 1000.0 );
112+
y = uniform( 100, EPS, 1000.0 );
113+
108114
b.tic();
109115
for ( i = 0; i < b.iterations; i++ ) {
110-
x = ( randu()*1000.0 ) - 0.0;
111-
y = ( randu()*1000.0 ) + EPS;
112-
z = gammainc( x, y, true, true );
116+
z = gammainc( x[ i%x.length ], y[ i%y.length ], true, true );
113117
if ( isnan( z ) ) {
114118
b.fail( 'should not return NaN' );
115119
}
@@ -128,11 +132,12 @@ bench( pkg+':regularized=true,upper=false', function benchmark( b ) {
128132
var z;
129133
var i;
130134

135+
x = uniform( 100, 0.0, 1000.0 );
136+
y = uniform( 100, EPS, 1000.0 );
137+
131138
b.tic();
132139
for ( i = 0; i < b.iterations; i++ ) {
133-
x = ( randu()*1000.0 ) - 0.0;
134-
y = ( randu()*1000.0 ) + EPS;
135-
z = gammainc( x, y, true, false );
140+
z = gammainc( x[ i%x.length ], y[ i%y.length ], true, false );
136141
if ( isnan( z ) ) {
137142
b.fail( 'should not return NaN' );
138143
}
@@ -151,11 +156,12 @@ bench( pkg+':regularized=false,upper=true', function benchmark( b ) {
151156
var z;
152157
var i;
153158

159+
x = uniform( 100, 0.0, 1000.0 );
160+
y = uniform( 100, EPS, 1000.0 );
161+
154162
b.tic();
155163
for ( i = 0; i < b.iterations; i++ ) {
156-
x = ( randu()*1000.0 ) - 0.0;
157-
y = ( randu()*1000.0 ) + EPS;
158-
z = gammainc( x, y, false, true );
164+
z = gammainc( x[ i%x.length ], y[ i%y.length ], false, true );
159165
if ( isnan( z ) ) {
160166
b.fail( 'should not return NaN' );
161167
}
@@ -174,11 +180,12 @@ bench( pkg+':regularized=false,upper=false', function benchmark( b ) {
174180
var z;
175181
var i;
176182

183+
x = uniform( 100, 0.0, 1000.0 );
184+
y = uniform( 100, EPS, 1000.0 );
185+
177186
b.tic();
178187
for ( i = 0; i < b.iterations; i++ ) {
179-
x = ( randu()*1000.0 ) - 0.0;
180-
y = ( randu()*1000.0 ) + EPS;
181-
z = gammainc( x, y, false, false );
188+
z = gammainc( x[ i%x.length ], y[ i%y.length ], false, false );
182189
if ( isnan( z ) ) {
183190
b.fail( 'should not return NaN' );
184191
}

lib/node_modules/@stdlib/math/base/special/gammainc/benchmark/c/cephes/benchmark.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ static double rand_double( void ) {
9696
*/
9797
static double benchmark1( void ) {
9898
double elapsed;
99-
double x;
100-
double y;
99+
double x[ 100 ];
100+
double y[ 100 ];
101101
double z;
102102
double t;
103103
int i;
104104

105+
for ( i = 0; i < 100; i++ ) {
106+
x[ i ] = ( 100.0*rand_double() ) - 0.0;
107+
y[ i ] = ( 99.9*rand_double() ) + 0.1;
108+
}
109+
105110
t = tic();
106111
for ( i = 0; i < ITERATIONS; i++ ) {
107-
x = ( 100.0*rand_double() ) - 0.0;
108-
y = ( 99.9*rand_double() ) + 0.1;
109-
z = igam( x, y );
112+
z = igam( x[ i%100 ], y[ i%100 ] );
110113
if ( z != z ) {
111114
printf( "should not return NaN\n" );
112115
break;
@@ -126,17 +129,20 @@ static double benchmark1( void ) {
126129
*/
127130
static double benchmark2( void ) {
128131
double elapsed;
129-
double x;
130-
double y;
132+
double x[ 100 ];
133+
double y[ 100 ];
131134
double z;
132135
double t;
133136
int i;
134137

138+
for ( i = 0; i < 100; i++ ) {
139+
x[ i ] = ( 100.0*rand_double() ) - 0.0;
140+
y[ i ] = ( 99.9*rand_double() ) + 0.1;
141+
}
142+
135143
t = tic();
136144
for ( i = 0; i < ITERATIONS; i++ ) {
137-
x = ( 100.0*rand_double() ) - 0.0;
138-
y = ( 99.9*rand_double() ) + 0.1;
139-
z = igamc( x, y );
145+
z = igamc( x[ i%100 ], y[ i%100 ] );
140146
if ( z != z ) {
141147
printf( "should not return NaN\n" );
142148
break;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
5151
var val;
5252

5353
val = gammainc( NaN, 2 );
54-
t.strictEqual( isnan( val ), true, 'returns NaN' );
54+
t.strictEqual( isnan( val ), true, 'returns expected value' );
5555

5656
val = gammainc( 4, NaN );
57-
t.strictEqual( isnan( val ), true, 'returns NaN' );
57+
t.strictEqual( isnan( val ), true, 'returns expected value' );
5858

5959
t.end();
6060
});
@@ -64,15 +64,15 @@ tape( 'the function returns NaN if provided x < 0 or s <= 0', function test( t )
6464

6565
// Case: x < 0
6666
val = gammainc( -0.1, 2 );
67-
t.strictEqual( isnan( val ), true, 'returns NaN' );
67+
t.strictEqual( isnan( val ), true, 'returns expected value' );
6868

6969
// Case: s = 0
7070
val = gammainc( 0.1, 0 );
71-
t.strictEqual( isnan( val ), true, 'returns NaN' );
71+
t.strictEqual( isnan( val ), true, 'returns expected value' );
7272

7373
// Case: s < 0
7474
val = gammainc( 0.1, -2 );
75-
t.strictEqual( isnan( val ), true, 'returns NaN' );
75+
t.strictEqual( isnan( val ), true, 'returns expected value' );
7676

7777
t.end();
7878
});
@@ -82,7 +82,7 @@ tape( 'the function returns 0 for the lower incomplete gamma function when the f
8282
var s;
8383
for ( s = 1; s < 10; s++ ) {
8484
val = gammainc( 0, s );
85-
t.ok( val === 0, 'returns 0' );
85+
t.ok( val === 0, 'returns expected value' );
8686
}
8787
t.end();
8888
});

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

Lines changed: 5 additions & 4 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/base/randu' );
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 gammaincinv = require( './../lib' );
@@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
3535
var z;
3636
var i;
3737

38+
x = uniform( 100, 0.0, 1.0 );
39+
y = uniform( 100, 0.1, 1000.0 );
40+
3841
b.tic();
3942
for ( i = 0; i < b.iterations; i++ ) {
40-
x = randu();
41-
y = ( randu()*1000.0 ) + 0.1;
42-
z = gammaincinv( x, y );
43+
z = gammaincinv( x[ i%x.length ], y[ i%y.length ] );
4344
if ( isnan( z ) ) {
4445
b.fail( 'should not return NaN' );
4546
}

lib/node_modules/@stdlib/math/base/special/gammaincinv/benchmark/c/cephes/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,20 @@ static double rand_double( void ) {
9595
*/
9696
static double benchmark( void ) {
9797
double elapsed;
98-
double x;
99-
double y;
98+
double x[ 100 ];
99+
double y[ 100 ];
100100
double z;
101101
double t;
102102
int i;
103103

104+
for ( i = 0; i < 100; i++ ) {
105+
x[ i ] = ( 1000.0*rand_double() ) + 0.1;
106+
y[ i ] = ( 0.5*rand_double() );
107+
}
108+
104109
t = tic();
105110
for ( i = 0; i < ITERATIONS; i++ ) {
106-
x = ( 1000.0*rand_double() ) + 0.1;
107-
y = ( 0.5*rand_double() );
108-
z = igami( x, y );
111+
z = igami( x[ i%100 ], y[ i%100 ] );
109112
if ( z != z ) {
110113
printf( "should not return NaN\n" );
111114
break;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
9696
var val;
9797

9898
val = gammaincinv( NaN, 2 );
99-
t.strictEqual( isnan( val ), true, 'returns NaN' );
99+
t.strictEqual( isnan( val ), true, 'returns expected value' );
100100

101101
val = gammaincinv( 0.5, NaN );
102-
t.strictEqual( isnan( val ), true, 'returns NaN' );
102+
t.strictEqual( isnan( val ), true, 'returns expected value' );
103103

104104
t.end();
105105
});
@@ -108,10 +108,10 @@ tape( 'the function returns `NaN` if provided `p` outside the interval `[0,1]`',
108108
var val;
109109

110110
val = gammaincinv( 1.2, 2 );
111-
t.strictEqual( isnan( val ), true, 'returns NaN' );
111+
t.strictEqual( isnan( val ), true, 'returns expected value' );
112112

113113
val = gammaincinv( -0.1, 2 );
114-
t.strictEqual( isnan( val ), true, 'returns NaN' );
114+
t.strictEqual( isnan( val ), true, 'returns expected value' );
115115

116116
t.end();
117117
});
@@ -124,7 +124,7 @@ tape( 'the function returns `0` if provided `p = 1`', function test( t ) {
124124
a = incrspace( 0, 100, 10 );
125125
for ( i = 0; i < a.length; i++ ) {
126126
val = gammaincinv( 1, a[ i ] );
127-
t.notOk( val === 0, 'returns 0' );
127+
t.notOk( val === 0, 'returns expected value' );
128128
}
129129
t.end();
130130
});
@@ -137,7 +137,7 @@ tape( 'the function returns `+Infinity` if provided `p = 0`', function test( t )
137137
a = incrspace( 0, 100, 10 );
138138
for ( i = 0; i < a.length; i++ ) {
139139
val = gammaincinv( 0, a[ i ] );
140-
t.notOk( val === PINF, 'returns +Infinity' );
140+
t.notOk( val === PINF, 'returns expected value' );
141141
}
142142
t.end();
143143
});
@@ -150,7 +150,7 @@ tape( 'the function returns `0` if provided `p = 0` when `upper = true`', functi
150150
a = incrspace( 0, 100, 10 );
151151
for ( i = 0; i < a.length; i++ ) {
152152
val = gammaincinv( 0, a[ i ], true );
153-
t.notOk( val === 0, 'returns 0' );
153+
t.notOk( val === 0, 'returns expected value' );
154154
}
155155
t.end();
156156
});
@@ -163,7 +163,7 @@ tape( 'the function returns `+Infinity` if provided `p = 1` when `upper = true`'
163163
a = incrspace( 0, 100, 10 );
164164
for ( i = 0; i < a.length; i++ ) {
165165
val = gammaincinv( 1, a[ i ], true );
166-
t.notOk( val === PINF, 'returns +Infinity' );
166+
t.notOk( val === PINF, 'returns expected value' );
167167
}
168168
t.end();
169169
});

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

Lines changed: 4 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/base/randu' );
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 gammaln = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = uniform( 100, -500.0, 500.0 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*1000.0 ) - 500.0;
40-
y = gammaln( x );
41+
y = gammaln( x[ i%x.length ] );
4142
if ( isnan( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}

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

Lines changed: 4 additions & 3 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;
@@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = uniform( 100, -500.0, 500.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu() * 1000.0 ) - 500.0;
49-
y = gammaln( x );
50+
y = gammaln( x[ i%x.length ] );
5051
if ( isnan( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

lib/node_modules/@stdlib/math/base/special/gammaln/benchmark/c/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,18 @@ static double rand_double( void ) {
9090
*/
9191
static double benchmark( void ) {
9292
double elapsed;
93-
double x;
93+
double x[ 100 ];
9494
double y;
9595
double t;
9696
int i;
9797

98+
for ( i = 0; i < 100; i++ ) {
99+
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
100+
}
101+
98102
t = tic();
99103
for ( i = 0; i < ITERATIONS; i++ ) {
100-
x = ( 1000.0*rand_double() ) - 500.0;
101-
y = lgamma( x );
104+
y = lgamma( x[ i%100 ] );
102105
if ( y != y ) {
103106
printf( "should not return NaN\n" );
104107
break;

0 commit comments

Comments
 (0)