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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isPositiveZerof = require( './../lib' );
Expand All @@ -30,14 +30,19 @@ var isPositiveZerof = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float32'
};
x = uniform( 100, -50.0, 50.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 50.0;
y = isPositiveZerof( x );
y = isPositiveZerof( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -39,14 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float32'
};
x = uniform( 100, -50.0, 50.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 50.0;
y = isPositiveZerof( x );
y = isPositiveZerof( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ bool is_positive_zerof( float x ) {
*/
static double benchmark( void ) {
double elapsed;
float x[ 100 ];
double t;
float x;
bool y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0f*rand_float() ) - 50.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0f*rand_float() ) - 50.0f;
y = is_positive_zerof( x );
y = is_positive_zerof( x[ i%100 ] );
if ( y != true && y != false ) {
printf( "should return true or false\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ static float rand_float( void ) {
*/
static double benchmark( void ) {
double elapsed;
float x[ 100 ];
double t;
float x;
bool b;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (rand_float()*100.0f) - 50.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = (rand_float()*100.0f) - 50.0f;
b = stdlib_base_is_positive_zerof( x );
b = stdlib_base_is_positive_zerof( x[ i%100 ] );
if ( b != true && b != false ) {
printf( "should return either true or false\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function returns `true` if provided `+0`', function test( t ) {
t.equal( isPositiveZerof( 0.0 ), true, 'returns true' );
t.equal( isPositiveZerof( +0.0 ), true, 'returns true' );
t.equal( isPositiveZerof( 0.0 ), true, 'returns expected value' );
t.equal( isPositiveZerof( +0.0 ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `-0`', function test( t ) {
t.equal( isPositiveZerof( -0.0 ), false, 'returns false' );
t.equal( isPositiveZerof( -0.0 ), false, 'returns expected value' );
t.end();
});

Expand All @@ -62,7 +62,7 @@ tape( 'the function returns `false` if not provided `+0`', function test( t ) {
];

for ( i = 0; i < values.length; i++ ) {
t.equal( isPositiveZerof( values[i] ), false, 'returns false when provided ' + values[ i ] );
t.equal( isPositiveZerof( values[i] ), false, 'returns expected value when provided ' + values[ i ] );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ tape( 'main export is a function', opts, function test( t ) {
});

tape( 'the function returns `true` if provided `+0`', opts, function test( t ) {
t.equal( isPositiveZerof( 0.0 ), true, 'returns true' );
t.equal( isPositiveZerof( +0.0 ), true, 'returns true' );
t.equal( isPositiveZerof( 0.0 ), true, 'returns expected value' );
t.equal( isPositiveZerof( +0.0 ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `-0`', opts, function test( t ) {
t.equal( isPositiveZerof( -0.0 ), false, 'returns false' );
t.equal( isPositiveZerof( -0.0 ), false, 'returns expected value' );
t.end();
});

Expand All @@ -71,7 +71,7 @@ tape( 'the function returns `false` if not provided `+0`', opts, function test(
];

for ( i = 0; i < values.length; i++ ) {
t.equal( isPositiveZerof( values[i] ), false, 'returns false when provided ' + values[ i ] );
t.equal( isPositiveZerof( values[i] ), false, 'returns expected value when provided ' + values[ i ] );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ var isProbability = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var opts;
var x;
var y;
var i;

len = 100;
x = uniform( len, 1.0, -1.0 );
opts = {
'dtype': 'float64'
};
x = uniform( 100, -1.0, 1.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = isProbability( x[ i % len ] );
y = isProbability( x[ i % x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var opts;
var x;
var y;
var i;

len = 100;
x = uniform( len, -1.0, 1.0 );
opts = {
'dtype': 'float64'
};
x = uniform( 100, -1.0, 1.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = isProbability( x[ i % len ] );
y = isProbability( x[ i % x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ var isProbabilityf = require( './../lib' );

bench( pkg, function benchmark( b ) {
var opts;
var len;
var x;
var y;
var i;

len = 100;
opts = {
'dtype': 'float32'
};
x = uniform( len, -1.0, 1.0, opts );
x = uniform( 100, -1.0, 1.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = isProbabilityf( x[ i % len ] );
y = isProbabilityf( x[ i % x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,18 @@ var opts = {

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var len;
var x;
var y;
var i;

len = 100;
opts = {
'dtype': 'float32'
};
x = uniform( len, -1.0, 1.0, opts );
x = uniform( 100, -1.0, 1.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = isProbabilityf( x[ i % len ] );
y = isProbabilityf( x[ i % x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down