Skip to content

Commit b5cd4af

Browse files
committed
chore: apply suggestions and add benchmark.native.js
1 parent da14b77 commit b5cd4af

File tree

4 files changed

+97
-10
lines changed

4 files changed

+97
-10
lines changed

lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/benchmark/benchmark.js

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

2323
var bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2426
var randu = require( '@stdlib/random/base/randu' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pkg = require( './../package.json' ).name;
@@ -30,18 +32,26 @@ var cdf = require( './../lib' );
3032
// MAIN //
3133

3234
bench( pkg, function benchmark( b ) {
35+
var len;
3336
var min;
3437
var max;
3538
var x;
3639
var y;
3740
var i;
3841

42+
len = 100;
43+
x = new Float64Array( len );
44+
min = new Float64Array( len );
45+
max = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
x[ i ] = ( randu() * 20.0 ) - 10.0;
48+
min[ i ] = ( randu() * 20.0 ) - 20.0;
49+
max[ i ] = min[ i ] + ( randu() * 40.0 );
50+
}
51+
3952
b.tic();
4053
for ( i = 0; i < b.iterations; i++ ) {
41-
x = ( randu() * 20.0 ) - 10.0;
42-
min = ( randu() * 20.0 ) - 20.0;
43-
max = min + ( randu() * 40.0 );
44-
y = cdf( x, min, max );
54+
y = cdf( x[ i % len ], min[ i % len ], max[ i % len ] );
4555
if ( isnan( y ) ) {
4656
b.fail( 'should not return NaN' );
4757
}
@@ -65,11 +75,11 @@ bench( pkg+':factory', function benchmark( b ) {
6575
min = -1.5;
6676
max = 1.5;
6777
mycdf = cdf.factory( min, max );
78+
x = uniform( 100, -2.0, 2.0 );
6879

6980
b.tic();
7081
for ( i = 0; i < b.iterations; i++ ) {
71-
x = ( randu()*2.0 ) - 2.0;
72-
y = mycdf( x );
82+
y = mycdf( x[ i % x.length ] );
7383
if ( isnan( y ) ) {
7484
b.fail( 'should not return NaN' );
7585
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var Float64Array = require( '@stdlib/array/float64' );
26+
var randu = require( '@stdlib/random/base/randu' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var cdf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( cdf instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( pkg, opts, function benchmark( b ) {
43+
var len;
44+
var min;
45+
var max;
46+
var x;
47+
var y;
48+
var i;
49+
50+
len = 100;
51+
x = new Float64Array( len );
52+
min = new Float64Array( len );
53+
max = new Float64Array( len );
54+
for ( i = 0; i < len; i++ ) {
55+
x[ i ] = ( randu() * 20.0 ) - 10.0;
56+
min[ i ] = ( randu() * 20.0 ) - 20.0;
57+
max[ i ] = min[ i ] + ( randu() * 40.0 );
58+
}
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
y = cdf( x[ i % len ], min[ i % len ], max[ i % len ] );
63+
if ( isnan( y ) ) {
64+
b.fail( 'should not return NaN' );
65+
}
66+
}
67+
b.toc();
68+
if ( isnan( y ) ) {
69+
b.fail( 'should not return NaN' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
});

lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/examples/c/example.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222

23+
static double random_uniform( const double min, const double max ) {
24+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
25+
return min + ( v*(max-min) );
26+
}
27+
2328
int main( void ) {
2429
double x;
2530
double a;
@@ -28,9 +33,9 @@ int main( void ) {
2833
int i;
2934

3035
for ( i = 0; i < 25; i++ ) {
31-
x = ( (double)rand() / (double)RAND_MAX ) * 20.0 - 10.0;
32-
a = ( (double)rand() / (double)RAND_MAX ) * 20.0 - 20.0;
33-
b = a + ( (double)rand() / (double)RAND_MAX ) * 40.0;
36+
x = random_uniform( -10.0, 10.0 );
37+
a = random_uniform( -20.0, 0.0 );
38+
b = random_uniform( a, a+40.0 );
3439
y = stdlib_base_dists_arcsine_cdf( x, a, b );
3540
printf( "x: %lf, a: %lf, b: %lf, F(x;a,b): %lf\n", x, a, b, y );
3641
}

lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"example": "./examples",
2222
"include": "./include",
2323
"lib": "./lib",
24-
"scripts": "./scripts",
2524
"src": "./src",
2625
"test": "./test"
2726
},

0 commit comments

Comments
 (0)