Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var acosh = require( './../lib' );
Expand All @@ -41,10 +41,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 1.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) + 1.0;
y = acosh( x );
y = acosh( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -62,10 +63,11 @@ bench( pkg+'::built-in', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 1.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) + 1.0;
y = Math.acosh( x ); // eslint-disable-line stdlib/no-builtin-math
y = Math.acosh( x[ i % x.length ] ); // eslint-disable-line stdlib/no-builtin-math
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/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 @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 1.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) + 1.0;
y = acosh( x );
y = acosh( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0*rand_double() ) + 1.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) + 1.0;
y = acosh( x );
y = acosh( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0*rand_double() ) + 1.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) + 1.0;
y = acosh( x );
y = acosh( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0*rand_double() ) + 1.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) + 1.0;
y = stdlib_base_acosh( x );
y = stdlib_base_acosh( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ double tic() {
* @return elapsed time in seconds
*/
double benchmark() {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;
Expand All @@ -97,10 +97,13 @@ double benchmark() {
// Define a uniform distribution for generating pseudorandom numbers as "doubles" between a minimum value (inclusive) and a maximum value (exclusive):
uniform_real_distribution<> randu( 1.0, 101.0 );

for ( i = 0; i < 100; i++ ) {
x[ i ] = randu( rng );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = randu( rng );
y = boost::math::acosh( x );
y = boost::math::acosh( x[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
29 changes: 2 additions & 27 deletions lib/node_modules/@stdlib/math/base/special/acosh/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var randu = require( '@stdlib/random/base/randu' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var acosh = require( './../lib' );


Expand All @@ -46,8 +45,6 @@ tape( 'main export is a function', function test( t ) {

tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -59,19 +56,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]'
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandkaranubc These changes should be reverted or you need to remove the if branch. Right now, if we were to update the test fixtures and the upstream values were to change, we would not catch that, as you now only assert when the values are equal. In this case, the approximate branch was included as a fallback in case values were to ever differ.

Copy link
Contributor Author

@anandkaranubc anandkaranubc Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will revert those. Is this different from what's being done in stats/base/dists/*. It was pointed out to me by @Neerajpathak07 in one of my PRs. Discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandkaranubc That comment applies to naive calculations. See the C implementation: https://github.com/stdlib-js/stdlib/pull/3974/files#diff-88bd0b2a5a78d2d32485c3217f1784e428ebf5cae61ec45eb5a1b872f400e0d7. In that implementation, there is no computation. Here, for acosh, we would, however, expect some approximate results due to floating-point rounding error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh, I see! Sorry, I overlooked that. Thanks for the clarification.

delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function computes the hyperbolic arccosine on the interval [3.0,28.0]', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -83,19 +74,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [3.0,28.0]
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function computes the hyperbolic arccosine on the interval [28.0,100.0]', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -107,19 +92,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [28.0,100.
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function computes the hyperbolic arccosine for huge values', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -131,18 +110,14 @@ tape( 'the function computes the hyperbolic arccosine for huge values', function
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = acosh( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -152,7 +127,7 @@ tape( 'the function returns `NaN` if provided value less than `1`', function tes

for ( i = 0; i < 1e3; i++ ) {
v = -(randu()*1.0e6) + (1-EPS);
t.equal( isnan( acosh( v ) ), true, 'returns NaN when provided '+v );
t.equal( isnan( acosh( v ) ), true, 'returns expected value when provided '+v );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var randu = require( '@stdlib/random/base/randu' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -55,8 +54,6 @@ tape( 'main export is a function', opts, function test( t ) {

tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]', opts, function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -68,19 +65,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]'
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function computes the hyperbolic arccosine on the interval [3.0,28.0]', opts, function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -92,19 +83,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [3.0,28.0]
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function computes the hyperbolic arccosine on the interval [28.0,100.0]', opts, function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -116,19 +101,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [28.0,100.
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function computes the hyperbolic arccosine for huge values', opts, function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -140,18 +119,14 @@ tape( 'the function computes the hyperbolic arccosine for huge values', opts, fu
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
var v = acosh( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -161,7 +136,7 @@ tape( 'the function returns `NaN` if provided value less than `1`', opts, functi

for ( i = 0; i < 1e3; i++ ) {
v = -(randu()*1.0e6) + (1-EPS);
t.equal( isnan( acosh( v ) ), true, 'returns NaN when provided '+v );
t.equal( isnan( acosh( v ) ), true, 'returns expected value when provided '+v );
}
t.end();
});