Skip to content

Commit af915d9

Browse files
committed
Refactor random number generation in JS benchmarks
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent f3b40b4 commit af915d9

File tree

6 files changed

+98
-105
lines changed

6 files changed

+98
-105
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ for ( i = 0; i < 10; i++ ) {
148148

149149
#### stdlib_base_dists_planck_mean( lambda )
150150

151-
Evaluates the mean for an planck distribution.
151+
Returns the expected value of a Planck distribution with shape parameter `lambda`.
152152

153153
```c
154154
double out = stdlib_base_dists_planck_mean( 0.1 );
@@ -187,20 +187,20 @@ double stdlib_base_dists_planck_mean( const double lambda );
187187
#include <stdio.h>
188188
189189
static double random_uniform( const double min, const double max ) {
190-
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
191-
return min + ( v * (max - min) );
190+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
191+
return min + ( v * (max - min) );
192192
}
193193
194194
int main( void ) {
195-
double lambda;
196-
double y;
197-
int i;
198-
199-
for ( i = 0; i < 25; i++ ) {
200-
lambda = random_uniform( 0.1, 10.0 );
201-
y = stdlib_base_dists_planck_mean( lambda );
202-
printf( "lambda: %lf, E(X;λ): %lf\n", lambda, y );
203-
}
195+
double lambda;
196+
double y;
197+
int i;
198+
199+
for ( i = 0; i < 25; i++ ) {
200+
lambda = random_uniform( 0.1, 10.0 );
201+
y = stdlib_base_dists_planck_mean( lambda );
202+
printf( "lambda: %lf, E(X;λ): %lf\n", lambda, y );
203+
}
204204
}
205205
```
206206

lib/node_modules/@stdlib/stats/base/dists/planck/mean/benchmark/benchmark.js

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

2323
var bench = require( '@stdlib/bench' );
2424
var Float64Array = require( '@stdlib/array/float64' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pkg = require( './../package.json' ).name;
2828
var mean = require( './../lib' );
@@ -31,16 +31,15 @@ var mean = require( './../lib' );
3131
// MAIN //
3232

3333
bench( pkg, function benchmark( b ) {
34-
var len;
3534
var lambda;
35+
var len;
3636
var y;
3737
var i;
3838

3939
len =100;
4040
lambda = new Float64Array( len );
4141
for ( i = 0; i < len; i++ ) {
42-
lambda[ i ] = ( randu() * 10.0 ) + 1.0;
43-
42+
lambda[ i ] = uniform( 1, 10.0 );
4443
}
4544

4645
b.tic();
@@ -57,4 +56,3 @@ bench( pkg, function benchmark( b ) {
5756
b.pass( 'benchmark finished' );
5857
b.end();
5958
});
60-

lib/node_modules/@stdlib/stats/base/dists/planck/mean/benchmark/benchmark.native.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var Float64Array = require( '@stdlib/array/float64' );
26-
var randu = require( '@stdlib/random/base/randu' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var pkg = require( './../package.json' ).name;
@@ -36,19 +36,19 @@ var opts = {
3636
'skip': ( mean instanceof Error )
3737
};
3838

39+
3940
// MAIN //
4041

4142
bench( pkg+'::native', opts, function benchmark( b ) {
42-
var len;
4343
var lambda;
44+
var len;
4445
var y;
4546
var i;
4647

4748
len =100;
4849
lambda = new Float64Array( len );
4950
for ( i = 0; i < len; i++ ) {
50-
lambda[ i ] = ( randu() * 10.0 ) + 1.0;
51-
51+
lambda[ i ] = uniform( 1.0, 10.0 );
5252
}
5353

5454
b.tic();
@@ -65,4 +65,3 @@ bench( pkg+'::native', opts, function benchmark( b ) {
6565
b.pass( 'benchmark finished' );
6666
b.end();
6767
});
68-

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

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

19-
// #include "stdlib/math/base/assert/is_nan.h"
20-
// #include "stdlib/math/base/special/expm1.h"
2119
#include "stdlib/stats/base/dists/planck/mean.h"
2220
#include <stdlib.h>
2321
#include <stdio.h>

lib/node_modules/@stdlib/stats/base/dists/planck/mean/include/stdlib/stats/base/dists/planck/mean.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 mean of the Planck distribution with given lambda .
30+
*Returns the expected value of a Planck distribution with shape parameter `lambda`.
3131
*
3232
* @param T - The temperature parameter of the Planck distribution (must be > 0)
3333
* @return The mean of the Planck distribution for the given temperature
Lines changed: 78 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,79 @@
11
{
2-
"options": {
3-
"task": "build",
4-
"wasm": false
5-
},
6-
"fields": [
7-
{
8-
"field": "src",
9-
"resolve": true,
10-
"relative": true
11-
},
12-
{
13-
"field": "include",
14-
"resolve": true,
15-
"relative": true
16-
},
17-
{
18-
"field": "libraries",
19-
"resolve": false,
20-
"relative": false
21-
},
22-
{
23-
"field": "libpath",
24-
"resolve": true,
25-
"relative": false
26-
}
27-
],
28-
"confs": [
29-
{
30-
"task": "build",
31-
"wasm": false,
32-
"src": [
33-
"./src/main.c"
34-
],
35-
"include": [
36-
"./include"
37-
],
38-
"libraries": [],
39-
"libpath": [],
40-
"dependencies": [
41-
"@stdlib/math/base/napi/unary",
42-
"@stdlib/math/base/assert/is-nan",
43-
"@stdlib/math/base/special/expm1"
44-
]
45-
},
46-
{
47-
"task": "benchmark",
48-
"wasm": false,
49-
"src": [
50-
"./src/main.c"
51-
],
52-
"include": [
53-
"./include"
54-
],
55-
"libraries": [],
56-
"libpath": [],
57-
"dependencies": [
58-
"@stdlib/math/base/assert/is-nan",
59-
"@stdlib/math/base/special/expm1",
60-
"@stdlib/constants/float64/pi"
61-
]
62-
},
63-
{
64-
"task": "examples",
65-
"wasm": false,
66-
"src": [
67-
"./src/main.c"
68-
],
69-
"include": [
70-
"./include"
71-
],
72-
"libraries": [],
73-
"libpath": [],
74-
"dependencies": [
75-
"@stdlib/math/base/assert/is-nan",
76-
"@stdlib/math/base/special/asin",
77-
"@stdlib/math/base/special/expm1"
78-
]
79-
}
80-
]
81-
}
2+
"options": {
3+
"task": "build",
4+
"wasm": false
5+
},
6+
"fields": [
7+
{
8+
"field": "src",
9+
"resolve": true,
10+
"relative": true
11+
},
12+
{
13+
"field": "include",
14+
"resolve": true,
15+
"relative": true
16+
},
17+
{
18+
"field": "libraries",
19+
"resolve": false,
20+
"relative": false
21+
},
22+
{
23+
"field": "libpath",
24+
"resolve": true,
25+
"relative": false
26+
}
27+
],
28+
"confs": [
29+
{
30+
"task": "build",
31+
"wasm": false,
32+
"src": [
33+
"./src/main.c"
34+
],
35+
"include": [
36+
"./include"
37+
],
38+
"libraries": [],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/math/base/napi/unary",
42+
"@stdlib/math/base/assert/is-nan",
43+
"@stdlib/math/base/special/expm1"
44+
]
45+
},
46+
{
47+
"task": "benchmark",
48+
"wasm": false,
49+
"src": [
50+
"./src/main.c"
51+
],
52+
"include": [
53+
"./include"
54+
],
55+
"libraries": [],
56+
"libpath": [],
57+
"dependencies": [
58+
"@stdlib/math/base/assert/is-nan",
59+
"@stdlib/math/base/special/expm1"
60+
]
61+
},
62+
{
63+
"task": "examples",
64+
"wasm": false,
65+
"src": [
66+
"./src/main.c"
67+
],
68+
"include": [
69+
"./include"
70+
],
71+
"libraries": [],
72+
"libpath": [],
73+
"dependencies": [
74+
"@stdlib/math/base/assert/is-nan",
75+
"@stdlib/math/base/special/expm1"
76+
]
77+
}
78+
]
79+
}

0 commit comments

Comments
 (0)