Skip to content
Merged
Changes from all commits
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
67 changes: 9 additions & 58 deletions lib/node_modules/@stdlib/math/base/special/polygamma/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
// MODULES //

var tape = require( 'tape' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var factorial = require( '@stdlib/math/base/special/factorial' );
var incrspace = require( '@stdlib/array/base/incrspace' );
var isnan = require( '@stdlib/assert/is-nan' );
var ldexp = require( '@stdlib/math/base/special/ldexp' );
var zeta = require( '@stdlib/math/base/special/riemann-zeta' );
var abs = require( '@stdlib/math/base/special/abs' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var polygamma = require( './../lib' );


Expand Down Expand Up @@ -82,8 +81,6 @@ tape( 'if provided an odd negative integer for `x`, the function returns positiv

tape( 'the function evaluates the polygamma function for small positive numbers', function test( t ) {
var expected;
var delta;
var tol;
var n;
var x;
var y;
Expand All @@ -94,21 +91,13 @@ tape( 'the function evaluates the polygamma function for small positive numbers'
expected = smallPositive.y;
for ( i = 0; i < x.length; i++ ) {
y = polygamma(n[i], x[i] );
if ( y === expected[ i ] ) {
t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 20.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the polygamma function for positive numbers', function test( t ) {
var expected;
var delta;
var tol;
var n;
var x;
var y;
Expand All @@ -119,21 +108,13 @@ tape( 'the function evaluates the polygamma function for positive numbers', func
expected = positive.y;
for ( i = 0; i < x.length; i++ ) {
y = polygamma(n[i], x[i] );
if ( y === expected[ i ] ) {
t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 20.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 15 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the polygamma function for negative numbers', function test( t ) {
var expected;
var delta;
var tol;
var n;
var x;
var y;
Expand All @@ -144,21 +125,13 @@ tape( 'the function evaluates the polygamma function for negative numbers', func
expected = negative.y;
for ( i = 0; i < x.length; i++ ) {
y = polygamma( n[i], x[i] );
if ( y === expected[ i ] ) {
t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 2300.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2858 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the polygamma function for large positive numbers', function test( t ) {
var expected;
var delta;
var tol;
var n;
var x;
var y;
Expand All @@ -169,21 +142,13 @@ tape( 'the function evaluates the polygamma function for large positive numbers'
expected = largePositive.y;
for ( i = 0; i < x.length; i++ ) {
y = polygamma(n[i], x[i] );
if ( y === expected[ i ] ) {
t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 20.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 18 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the polygamma function for large negative numbers', function test( t ) {
var expected;
var delta;
var tol;
var n;
var x;
var y;
Expand All @@ -194,23 +159,15 @@ tape( 'the function evaluates the polygamma function for large negative numbers'
expected = largeNegative.y;
for ( i = 0; i < x.length; i++ ) {
y = polygamma( n[i], x[i] );
if ( y === expected[ i ] ) {
t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );

// The large discrepancies for a few input values seem to be mostly due to a slight difference in the calculation of `cospi`, which is used in `polycotpi.js`. For example, for `x = 128.69279279279279`, our `cospi` function returns `-0.5693183042040957`, whereas Boost returns `-0.56931830420405894`. These differences are then magnified as the result is used as the value at which polynomials are evaluated.
tol = 2200.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}

// The large discrepancies for a few input values seem to be mostly due to a slight difference in the calculation of `cospi`, which is used in `polycotpi.js`. For example, for `x = 128.69279279279279`, our `cospi` function returns `-0.5693183042040957`, whereas Boost returns `-0.56931830420405894`. These differences are then magnified as the result is used as the value at which polynomials are evaluated.
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2773 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the polygamma function for huge positive numbers', function test( t ) {
var expected;
var delta;
var tol;
var n;
var x;
var y;
Expand All @@ -221,13 +178,7 @@ tape( 'the function evaluates the polygamma function for huge positive numbers',
expected = hugePositive.y;
for ( i = 0; i < x.length; i++ ) {
y = polygamma(n[i], x[i] );
if ( y === expected[ i ] ) {
t.strictEqual( y, expected[ i ], 'n: '+n[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. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});
Expand Down