Skip to content

Commit ae21126

Browse files
committed
feat: add support for struct arrays
--- 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: passed - 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: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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 3c4e7f2 commit ae21126

File tree

5 files changed

+47
-48
lines changed

5 files changed

+47
-48
lines changed

lib/node_modules/@stdlib/ndarray/base/buffer-dtype-enum/README.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var dtypeEnum = require( '@stdlib/ndarray/base/buffer-dtype-enum' );
4242

4343
#### dtypeEnum( buffer )
4444

45-
Returns the [data type][@stdlib/ndarray/dtypes] enumeration constant of an ndarray data [`buffer`][@stdlib/ndarray/base/buffer-ctors].
45+
Returns the [data type][@stdlib/ndarray/dtypes] enumeration constant of an ndarray data [buffer][@stdlib/ndarray/base/buffer-ctors].
4646

4747
```javascript
4848
var Float64Array = require( '@stdlib/array/float64' );
@@ -52,7 +52,7 @@ var c = dtypeEnum( buf );
5252
// returns <number>
5353
```
5454

55-
If provided an ndarray data [`buffer`][@stdlib/ndarray/base/buffer-ctors] having an unknown or unsupported [data type][@stdlib/ndarray/dtypes], the function returns `null`.
55+
If provided an ndarray data [buffer][@stdlib/ndarray/base/buffer-ctors] having an unknown or unsupported [data type][@stdlib/ndarray/dtypes], the function returns `null`.
5656

5757
```javascript
5858
var c = dtypeEnum( 'beep' );
@@ -86,40 +86,27 @@ var c = dtypeEnum( 'beep' );
8686
```javascript
8787
var dtypes = require( '@stdlib/ndarray/dtypes' );
8888
var bufferCtors = require( '@stdlib/ndarray/base/buffer-ctors' );
89-
var isFunction = require( '@stdlib/assert/is-function' );
9089
var dtypeEnum = require( '@stdlib/ndarray/base/buffer-dtype-enum' );
9190

92-
var DTYPES;
93-
var ctor;
94-
var buf;
95-
var len;
96-
var c;
97-
var i;
98-
9991
// Get a list of supported ndarray buffer data types:
100-
DTYPES = dtypes();
92+
var DTYPES = dtypes( 'integer_and_generic' );
10193

10294
// Buffer length:
103-
len = 10;
95+
var len = 10;
10496

10597
// For each supported data type, create a buffer and retrieve its data type enumeration constant...
98+
var ctor;
99+
var i;
106100
for ( i = 0; i < DTYPES.length; i++ ) {
107101
ctor = bufferCtors( DTYPES[ i ] );
108-
if ( DTYPES[ i ] === 'binary' && isFunction( ctor.alloc ) ) {
109-
buf = ctor.alloc( len );
110-
} else {
111-
buf = new ctor( len );
112-
}
113-
c = dtypeEnum( buf );
114-
console.log( '%s => %d', DTYPES[ i ], c );
102+
console.log( '%s => %d', DTYPES[ i ], dtypeEnum( new ctor( len ) ) );
115103
}
116104

117105
// Try an array-like object...
118-
buf = {
119-
'length': 10
106+
var buf = {
107+
'length': len
120108
};
121-
c = dtypeEnum( buf );
122-
console.log( '%s => %s', 'generic', c );
109+
console.log( '%s => %s', 'generic', dtypeEnum( buf ) );
123110
```
124111

125112
</section>

lib/node_modules/@stdlib/ndarray/base/buffer-dtype-enum/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var dtypeEnum = require( './../lib' );
3131

3232
// VARIABLES //
3333

34-
var DTYPES = dtypes();
34+
var DTYPES = dtypes( 'integer_and_generic' );
3535

3636

3737
// MAIN //

lib/node_modules/@stdlib/ndarray/base/buffer-dtype-enum/examples/index.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,24 @@
2020

2121
var dtypes = require( '@stdlib/ndarray/dtypes' );
2222
var bufferCtors = require( '@stdlib/ndarray/base/buffer-ctors' );
23-
var isFunction = require( '@stdlib/assert/is-function' );
2423
var dtypeEnum = require( './../lib' );
2524

26-
var DTYPES;
27-
var ctor;
28-
var buf;
29-
var len;
30-
var c;
31-
var i;
32-
3325
// Get a list of supported ndarray buffer data types:
34-
DTYPES = dtypes();
26+
var DTYPES = dtypes( 'integer_and_generic' );
3527

3628
// Buffer length:
37-
len = 10;
29+
var len = 10;
3830

3931
// For each supported data type, create a buffer and retrieve its data type enumeration constant...
32+
var ctor;
33+
var i;
4034
for ( i = 0; i < DTYPES.length; i++ ) {
4135
ctor = bufferCtors( DTYPES[ i ] );
42-
if ( DTYPES[ i ] === 'binary' && isFunction( ctor.alloc ) ) {
43-
buf = ctor.alloc( len );
44-
} else {
45-
buf = new ctor( len );
46-
}
47-
c = dtypeEnum( buf );
48-
console.log( '%s => %d', DTYPES[ i ], c );
36+
console.log( '%s => %d', DTYPES[ i ], dtypeEnum( new ctor( len ) ) );
4937
}
5038

5139
// Try an array-like object...
52-
buf = {
53-
'length': 10
40+
var buf = {
41+
'length': len
5442
};
55-
c = dtypeEnum( buf );
56-
console.log( '%s => %s', 'generic', c );
43+
console.log( '%s => %s', 'generic', dtypeEnum( buf ) );

lib/node_modules/@stdlib/ndarray/base/buffer-dtype-enum/lib/main.js

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

2121
// MODULES //
2222

23-
var str2enum = require( '@stdlib/ndarray/base/dtype-str2enum' );
23+
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
2424
var dtype = require( '@stdlib/ndarray/base/buffer-dtype' );
2525

2626

@@ -29,7 +29,7 @@ var dtype = require( '@stdlib/ndarray/base/buffer-dtype' );
2929
/**
3030
* Returns the data type enumeration constant for a provided ndarray data buffer.
3131
*
32-
* @param {Collection} arr - strided array
32+
* @param {Collection} arr - ndarray data buffer
3333
* @returns {(integer|null)} data type enumeration constant or null
3434
*
3535
* @example
@@ -43,7 +43,7 @@ var dtype = require( '@stdlib/ndarray/base/buffer-dtype' );
4343
function dtypeEnum( arr ) {
4444
var dt = dtype( arr );
4545
if ( dt ) {
46-
return str2enum( dt );
46+
return resolveEnum( dt );
4747
}
4848
return null;
4949
}

lib/node_modules/@stdlib/ndarray/base/buffer-dtype-enum/test/test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var tape = require( 'tape' );
2424
var dtypes = require( '@stdlib/ndarray/dtypes' );
2525
var bufferCtors = require( '@stdlib/ndarray/base/buffer-ctors' );
26+
var structFactory = require( '@stdlib/array/struct-factory' );
2627
var isFunction = require( '@stdlib/assert/is-function' );
2728
var dtypeEnum = require( './../lib' );
2829

@@ -49,6 +50,10 @@ tape( 'the function returns the data type enumeration constant for ndarray data
4950

5051
for ( i = 0; i < DTYPES.length; i++ ) {
5152
ctor = bufferCtors( DTYPES[ i ] );
53+
if ( DTYPES[ i ] === 'float16' || DTYPES[ i ] === 'complex32' ) {
54+
// FIXME: remove this condition once `float16` and `complex32` are supported
55+
continue;
56+
}
5257
if ( DTYPES[ i ] === 'binary' && isFunction( ctor.alloc ) ) {
5358
buf = ctor.alloc( 10 );
5459
} else {
@@ -60,6 +65,26 @@ tape( 'the function returns the data type enumeration constant for ndarray data
6065
t.end();
6166
});
6267

68+
tape( 'the function supports struct arrays', function test( t ) {
69+
var schema;
70+
var ctor;
71+
var buf;
72+
var dt;
73+
74+
schema = [
75+
{
76+
'name': 'foo',
77+
'type': 'float64'
78+
}
79+
];
80+
ctor = structFactory( schema );
81+
82+
buf = new ctor( 10 );
83+
dt = dtypeEnum( buf );
84+
t.strictEqual( dt, TABLE[ 'userdefined_type' ], 'returns expected value' );
85+
t.end();
86+
});
87+
6388
tape( 'the function supports generic objects', function test( t ) {
6489
var buf;
6590
var dt;

0 commit comments

Comments
 (0)