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
out.push(arr.iget(i));// as output buffer is generic, should work with both real- and complex-valued ndarrays
55
-
}
56
-
returnout;
57
-
}
58
-
59
-
/**
60
-
* Copies a "binary" ndarray view.
61
-
*
62
-
* @private
63
-
* @param {ndarray} arr - input ndarray
64
-
* @returns {Array} output data buffer
65
-
*/
66
-
functionbinary(arr){
67
-
varlen;
68
-
varout;
69
-
vari;
70
-
71
-
len=arr.length;
72
-
out=allocUnsafe(len);
73
-
for(i=0;i<len;i++){
74
-
out[i]=arr.iget(i);// we're assuming that we're doing something sensible here (e.g., not trying to cast a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc)
75
-
}
76
-
returnout;
77
-
}
78
-
79
-
/**
80
-
* Copies a "typed" ndarray view.
81
-
*
82
-
* @private
83
-
* @param {ndarray} arr - input ndarray
84
-
* @param {string} dtype - data type
85
-
* @returns {Array} output data buffer
86
-
*/
87
-
functiontyped(arr,dtype){
88
-
varctor;
89
-
varlen;
90
-
varout;
91
-
varset;
92
-
varfcn;
93
-
varo;
94
-
vari;
95
-
96
-
ctor=bufferCtors(dtype);
97
-
len=arr.length;
98
-
out=newctor(len);
99
-
100
-
// If the output data buffer is a complex number array, we need to use accessors...
101
-
o=arraylike2object(out);
102
-
if(o.accessorProtocol){
103
-
set=o.accessors[1];
104
-
fcn=castReturn(wrapper,1,complexCtors(dtype));
105
-
for(i=0;i<len;i++){
106
-
set(out,i,fcn(i));// we're assuming that we're doing something sensible here (e.g., not trying to cast arbitrary objects to complex numbers, etc)
107
-
}
108
-
}else{
109
-
for(i=0;i<len;i++){
110
-
out[i]=arr.iget(i);// we're assuming that we're doing something sensible here (e.g., not trying to cast an ndarray containing generic objects to a double-precision floating-point array or a complex-valued ndarray to a real-valued ndarray, etc)
111
-
}
112
-
}
113
-
returnout;
114
-
115
-
/**
116
-
* Returns the ndarray element specified by a provided linear index.
thrownewError(format('invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.',opts.casting,btype,dtype));
212
212
}
213
213
}elseif(btype){// btype !== void 0
214
214
// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.
215
215
216
216
// Only cast generic array data sources when not provided an ndarray...
217
-
if(!FLG&&btype==='generic'){
217
+
if(!FLG&&isEqualDataType(btype,'generic')){
218
218
dtype=defaults.dtype;
219
219
}else{
220
220
dtype=btype;
@@ -310,7 +310,7 @@ function array() {
310
310
if(numel(buffer.shape)!==len){
311
311
thrownewRangeError('invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
thrownewRangeError('invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
0 commit comments