Skip to content
Open
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
87 changes: 54 additions & 33 deletions lib/node_modules/@stdlib/blas/base/srot/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );


Expand All @@ -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' );
}
}

Expand All @@ -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;
Expand All @@ -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 ];
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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 ];
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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 ];
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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 ];
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
});
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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();
});
Loading
Loading