diff --git a/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.js index 097409350e15..8722e16d39e6 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.js @@ -23,8 +23,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var scopy = require( '@stdlib/blas/base/scopy' ).ndarray; -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var srot = require( './../lib/ndarray.js' ); @@ -37,22 +36,14 @@ var srot = require( './../lib/ndarray.js' ); * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -74,6 +65,7 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -83,6 +75,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -108,8 +102,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 1, ox[ i ], y, 1, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 6.0 ); - isApprox( t, y, ye[ i ], 6.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -119,6 +113,7 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -128,6 +123,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -153,8 +150,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 2, ox[ i ], y, -2, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -164,6 +161,7 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -173,6 +171,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -197,8 +197,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -2, ox[ i ], y, 1, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -208,6 +208,7 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -217,6 +218,8 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -242,19 +245,22 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -1, ox[ i ], y, -2, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 4.0 ); - isApprox( t, y, ye[ i ], 4.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); }); tape( 'the function supports an `x` stride', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, // 0 2.0, @@ -275,18 +281,21 @@ tape( 'the function supports an `x` stride', function test( t ) { xe = new Float32Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float32Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - isApprox( t, x, xe, 2.0 ); - isApprox( t, y, ye, 2.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports an `x` offset', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, 2.0, // 0 @@ -307,18 +316,21 @@ tape( 'the function supports an `x` offset', function test( t ) { xe = new Float32Array( [ 1.0, 5.2, 6.6, 4.0, 5.0 ] ); ye = new Float32Array( [ 3.6, 3.8, 8.0, 9.0, 10.0 ] ); - isApprox( t, x, xe, 2.0 ); - isApprox( t, y, ye, 2.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports a `y` stride', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 0; + x = new Float32Array([ 1.0, // 0 2.0, // 1 @@ -339,18 +351,21 @@ tape( 'the function supports a `y` stride', function test( t ) { xe = new Float32Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); ye = new Float32Array( [ 1.0, 2.0, 2.0, 4.0, 3.0 ] ); - isApprox( t, x, xe, 1.0 ); - isApprox( t, y, ye, 1.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports a `y` offset', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, // 0 2.0, // 1 @@ -371,8 +386,8 @@ tape( 'the function supports a `y` offset', function test( t ) { xe = new Float32Array( [ 5.6, 7.0, 3.0, 4.0, 5.0 ] ); ye = new Float32Array( [ 6.0, 7.0, 5.8, 6.0, 10.0 ] ); - isApprox( t, x, xe, 1.0 ); - isApprox( t, y, ye, 1.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); @@ -418,11 +433,14 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 6; + x = new Float32Array([ 0.6, // 3 0.1, @@ -447,18 +465,21 @@ tape( 'the function supports negative strides', function test( t ) { xe = new Float32Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float32Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 5.0 ); - isApprox( t, y, ye, 5.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports complex access patterns', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 2; + x = new Float32Array([ 0.6, // 1 0.1, // 0 @@ -483,8 +504,8 @@ tape( 'the function supports complex access patterns', function test( t ) { xe = new Float32Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float32Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 5.0 ); - isApprox( t, y, ye, 5.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.native.js index 16b2ac8a3004..d2f7d99754df 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.native.js @@ -24,8 +24,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var scopy = require( '@stdlib/blas/base/scopy' ).ndarray; -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -46,22 +45,14 @@ var opts = { * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -83,6 +74,7 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -92,6 +84,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -117,8 +111,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 1, ox[ i ], y, 1, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 6.0 ); - isApprox( t, y, ye[ i ], 6.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -128,6 +122,7 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -137,6 +132,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -162,8 +159,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 2, ox[ i ], y, -2, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -173,6 +170,7 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -182,6 +180,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -206,8 +206,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -2, ox[ i ], y, 1, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -217,6 +217,7 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function tes var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var ox; @@ -226,6 +227,8 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function tes var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -251,19 +254,22 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function tes x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -1, ox[ i ], y, -2, oy[ i ], 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 4.0 ); - isApprox( t, y, ye[ i ], 4.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); }); tape( 'the function supports an `x` stride', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, // 0 2.0, @@ -284,18 +290,21 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { xe = new Float32Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float32Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - isApprox( t, x, xe, 2.0 ); - isApprox( t, y, ye, 2.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports an `x` offset', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, 2.0, // 0 @@ -316,18 +325,21 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { xe = new Float32Array( [ 1.0, 5.2, 6.6, 4.0, 5.0 ] ); ye = new Float32Array( [ 3.6, 3.8, 8.0, 9.0, 10.0 ] ); - isApprox( t, x, xe, 2.0 ); - isApprox( t, y, ye, 2.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports a `y` stride', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 0; + x = new Float32Array([ 1.0, // 0 2.0, // 1 @@ -348,18 +360,21 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { xe = new Float32Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); ye = new Float32Array( [ 1.0, 2.0, 2.0, 4.0, 3.0 ] ); - isApprox( t, x, xe, 1.0 ); - isApprox( t, y, ye, 1.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports a `y` offset', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, // 0 2.0, // 1 @@ -380,8 +395,8 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { xe = new Float32Array( [ 5.6, 7.0, 3.0, 4.0, 5.0 ] ); ye = new Float32Array( [ 6.0, 7.0, 5.8, 6.0, 10.0 ] ); - isApprox( t, x, xe, 1.0 ); - isApprox( t, y, ye, 1.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); @@ -427,11 +442,14 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 6; + x = new Float32Array([ 0.6, // 3 0.1, @@ -456,18 +474,21 @@ tape( 'the function supports negative strides', opts, function test( t ) { xe = new Float32Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float32Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 5.0 ); - isApprox( t, y, ye, 5.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports complex access patterns', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 2; + x = new Float32Array([ 0.6, // 1 0.1, // 0 @@ -492,8 +513,8 @@ tape( 'the function supports complex access patterns', opts, function test( t ) xe = new Float32Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float32Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 5.0 ); - isApprox( t, y, ye, 5.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.js b/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.js index f415f73d03dc..fbd621979cf8 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.js +++ b/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.js @@ -23,8 +23,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var scopy = require( '@stdlib/blas/base/scopy' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var srot = require( './../lib/srot.js' ); @@ -37,22 +36,14 @@ var srot = require( './../lib/srot.js' ); * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -74,6 +65,7 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -81,6 +73,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -102,8 +96,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 1, y, 1, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 6.0 ); - isApprox( t, y, ye[ i ], 6.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -113,6 +107,7 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -120,6 +115,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -141,8 +138,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 2, y, -2, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -152,6 +149,7 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -159,6 +157,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -180,8 +180,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -2, y, 1, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -191,6 +191,7 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -198,6 +199,8 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -219,19 +222,22 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -1, y, -2, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); }); tape( 'the function supports an `x` stride', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, // 0 2.0, @@ -252,8 +258,8 @@ tape( 'the function supports an `x` stride', function test( t ) { xe = new Float32Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float32Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - isApprox( t, x, xe, 2.0 ); - isApprox( t, y, ye, 2.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); @@ -329,11 +335,14 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 6; + x = new Float32Array([ 0.6, // 3 0.1, @@ -358,18 +367,21 @@ tape( 'the function supports negative strides', function test( t ) { xe = new Float32Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float32Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 5.0 ); - isApprox( t, y, ye, 5.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports complex access patterns', function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 2; + x = new Float32Array([ 0.6, // 1 0.1, // 0 @@ -394,8 +406,8 @@ tape( 'the function supports complex access patterns', function test( t ) { xe = new Float32Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float32Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 10.0 ); - isApprox( t, y, ye, 10.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.native.js b/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.native.js index 728bd094571e..73befb98ae61 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.native.js +++ b/lib/node_modules/@stdlib/blas/base/srot/test/test.srot.native.js @@ -24,8 +24,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); var scopy = require( '@stdlib/blas/base/scopy' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -46,22 +45,14 @@ var opts = { * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -83,6 +74,7 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -90,6 +82,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -111,8 +105,8 @@ tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 1, y, 1, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 6.0 ); - isApprox( t, y, ye[ i ], 6.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -122,6 +116,7 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -129,6 +124,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -150,8 +147,8 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, 2, y, -2, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -161,6 +158,7 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -168,6 +166,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test var y; var i; + ULP = 6; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -189,8 +189,8 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -2, y, 1, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); @@ -200,6 +200,7 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function tes var xbuf; var ybuf; var out; + var ULP; var xe; var ye; var N; @@ -207,6 +208,8 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function tes var y; var i; + ULP = 2; + N = [ 0, 1, 2, 4 ]; xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; @@ -228,19 +231,22 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function tes x = new Float32Array( xbuf ); y = new Float32Array( ybuf ); out = srot( N[ i ], x, -1, y, -2, 0.8, 0.6 ); - isApprox( t, x, xe[ i ], 5.0 ); - isApprox( t, y, ye[ i ], 5.0 ); + isApprox( t, x, xe[ i ], ULP ); + isApprox( t, y, ye[ i ], ULP ); t.strictEqual( out, y, 'returns expected value' ); } t.end(); }); tape( 'the function supports an `x` stride', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 1; + x = new Float32Array([ 1.0, // 0 2.0, @@ -261,8 +267,8 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { xe = new Float32Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float32Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - isApprox( t, x, xe, 2.0 ); - isApprox( t, y, ye, 2.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); @@ -338,11 +344,14 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 6; + x = new Float32Array([ 0.6, // 3 0.1, @@ -367,18 +376,21 @@ tape( 'the function supports negative strides', opts, function test( t ) { xe = new Float32Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float32Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 5.0 ); - isApprox( t, y, ye, 5.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); }); tape( 'the function supports complex access patterns', opts, function test( t ) { + var ULP; var xe; var ye; var x; var y; + ULP = 2; + x = new Float32Array([ 0.6, // 1 0.1, // 0 @@ -403,8 +415,8 @@ tape( 'the function supports complex access patterns', opts, function test( t ) xe = new Float32Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float32Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - isApprox( t, x, xe, 10.0 ); - isApprox( t, y, ye, 10.0 ); + isApprox( t, x, xe, ULP ); + isApprox( t, y, ye, ULP ); t.end(); });