Skip to content

Commit 7078536

Browse files
committed
refactor: use ctors package
1 parent cf3f92e commit 7078536

3 files changed

Lines changed: 15 additions & 44 deletions

File tree

lib/node_modules/@stdlib/complex/cmplx/benchmark/benchmark.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
2524
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var pkg = require( './../package.json' ).name;
2726
var complex = require( './../lib' );
@@ -34,7 +33,7 @@ bench( pkg, function benchmark( b ) {
3433
var i;
3534
b.tic();
3635
for ( i = 0; i < b.iterations; i++ ) {
37-
z = complex( randu(), randu() );
36+
z = complex( i, -i );
3837
if ( isnan( z ) ) {
3938
b.fail( 'should not return NaN' );
4039
}
@@ -52,7 +51,7 @@ bench( pkg+':dtype=float64', function benchmark( b ) {
5251
var i;
5352
b.tic();
5453
for ( i = 0; i < b.iterations; i++ ) {
55-
z = complex( randu(), randu(), 'float64' );
54+
z = complex( i, -i, 'float64' );
5655
if ( isnan( z ) ) {
5756
b.fail( 'should not return NaN' );
5857
}
@@ -70,7 +69,7 @@ bench( pkg+':dtype=float32', function benchmark( b ) {
7069
var i;
7170
b.tic();
7271
for ( i = 0; i < b.iterations; i++ ) {
73-
z = complex( randu(), randu(), 'float32' );
72+
z = complex( i, -i, 'float32' );
7473
if ( isnan( z ) ) {
7574
b.fail( 'should not return NaN' );
7675
}

lib/node_modules/@stdlib/complex/cmplx/lib/ctors.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/node_modules/@stdlib/complex/cmplx/lib/main.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@
2020

2121
// MODULES //
2222

23+
var ctors = require( '@stdlib/complex/ctors' );
2324
var format = require( '@stdlib/string/format' );
24-
var CTORS = require( './ctors.js' );
25+
26+
27+
// VARIABLES //
28+
29+
var TABLE = {
30+
'float64': 'complex128',
31+
'float32': 'complex64'
32+
};
33+
var DEFAULT_CTOR = ctors( TABLE[ 'float64' ] );
2534

2635

2736
// MAIN //
@@ -42,13 +51,13 @@ var CTORS = require( './ctors.js' );
4251
function complex( real, imag, dtype ) {
4352
var ctor;
4453
if ( arguments.length > 2 ) {
45-
ctor = CTORS[ dtype ];
54+
ctor = ctors( TABLE[ dtype ] );
4655
if ( ctor ) {
4756
return new ctor( real, imag );
4857
}
4958
throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );
5059
}
51-
return new CTORS[ 'float64' ]( real, imag );
60+
return new DEFAULT_CTOR( real, imag );
5261
}
5362

5463

0 commit comments

Comments
 (0)