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
42 changes: 6 additions & 36 deletions lib/node_modules/@stdlib/blas/base/wasm/snrm2/test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,10 @@

var tape = require( 'tape' );
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 snrm2 = require( './../lib' );


// 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 an object', function test( t ) {
Expand All @@ -76,12 +46,12 @@ tape( 'the `main` method calculates the L2-norm of a vector', function test( t )
x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] );

nrm2 = snrm2.main( x.length, x, 1 );
isApprox( t, nrm2, 7.4, 2.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 7.416198253631592, 0 ), true, 'returns expected value' );

x = new Float32Array( [ -4.0 ] );

nrm2 = snrm2.main( x.length, x, 1 );
isApprox( t, nrm2, 4.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 4.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand All @@ -102,7 +72,7 @@ tape( 'the `main` method supports a `stride` parameter', function test( t ) {
]);

nrm2 = snrm2.main( 4, x, 2 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand All @@ -123,7 +93,7 @@ tape( 'the `main` method supports a negative `stride` parameter', function test(
]);

nrm2 = snrm2.main( 4, x, -2 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -163,7 +133,7 @@ tape( 'the `main` method supports view offsets', function test( t ) {
x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

nrm2 = snrm2.main( 4, x1, 2 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,10 @@
var tape = require( 'tape' );
var Memory = require( '@stdlib/wasm/memory' );
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 Module = require( './../lib' ).Module;


// 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 @@ -96,15 +66,15 @@ tape( 'a module instance has a `main` method which calculates the L2-norm of a v
mod.write( xp, new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ) );

nrm2 = mod.main( 6, xp, 1 );
isApprox( t, nrm2, 7.4, 2.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 7.416198253631592, 0 ), true, 'returns expected value' );

// Short datasets:
xp = 0;

mod.write( xp, new Float32Array( [ -4.0 ] ) );

nrm2 = mod.main( 1, xp, 1 );
isApprox( t, nrm2, 4.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 4.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -135,7 +105,7 @@ tape( 'a module instance has a `main` method which supports a `stride` parameter
]));

nrm2 = mod.main( 4, xp, 2 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -166,7 +136,7 @@ tape( 'a module instance has a `main` method which supports a negative `stride`
]));

nrm2 = mod.main( 4, xp, -2 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,10 @@
var tape = require( 'tape' );
var Memory = require( '@stdlib/wasm/memory' );
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 Module = require( './../lib' ).Module;


// 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 @@ -96,15 +66,15 @@ tape( 'a module instance has an `ndarray` method which calculates the L2-norm of
mod.write( xp, new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ) );

nrm2 = mod.ndarray( 6, xp, 1, 0 );
isApprox( t, nrm2, 7.4, 2.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 7.416198253631592, 0 ), true, 'returns expected value' );

// Short datasets:
xp = 0;

mod.write( xp, new Float32Array( [ -4.0 ] ) );

nrm2 = mod.ndarray( 1, xp, 1, 0 );
isApprox( t, nrm2, 4.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 4.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -135,7 +105,7 @@ tape( 'a module instance has an `ndarray` method which supports a `stride` param
]));

nrm2 = mod.ndarray( 4, xp, 2, 0 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -166,7 +136,7 @@ tape( 'a module instance has an `ndarray` method which supports a negative `stri
]));

nrm2 = mod.ndarray( 4, xp, -2, 6 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -197,7 +167,7 @@ tape( 'a module instance has an `ndarray` method which supports an `x` offset',
]));

nrm2 = mod.ndarray( 4, xp, 2, 1 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down
42 changes: 6 additions & 36 deletions lib/node_modules/@stdlib/blas/base/wasm/snrm2/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 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 snrm2 = require( './../lib' );


// 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 an object', function test( t ) {
Expand All @@ -76,13 +46,13 @@ tape( 'the `ndarray` method calculates the L2-norm of a vector', function test(
x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] );

nrm2 = snrm2.ndarray( x.length, x, 1, 0 );
isApprox( t, nrm2, 7.4, 2.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 7.416198253631592, 0 ), true, 'returns expected value' );

// Short datasets:
x = new Float32Array( [ -4.0 ] );

nrm2 = snrm2.ndarray( x.length, x, 1, 0 );
isApprox( t, nrm2, 4.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 4.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand All @@ -103,7 +73,7 @@ tape( 'the `ndarray` method supports a `stride` parameter', function test( t ) {
]);

nrm2 = snrm2.ndarray( 4, x, 2, 0 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand All @@ -124,7 +94,7 @@ tape( 'the `ndarray` method supports a negative stride parameter', function test
]);

nrm2 = snrm2.ndarray( 4, x, -2, x.length-2 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand All @@ -145,7 +115,7 @@ tape( 'the `ndarray` method supports an `offset` parameter', function test( t )
]);

nrm2 = snrm2.ndarray( 4, x, 2, 1 );
isApprox( t, nrm2, 5.0, 1.0 );
t.strictEqual( isAlmostSameValuef( nrm2, 5.0, 0 ), true, 'returns expected value' );

t.end();
});
Expand Down
Loading