Skip to content
Merged
Show file tree
Hide file tree
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
54 changes: 12 additions & 42 deletions lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,10 @@

var tape = require( 'tape' );
var Complex64Array = require( '@stdlib/array/complex64' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
var scnrm2 = 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 {number} rtol - relative tolerance
*/
function isApprox( t, actual, expected, rtol ) {
var delta;
var tol;
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+'.' );
}
}
}


// TESTS //

tape( 'main export is a function', function test( t ) {
Expand Down Expand Up @@ -89,7 +59,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );

x = new Complex64Array([
0.1, // 1
Expand All @@ -104,7 +74,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 0.7;

actual = scnrm2( 3, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );

// Checked on Wolfram Alpha:
x = new Complex64Array([
Expand All @@ -120,7 +90,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 14142135623730952;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );

// Checked on Wolfram Alpha:
x = new Complex64Array([
Expand All @@ -136,7 +106,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 2.82843e-20;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 9 ), true, 'returns expected value' );

// Checked on Wolfram Alpha:
x = new Complex64Array([
Expand All @@ -152,7 +122,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 200000000000000000000;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );

// Checked on Wolfram Alpha:
x = new Complex64Array([
Expand All @@ -168,7 +138,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 20000000000;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 0 ), true, 'returns expected value' );

// Checked on Wolfram Alpha:
x = new Complex64Array([
Expand All @@ -184,7 +154,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 2.52012e-19;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 13 ), true, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -233,7 +203,7 @@ tape( 'the function supports specifying a stride', function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, 2, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -263,7 +233,7 @@ tape( 'the function supports specifying a negative stride', function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, -2, 6 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand All @@ -284,9 +254,9 @@ tape( 'the function supports specifying an offset', function test( t ) {
9.0,
10.0
]);
expected = 14.1;
expected = 14.106736183166504;

actual = scnrm2( 3, x, 1, 1 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 0 ), true, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var Complex64Array = require( '@stdlib/array/complex64' );
var EPS = require( '@stdlib/constants/float64/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' );


Expand All @@ -36,35 +35,6 @@ 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 {number} rtol - relative tolerance
*/
function isApprox( t, actual, expected, rtol ) {
var delta;
var tol;
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+'.' );
}
}
}


// TESTS //

tape( 'main export is a function', opts, function test( t ) {
Expand Down Expand Up @@ -98,7 +68,7 @@ tape( 'the function computes the L2-norm', opts, function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );

x = new Complex64Array([
0.1, // 1
Expand All @@ -113,7 +83,7 @@ tape( 'the function computes the L2-norm', opts, function test( t ) {
expected = 0.7;

actual = scnrm2( 3, x, 1, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -162,7 +132,7 @@ tape( 'the function supports specifying a stride', opts, function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, 2, 0 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -192,7 +162,7 @@ tape( 'the function supports specifying a negative stride', opts, function test(
expected = 0.8;

actual = scnrm2( 4, x, -2, 6 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand All @@ -213,9 +183,9 @@ tape( 'the function supports specifying an offset', opts, function test( t ) {
9.0,
10.0
]);
expected = 14.1;
expected = 14.106736183166504;

actual = scnrm2( 3, x, 1, 1 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});
44 changes: 7 additions & 37 deletions lib/node_modules/@stdlib/blas/base/scnrm2/test/test.scnrm2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,10 @@

var tape = require( 'tape' );
var Complex64Array = require( '@stdlib/array/complex64' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
var scnrm2 = require( './../lib/scnrm2.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 {number} rtol - relative tolerance
*/
function isApprox( t, actual, expected, rtol ) {
var delta;
var tol;
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+'.' );
}
}
}


// TESTS //

tape( 'main export is a function', function test( t ) {
Expand Down Expand Up @@ -89,7 +59,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, 1 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );

x = new Complex64Array([
0.1, // 1
Expand All @@ -104,7 +74,7 @@ tape( 'the function computes the L2-norm', function test( t ) {
expected = 0.7;

actual = scnrm2( 3, x, 1 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -153,7 +123,7 @@ tape( 'the function supports specifying a stride', function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, 2 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -183,7 +153,7 @@ tape( 'the function supports specifying a negative stride', function test( t ) {
expected = 0.8;

actual = scnrm2( 4, x, -2 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 1 ), true, 'returns expected value' );
t.end();
});

Expand All @@ -205,11 +175,11 @@ tape( 'the function supports view offsets', function test( t ) {
9.0,
10.0
]);
expected = 14.1;
expected = 14.106736183166504;

x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 );

actual = scnrm2( 3, x1, 1 );
isApprox( t, actual, expected, 2.0 );
t.strictEqual( isAlmostSameValuef( actual, expected, 0 ), true, 'returns expected value' );
t.end();
});
Loading
Loading