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.get(i));// FIXME: what if `arr` has more than one dimensions?
54
+
out.push(arr.iget(i));// as output buffer is generic, should work with both real- and complex-valued ndarrays
45
55
}
46
56
returnout;
47
57
}
@@ -61,7 +71,7 @@ function binary( arr ) {
61
71
len=arr.length;
62
72
out=allocUnsafe(len);
63
73
for(i=0;i<len;i++){
64
-
out[i]=arr.get(i);// FIXME: what if `arr` has more than one dimensions?
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)
65
75
}
66
76
returnout;
67
77
}
@@ -78,15 +88,40 @@ function typed( arr, dtype ) {
78
88
varctor;
79
89
varlen;
80
90
varout;
91
+
varset;
92
+
varfcn;
93
+
varo;
81
94
vari;
82
95
83
96
ctor=bufferCtors(dtype);
84
97
len=arr.length;
85
-
out=newctor(len);// FIXME: need to account for complex number arrays; in which case, we may want to do something similar to `array/convert`
86
-
for(i=0;i<len;i++){
87
-
out[i]=arr.get(i);// FIXME: what if `arr` has more than one dimensions?
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
+
}
88
112
}
89
113
returnout;
114
+
115
+
/**
116
+
* Returns the ndarray element specified by a provided linear index.
117
+
*
118
+
* @private
119
+
* @param {NonNegativeInteger} i - linear index
120
+
* @returns {*} value
121
+
*/
122
+
functionwrapper(i){
123
+
returnarr.iget(i);
124
+
}
90
125
}
91
126
92
127
@@ -112,14 +147,18 @@ function typed( arr, dtype ) {
112
147
* // returns <Float64Array>[ 3.0, 2.0, 1.0 ]
113
148
*/
114
149
functioncopyView(arr,dtype){
115
-
// TODO: handle complex number dtypes!!
150
+
varx;
151
+
152
+
// Create a new "base" view, thus ensuring we have an `.iget` method and associated meta data...
0 commit comments