@@ -18,22 +18,49 @@ var DESELECTDIM = require('../constants/interactions').DESELECTDIM;
1818var nestedProperty = require ( './nested_property' ) ;
1919var counterRegex = require ( './regex' ) . counter ;
2020var modHalf = require ( './mod' ) . modHalf ;
21+ var isPlainObject = require ( './is_plain_object' ) ;
2122var isArrayOrTypedArray = require ( './array' ) . isArrayOrTypedArray ;
2223
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+
2338exports . valObjectMeta = {
2439 data_array : {
2540 // You can use *dflt=[] to force said array to exist though.
2641 description : [
2742 '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.'
3048 ] . join ( ' ' ) ,
3149 requiredOpts : [ ] ,
3250 otherOpts : [ 'dflt' ] ,
3351 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 ) ;
3764 }
3865 } ,
3966 enumerated : {
0 commit comments