You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -52,12 +55,14 @@ var errMessage = require( './error_message.js' );
52
55
functionsetElements(target,property,value,ctx){
53
56
varidx;
54
57
varerr;
58
+
vardt;
55
59
varv;
56
60
57
61
idx=prop2array(property,ctx.cache);
58
62
if(isCollection(value)){
59
63
// When handling collections, we delegate to implementation APIs (see below) to perform argument validation (e.g., ensuring a (mostly) safe cast, broadcast compatibility, etc), so we just reassign the value here:
60
64
v=value;
65
+
dt=dtype(value)||'generic';
61
66
}else{
62
67
// When provided a "scalar", we need to check whether the value can be safely cast to the target array data type:
// As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during assignment:
73
78
v=scalar2array(v,ctx.dtype);
79
+
dt=ctx.dtype;
74
80
}
75
81
if(idx.type==='int'){
76
82
try{
77
-
put(target,idx.data,v);
83
+
put(target,idx.data,v);// note: defer to `put` for ensuring a mostly safe cast
78
84
}catch(err){
79
85
thrownewerr.constructor(errMessage(err.message));
80
86
}
81
87
returntrue;
82
88
}
89
+
// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the target array data type is floating-point...
90
+
if(!isMostlySafeCast(dt,ctx.dtype)){
91
+
thrownewTypeError(format('invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].',dt,ctx.dtype));
92
+
}
83
93
if(idx.type==='bool'){
84
-
// FIXME: where( idx.data, target, value );
85
-
returnfalse;
94
+
where(idx.data,v,target,target,1,0);
95
+
returntrue;
86
96
}
87
97
if(idx.type==='mask'){
88
-
// FIXME: where( idx.data, value, target );
89
-
returnfalse;
98
+
where(idx.data,target,v,target,1,0);
99
+
returntrue;
90
100
}
91
101
thrownewError(format('invalid operation. Unrecognized array index type. Value: `%s`.',idx.type));
0 commit comments