Skip to content

Commit 58a8f38

Browse files
committed
Rename file, use base array utility, add todo, and fix failing tests
1 parent b259a83 commit 58a8f38

File tree

6 files changed

+248
-434
lines changed

6 files changed

+248
-434
lines changed

lib/node_modules/@stdlib/math/tools/unary/lib/main.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function dispatch( table, options ) {
133133
* @throws {TypeError} must provide valid options
134134
* @returns {(ndarray|Collection|number|Complex)} results
135135
*/
136-
function dispatcher( x, options ) {
136+
function dispatcher( x ) {
137137
var xdtype;
138138
var ydtype;
139139
var opts;
@@ -153,7 +153,7 @@ function dispatch( table, options ) {
153153
}
154154
opts = {};
155155
if ( arguments.length > 1 ) {
156-
err = validate( opts, options );
156+
err = validate( opts, arguments[ 1 ] );
157157
if ( err ) {
158158
throw err;
159159
}
@@ -172,9 +172,7 @@ function dispatch( table, options ) {
172172
xdtype = dtype( x ) || 'generic';
173173
ydtype = opts.dtype || odtype( xdtype, OPTS.policy );
174174
y = buffer( ydtype, x.length );
175-
176-
// FIXME: need to supply dtype enum argument for each array argument...
177-
t.array( x.length, x, 1, y, 1 );
175+
t.array( x.length, xdtype, x, 1, ydtype, y, 1 );
178176
return y;
179177
}
180178
throw new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );
@@ -226,8 +224,7 @@ function dispatch( table, options ) {
226224
if ( y.length !== x.length ) {
227225
throw new RangeError( 'invalid argument. Output array must have the same number of elements (i.e., length) as the input array.' );
228226
}
229-
// FIXME: need to supply dtype enum argument for each array argument...
230-
t.array( x.length, x, 1, y, 1 );
227+
t.array( x.length, dtype( x ) || 'generic', x, 1, dtype( y ) || 'generic', y, 1 );
231228
return y;
232229
}
233230
throw new TypeError( 'invalid argument. If the first argument is an array-like object, the second argument must be an array-like object.' );

lib/node_modules/@stdlib/math/tools/unary/lib/ndarray.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,7 @@ var ndarray = require( '@stdlib/ndarray/ctor' );
2424
var buffer = require( '@stdlib/ndarray/base/buffer' );
2525
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
2626
var numel = require( '@stdlib/ndarray/base/numel' );
27-
28-
29-
// FUNCTIONS //
30-
31-
/**
32-
* Copies an array-like object to a generic array.
33-
*
34-
* @private
35-
* @param {ArrayLikeObject} x - input array
36-
* @returns {Array} output array
37-
*/
38-
function copy( x ) {
39-
var out;
40-
var i;
41-
42-
out = [];
43-
for ( i = 0; i < x.length; i++ ) {
44-
out.push( x[ i ] );
45-
}
46-
return out;
47-
}
27+
var copy = require( '@stdlib/array/base/copy-indexed' );
4828

4929

5030
// MAIN //

lib/node_modules/@stdlib/math/tools/unary/lib/resolve_output_dtype.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ function resolve( xdtype, policy ) {
3939
case 'same':
4040
return xdtype;
4141
case 'float':
42+
// TODO: we may want to delegate checking for a floating-point dtype to a utility function/package (e.g., isFloatDtype), in order to centralize logic for testing whether a dtype is "floating-point". Otherwise, this will be yet another place to update logic should we ever add, e.g., a `float128` or `float16` dtype.
4243
if (
4344
xdtype === 'float64' ||
4445
xdtype === 'float32' ||
45-
xdtype === 'generic'
46+
xdtype === 'generic' ||
47+
xdtype === 'complex128' ||
48+
xdtype === 'complex64'
4649
) {
4750
return xdtype;
4851
}

lib/node_modules/@stdlib/math/tools/unary/test/test.js

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
var tape = require( 'tape' );
2424
var Float64Array = require( '@stdlib/array/float64' );
25-
var Int32Array = require( '@stdlib/array/int32' );
2625
var array = require( '@stdlib/ndarray/array' );
2726
var ndarray = require( '@stdlib/ndarray/ctor' );
2827
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
@@ -56,10 +55,10 @@ tape( 'the function throws an error if provided an invalid table object', functi
5655
void 0,
5756
[],
5857
{
59-
'scalar': null
58+
'complex': {}
6059
},
6160
{
62-
'scalar': [ 'number' ]
61+
'number': [ 'number' ]
6362
},
6463
{
6564
'array': {}
@@ -408,52 +407,4 @@ tape( 'the function returns a function which supports operating on an ndarray (n
408407
t.end();
409408
});
410409

411-
tape( 'the function returns a function which defaults to a "generic" implementation if unable to resolve a function corresponding to an array-like object\'s underlying data type', function test( t ) {
412-
var expected;
413-
var values;
414-
var abs;
415-
416-
abs = dispatch( table );
417-
418-
values = new Int32Array([
419-
-1.0,
420-
-3.0,
421-
2.0
422-
]);
423-
expected = new Int32Array([
424-
1.0,
425-
3.0,
426-
2.0
427-
]);
428-
t.deepEqual( abs( values ), expected, 'returns expected value' );
429-
t.end();
430-
});
431-
432-
tape( 'the function returns a function which defaults to a "generic" implementation if unable to resolve a function corresponding to an ndarray\'s underlying data type', function test( t ) {
433-
var expected;
434-
var values;
435-
var abs;
436-
437-
abs = dispatch( table );
438-
439-
values = new Int32Array([
440-
-1.0,
441-
-3.0,
442-
2.0
443-
]);
444-
values = array( values, {
445-
'dtype': 'int32'
446-
});
447-
expected = new Int32Array([
448-
1.0,
449-
3.0,
450-
2.0
451-
]);
452-
expected = array( expected, {
453-
'dtype': 'int32'
454-
});
455-
t.deepEqual( abs( values ), expected, 'returns expected value' );
456-
t.end();
457-
});
458-
459410
// TODO: add tests for complex numbers

0 commit comments

Comments
 (0)