diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js index a34ee6a73e4f..390800a8396d 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js @@ -24,11 +24,31 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); -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 cscal = require( './../lib/cscal.js' ); +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference +*/ +function isApprox( t, actual, expected, ulp ) { + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); + } +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -44,12 +64,9 @@ tape( 'the function has an arity of 4', function test( t ) { tape( 'the function scales elements from `x` by `alpha`', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.3, // 1 @@ -76,26 +93,16 @@ tape( 'the function scales elements from `x` by `alpha`', function test( t ) { 0.14, // 4 0.08 // 4 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 1 @@ -130,26 +137,16 @@ tape( 'the function supports specifying a `x` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a negative `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 3 @@ -184,15 +181,8 @@ tape( 'the function supports specifying a negative `x` stride', function test( t 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); @@ -233,13 +223,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports view offsets', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var cx0; var cx1; - var k; // Initial arrays... cx0 = new Complex64Array([ @@ -274,14 +261,7 @@ tape( 'the function supports view offsets', function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 2 ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js index 8d8d12cf8fda..84019d3b6fff 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js @@ -25,8 +25,7 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); -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' ); @@ -38,6 +37,27 @@ var opts = { }; +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference +*/ +function isApprox( t, actual, expected, ulp ) { + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); + } +} + + // TESTS // tape( 'main export is a function', opts, function test( t ) { @@ -53,12 +73,9 @@ tape( 'the function has an arity of 4', opts, function test( t ) { tape( 'the function scales elements from `x` by `alpha`', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.3, // 1 @@ -85,26 +102,16 @@ tape( 'the function scales elements from `x` by `alpha`', opts, function test( t 0.14, // 4 0.08 // 4 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a `x` stride', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 1 @@ -139,26 +146,16 @@ tape( 'the function supports specifying a `x` stride', opts, function test( t ) 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a negative `x` stride', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 3 @@ -193,15 +190,8 @@ tape( 'the function supports specifying a negative `x` stride', opts, function t 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); @@ -242,13 +232,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports view offsets', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var cx0; var cx1; - var k; // Initial arrays... cx0 = new Complex64Array([ @@ -283,14 +270,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 2 ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js index 2efd7a94c0a2..7b8aff9f3c22 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js @@ -24,11 +24,31 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); -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 cscal = require( './../lib/ndarray.js' ); +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference +*/ +function isApprox( t, actual, expected, ulp ) { + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); + } +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -44,12 +64,9 @@ tape( 'the function has an arity of 5', function test( t ) { tape( 'the function scales elements from `x` by `alpha`', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.3, // 1 @@ -84,26 +101,16 @@ tape( 'the function scales elements from `x` by `alpha`', function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 1 @@ -138,26 +145,16 @@ tape( 'the function supports specifying a `x` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a negative `x` stride', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 3 @@ -192,26 +189,16 @@ tape( 'the function supports specifying a negative `x` stride', function test( t 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports a `x` offset', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, @@ -246,15 +233,8 @@ tape( 'the function supports a `x` offset', function test( t ) { 4.2, // 3 -4.1 // 3 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 5 ); + t.end(); }); @@ -295,12 +275,9 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports complex access patterns', function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, @@ -339,14 +316,7 @@ tape( 'the function supports complex access patterns', function test( t ) { 2.9, // 2 -0.2 // 2 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 5 ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js index 3499b30cf552..b03e727d7230 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js @@ -25,8 +25,7 @@ var tape = require( 'tape' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); -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' ); @@ -38,6 +37,27 @@ var opts = { }; +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference +*/ +function isApprox( t, actual, expected, ulp ) { + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); + } +} + + // TESTS // tape( 'main export is a function', opts, function test( t ) { @@ -53,12 +73,9 @@ tape( 'the function has an arity of 5', opts, function test( t ) { tape( 'the function scales elements from `x` by `alpha`', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.3, // 1 @@ -93,26 +110,16 @@ tape( 'the function scales elements from `x` by `alpha`', opts, function test( t 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a `x` stride', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 1 @@ -147,26 +154,16 @@ tape( 'the function supports specifying a `x` stride', opts, function test( t ) 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports specifying a negative `x` stride', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, // 3 @@ -201,26 +198,16 @@ tape( 'the function supports specifying a negative `x` stride', opts, function t 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 1 ); + t.end(); }); tape( 'the function supports a `x` offset', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, @@ -255,15 +242,8 @@ tape( 'the function supports a `x` offset', opts, function test( t ) { 4.2, // 3 -4.1 // 3 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 5 ); + t.end(); }); @@ -304,12 +284,9 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports complex access patterns', opts, function test( t ) { var expected; - var delta; var viewX; var alpha; - var tol; var x; - var k; x = new Complex64Array([ 0.1, @@ -348,14 +325,7 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 2.9, // 2 -0.2 // 2 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + isApprox( t, viewX, expected, 5 ); + t.end(); });