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
23 changes: 3 additions & 20 deletions lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
// MODULES //

var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var complexDataType = require( '@stdlib/complex/dtype' );
var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' );
var dims = require( '@stdlib/ndarray/base/ndims' );
var defaults = require( '@stdlib/ndarray/defaults' );
Expand All @@ -36,13 +32,11 @@ var getOrder = require( '@stdlib/ndarray/base/order' );
var getDType = require( '@stdlib/ndarray/base/dtype' );
var getData = require( '@stdlib/ndarray/base/data-buffer' );
var ones = require( '@stdlib/array/base/ones' );
var scalarDType = require( '@stdlib/ndarray/base/scalar-dtype' );


// VARIABLES //

var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' );
var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' );
var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' );
var ORDER = defaults.get( 'order' );


Expand Down Expand Up @@ -107,19 +101,8 @@ function atleastnd( ndims, arrays ) {
out.push( new ndarray( getDType( v ), getData( v ), shape, strides, getOffset( v ), getOrder( v ) ) ); // eslint-disable-line max-len
continue;
}
// For scalar values, resolve a corresponding ndarray data type...
if ( isNumber( v ) ) { // TODO: consider abstracting this logic to an `ndarray/base/scalar-dtype` (???) package, as this logic is found elsewhere (e.g., `ndarray/from-scalar`) and it would be good to avoid duplication, especially as we add support for more ndarray data types
dt = DEFAULT_REAL;
} else if ( isBoolean( v ) ) {
dt = DEFAULT_BOOL;
} else if ( isComplexLike( v ) ) {
dt = complexDataType( v );
if ( dt === null ) {
dt = DEFAULT_CMPLX;
}
} else {
dt = 'generic';
}

dt = scalarDType( v );
out.push( broadcastScalar( v, dt, ones( ndims ), ORDER ) );
}
return out;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var scalarDType = require( './../lib' );

console.log( scalarDType( 5 ) );
// => float64

console.log( scalarDType( true ) );
// => bool

console.log( scalarDType( {} ) );
// => generic
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

// MODULES //

var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
var complexDataType = require( '@stdlib/complex/dtype' );
var defaults = require( '@stdlib/ndarray/defaults' );

// VARIABLES //

var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' );
var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' );
var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' );

// MAIN //

function scalarDType( v ) {
if ( isNumber( v ) ) {
return DEFAULT_REAL;
}
if ( isBoolean( v ) ) {
return DEFAULT_BOOL;
}
if ( isComplexLike( v ) ) {
var dt = complexDataType( v );
return ( dt === null ) ? DEFAULT_CMPLX : dt;
}
return 'generic';
}

module.exports = scalarDType;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@stdlib/ndarray/base/scalar-dtype",
"version": "0.0.0",
"main": "./lib",
"scripts": {
"test": "node ./test/test.js"
}
}
19 changes: 19 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/scalar-dtype/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var tape = require( 'tape' );
var scalarDType = require( './../lib' );

tape( 'returns dtype for number', function test( t ) {
t.strictEqual( scalarDType( 5 ), 'float64', 'returns float64' );
t.end();
});

tape( 'returns dtype for boolean', function test( t ) {
t.strictEqual( scalarDType( true ), 'bool', 'returns bool' );
t.end();
});

tape( 'returns generic for objects', function test( t ) {
t.strictEqual( scalarDType( {} ), 'generic', 'returns generic' );
t.end();
});