@@ -18,22 +18,49 @@ var DESELECTDIM = require('../constants/interactions').DESELECTDIM;
18
18
var nestedProperty = require ( './nested_property' ) ;
19
19
var counterRegex = require ( './regex' ) . counter ;
20
20
var modHalf = require ( './mod' ) . modHalf ;
21
+ var isPlainObject = require ( './is_plain_object' ) ;
21
22
var isArrayOrTypedArray = require ( './array' ) . isArrayOrTypedArray ;
22
23
24
+ var typedArrays = {
25
+ int8 : typeof Int8Array !== 'undefined' ? 1 : 0 ,
26
+ uint8 : typeof Uint8Array !== 'undefined' ? 1 : 0 ,
27
+ uint8clamped : typeof Uint8ClampedArray !== 'undefined' ? 1 : 0 ,
28
+ int16 : typeof Int16Array !== 'undefined' ? 1 : 0 ,
29
+ uint16 : typeof Uint16Array !== 'undefined' ? 1 : 0 ,
30
+ int32 : typeof Int32Array !== 'undefined' ? 1 : 0 ,
31
+ uint32 : typeof Uint32Array !== 'undefined' ? 1 : 0 ,
32
+ float32 : typeof Float32Array !== 'undefined' ? 1 : 0 ,
33
+ float64 : typeof Float64Array !== 'undefined' ? 1 : 0 ,
34
+ bigint64 : typeof BigInt64Array !== 'undefined' ? 1 : 0 ,
35
+ biguint64 : typeof BigUint64Array !== 'undefined' ? 1 : 0
36
+ } ;
37
+
23
38
exports . valObjectMeta = {
24
39
data_array : {
25
40
// You can use *dflt=[] to force said array to exist though.
26
41
description : [
27
42
'An {array} of data.' ,
28
- 'The value MUST be an {array}, or we ignore it.' ,
29
- 'Note that typed arrays (e.g. Float32Array) are supported.'
43
+ 'The value could be an {array}' ,
44
+ 'noting that typed arrays (e.g. Float32Array) are also supported.' ,
45
+ 'It could also be an object in the form of' ,
46
+ 'v: {, dtype: \'float32\', bvals: [/* ... */]}, shape: [dim0 (, dim1, (dim3))]' ,
47
+ 'otherwise, it would be ignored.'
30
48
] . join ( ' ' ) ,
31
49
requiredOpts : [ ] ,
32
50
otherOpts : [ 'dflt' ] ,
33
51
coerceFunction : function ( v , propOut , dflt ) {
34
- // TODO maybe `v: {type: 'float32', vals: [/* ... */]}` also
35
- if ( isArrayOrTypedArray ( v ) ) propOut . set ( v ) ;
36
- else if ( dflt !== undefined ) propOut . set ( dflt ) ;
52
+ var wasSet ;
53
+ if ( isArrayOrTypedArray ( v ) ) {
54
+ propOut . set ( v ) ;
55
+ wasSet = true ;
56
+ } else if ( isPlainObject ( v ) ) {
57
+ var T = typedArrays [ v . dtype ] ;
58
+ if ( T ) {
59
+ propOut . set ( v ) ;
60
+ wasSet = true ;
61
+ }
62
+ }
63
+ if ( ! wasSet && dflt !== undefined ) propOut . set ( dflt ) ;
37
64
}
38
65
} ,
39
66
enumerated : {
0 commit comments