Skip to content

Commit bd31cd9

Browse files
committed
refactor: use internal utility and expose DataType instances, rather than enums
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5b491c9 commit bd31cd9

File tree

5 files changed

+16
-269
lines changed

5 files changed

+16
-269
lines changed

lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json

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

lib/node_modules/@stdlib/ndarray/dtypes/lib/enum.js

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

lib/node_modules/@stdlib/ndarray/dtypes/lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232

3333
// MODULES //
3434

35-
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
35+
var dtypeObjects = require( '@stdlib/ndarray/base/dtype-objects' );
3636
var main = require( './main.js' );
37-
var enumeration = require( './enum.js' );
3837
var assign = require( './assign.js' );
3938

4039

4140
// MAIN //
4241

43-
setReadOnly( main, 'enum', enumeration );
44-
assign( main, enumeration() );
42+
assign( main, dtypeObjects() );
4543

4644

4745
// EXPORTS //
4846

4947
module.exports = main;
48+
49+
// exports: { "float64": "main.float64", "float32": "main.float32", "float16": "main.float16", "complex128": "main.complex128", "complex64": "main.complex64", "complex32": "main.complex32", "int32": "main.int32", "int16": "main.int16", "int8": "main.int8", "uint32": "main.uint32", "uint16": "main.uint16", "uint8": "main.uint8", "uint8c": "main.uint8c", "bool": "main.bool", "binary": "main.binary", "generic": "main.generic" }

lib/node_modules/@stdlib/ndarray/dtypes/lib/main.js

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020

2121
// MODULES //
2222

23-
var replace = require( '@stdlib/string/base/replace' );
24-
var DTYPES = require( './dtypes.json' );
25-
26-
27-
// VARIABLES //
28-
29-
var RE_SUFFIX = /_and_generic$/;
23+
var dtypeStrings = require( '@stdlib/ndarray/base/dtype-strings' );
3024

3125

3226
// MAIN //
@@ -35,7 +29,7 @@ var RE_SUFFIX = /_and_generic$/;
3529
* Returns a list of ndarray data types.
3630
*
3731
* @param {string} [kind] - data type kind
38-
* @returns {StringArray} list of ndarray data types
32+
* @returns {Array<string>} list of ndarray data types
3933
*
4034
* @example
4135
* var list = dtypes();
@@ -46,26 +40,10 @@ var RE_SUFFIX = /_and_generic$/;
4640
* // returns [...]
4741
*/
4842
function dtypes() {
49-
var kind;
50-
var out;
51-
var FLG;
52-
if ( arguments.length === 0 ) {
53-
return DTYPES.all.slice();
54-
}
55-
FLG = false;
56-
kind = arguments[ 0 ];
57-
if ( RE_SUFFIX.test( kind ) ) {
58-
kind = replace( kind, RE_SUFFIX, '' );
59-
if ( kind !== 'all' && kind !== 'index' ) {
60-
FLG = true;
61-
}
62-
}
63-
out = DTYPES[ kind ];
64-
out = ( out ) ? out.slice() : [];
65-
if ( FLG && out.length > 0 ) {
66-
out.push( 'generic' );
43+
if ( arguments.length ) {
44+
return dtypeStrings( arguments[ 0 ] );
6745
}
68-
return out;
46+
return dtypeStrings();
6947
}
7048

7149

lib/node_modules/@stdlib/ndarray/dtypes/test/test.js

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

2323
var tape = require( 'tape' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25-
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
25+
var isDataTypeObject = require( '@stdlib/ndarray/base/assert/is-data-type-object' );
2626
var dtypes = require( './../lib' );
2727

2828

@@ -36,8 +36,6 @@ var DTYPES = [
3636
'uint16',
3737
'int32',
3838
'uint32',
39-
'int64',
40-
'uint64',
4139

4240
'float16',
4341
'float32',
@@ -676,28 +674,14 @@ tape( 'the function returns an empty array if provided an unrecognized data type
676674
t.end();
677675
});
678676

679-
tape( 'attached to the main function is an `enum` method to return an object mapping dtypes to enumeration constants for C inter-operation', function test( t ) {
680-
var obj;
681-
var i;
682-
683-
t.strictEqual( hasOwnProp( dtypes, 'enum' ), true, 'has property' );
684-
t.strictEqual( typeof dtypes.enum, 'function', 'has method' );
685-
686-
obj = dtypes.enum();
687-
t.strictEqual( typeof obj, 'object', 'returns expected value type' );
688-
689-
for ( i = 0; i < DTYPES.length; i++ ) {
690-
t.strictEqual( hasOwnProp( obj, DTYPES[ i ] ), true, 'has property `' + DTYPES[ i ] + '`' );
691-
t.strictEqual( isNonNegativeInteger( obj[ DTYPES[i] ] ), true, 'returns expected value' );
692-
}
693-
694-
t.end();
695-
});
696-
697-
tape( 'attached to the main function are dtype enumeration constants', function test( t ) {
677+
tape( 'attached to the main function are data type instances', function test( t ) {
678+
var k;
698679
var i;
699680
for ( i = 0; i < DTYPES.length; i++ ) {
700-
t.strictEqual( isNonNegativeInteger( dtypes[ DTYPES[i] ] ), true, 'returns expected value' );
681+
k = DTYPES[ i ];
682+
t.strictEqual( hasOwnProp( dtypes, k ), true, 'returns expected value' );
683+
t.strictEqual( isDataTypeObject( dtypes[ k ] ), true, 'returns expected value' );
684+
t.strictEqual( String( dtypes[ k ] ), k, 'returns expected value' );
701685
}
702686
t.end();
703687
});

0 commit comments

Comments
 (0)