Skip to content

Commit

Permalink
Refactor random number generation in JS benchmarks
Browse files Browse the repository at this point in the history
---
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
---
  • Loading branch information
yuvi-mittal committed Feb 3, 2025
1 parent f3b40b4 commit af915d9
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 105 deletions.
24 changes: 12 additions & 12 deletions lib/node_modules/@stdlib/stats/base/dists/planck/mean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ for ( i = 0; i < 10; i++ ) {

#### stdlib_base_dists_planck_mean( lambda )

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

```c
double out = stdlib_base_dists_planck_mean( 0.1 );
Expand Down Expand Up @@ -187,20 +187,20 @@ double stdlib_base_dists_planck_mean( const double lambda );
#include <stdio.h>
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v * (max - min) );
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v * (max - min) );
}
int main( void ) {
double lambda;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
lambda = random_uniform( 0.1, 10.0 );
y = stdlib_base_dists_planck_mean( lambda );
printf( "lambda: %lf, E(X;λ): %lf\n", lambda, y );
}
double lambda;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
lambda = random_uniform( 0.1, 10.0 );
y = stdlib_base_dists_planck_mean( lambda );
printf( "lambda: %lf, E(X;λ): %lf\n", lambda, y );
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var mean = require( './../lib' );
Expand All @@ -31,16 +31,15 @@ var mean = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var lambda;
var len;
var y;
var i;

len =100;
lambda = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
lambda[ i ] = ( randu() * 10.0 ) + 1.0;

lambda[ i ] = uniform( 1, 10.0 );
}

b.tic();
Expand All @@ -57,4 +56,3 @@ bench( pkg, function benchmark( b ) {
b.pass( 'benchmark finished' );
b.end();
});

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -36,19 +36,19 @@ var opts = {
'skip': ( mean instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var lambda;
var len;
var y;
var i;

len =100;
lambda = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
lambda[ i ] = ( randu() * 10.0 ) + 1.0;

lambda[ i ] = uniform( 1.0, 10.0 );
}

b.tic();
Expand All @@ -65,4 +65,3 @@ bench( pkg+'::native', opts, function benchmark( b ) {
b.pass( 'benchmark finished' );
b.end();
});

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* limitations under the License.
*/

// #include "stdlib/math/base/assert/is_nan.h"
// #include "stdlib/math/base/special/expm1.h"
#include "stdlib/stats/base/dists/planck/mean.h"
#include <stdlib.h>
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
#endif

/**
* Evaluates the mean of the Planck distribution with given lambda .
*Returns the expected value of a Planck distribution with shape parameter `lambda`.
*
* @param T - The temperature parameter of the Planck distribution (must be > 0)
* @return The mean of the Planck distribution for the given temperature
Expand Down
158 changes: 78 additions & 80 deletions lib/node_modules/@stdlib/stats/base/dists/planck/mean/manifest.json
Original file line number Diff line number Diff line change
@@ -1,81 +1,79 @@
{
"options": {
"task": "build",
"wasm": false
},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"task": "build",
"wasm": false,
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/expm1"
]
},
{
"task": "benchmark",
"wasm": false,
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/expm1",
"@stdlib/constants/float64/pi"
]
},
{
"task": "examples",
"wasm": false,
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/asin",
"@stdlib/math/base/special/expm1"
]
}
]
}
"options": {
"task": "build",
"wasm": false
},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"task": "build",
"wasm": false,
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/expm1"
]
},
{
"task": "benchmark",
"wasm": false,
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/expm1"
]
},
{
"task": "examples",
"wasm": false,
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/expm1"
]
}
]
}

0 comments on commit af915d9

Please sign in to comment.