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
81 changes: 31 additions & 50 deletions lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,36 @@ 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' );


// VARIABLES //

var ULP = 5;


// 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 ) {
Expand All @@ -44,12 +69,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
Expand All @@ -76,26 +98,15 @@ 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, ULP );
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
Expand Down Expand Up @@ -130,26 +141,15 @@ 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, ULP );
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
Expand Down Expand Up @@ -184,15 +184,7 @@ 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, ULP );
t.end();
});

Expand Down Expand Up @@ -233,13 +225,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([
Expand Down Expand Up @@ -274,14 +263,6 @@ 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, ULP );
t.end();
});
94 changes: 32 additions & 62 deletions lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,36 @@ 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' );


// VARIABLES //

var ULP = 5;


// 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 ) {
Expand All @@ -44,12 +69,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
Expand Down Expand Up @@ -84,26 +106,15 @@ 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, ULP );
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
Expand Down Expand Up @@ -138,26 +149,15 @@ 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, ULP );
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
Expand Down Expand Up @@ -192,26 +192,15 @@ 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, ULP );
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,
Expand Down Expand Up @@ -246,15 +235,7 @@ 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, ULP );
t.end();
});

Expand Down Expand Up @@ -295,12 +276,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,
Expand Down Expand Up @@ -339,14 +317,6 @@ 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, ULP );
t.end();
});
Loading