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
@@ -49,7 +50,7 @@ var castBuffer = require( './cast_buffer.js' );
49
50
* @param {Options} [options] - function options
50
51
* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source
51
52
* @param {string} [options.dtype="float64"] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data)
52
-
* @param {string} [options.order="row-major"] - specifies whether an array should be row-major (C-style) or column-major (Fortran-style)
53
+
* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style)
// If the user indicated that "any" order suffices (meaning the user does not care about ndarray order), then we default to the default order, unless the input ndarray is unequivocally either "row-major" or "column-major"....
152
+
if(order==='any'){
153
+
ord=strides2order(buffer.strides);
154
+
if(ord==='column-major'){
155
+
order=ord;
156
+
}elseif(ord==='row-major'){
157
+
order=ord;
158
+
}else{
159
+
order=defaults.order;
160
+
}
161
+
}
162
+
// If the user indicated to keep the same order, then TODO...
163
+
elseif(order==='same'){
164
+
165
+
}
166
+
}else{
167
+
order=defaults.order;
168
+
}
169
+
}elseif(!isOrder(order)){
148
170
thrownewTypeError('invalid option. `order` option must be a recognized order. Option: `'+order+'`.');
149
171
}
150
172
}else{
@@ -212,27 +234,48 @@ function array() {
212
234
}else{
213
235
thrownewError('invalid input arguments. Must provide either a data source, array shape, or both.');
214
236
}
215
-
// TODO: if provided an ndarray, determine order
216
-
217
-
// Compute the array strides:
218
-
strides=shape2strides(shape,order);
219
-
220
-
// Determine the index offset (i.e., the pointer to the first array element):
221
-
offset=strides2offset(shape,strides);
237
+
// If provided an ndarray, we need to take special care to ensure we determine the correct order...
238
+
if(FLG){
239
+
// If we are not copying the ndarray buffer, then we are simply creating another ndarray wrapper around the same underlying buffer...
240
+
if(opts.copy===false){
241
+
strides=buffer.strides;
242
+
offset=buffer.offset;
243
+
order=buffer.order;
244
+
}
245
+
// If we are copying the ndarray buffer, then we need to perform some analysis to determine order of the output ndarray...
246
+
else{
222
247
248
+
}
249
+
}
250
+
// For all other data source inputs, we assume we've been provided a contiguous data source for which we can simply compute the strides and index offset pointing to the first indexed element...
251
+
else{
252
+
strides=shape2strides(shape,order);
253
+
offset=strides2offset(shape,strides);
254
+
}
223
255
// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...
224
256
if(buffer){
225
257
// TODO: determine how to handle ndarray data sources (for non-copy, we need to compute strides based on the order taking into account that a provided ndarray may have "scrambled" strides; for copy, we need to "pluck" the values from the ndarray buffer)
226
258
227
-
btype=getType(buffer);
228
-
if(btype==='generic'&&opts.flatten){
229
-
buffer=flattenArray(buffer);
230
-
}
231
-
if(btype!==dtype||opts.copy){
232
-
if(buffer.length<len){
233
-
thrownewRangeError('invalid input arguments. Array shape is incompatible with provided data source. To accommodate the requested shape, provide a bigger data source.');
259
+
if(FLG){
260
+
if(buffer.length!==len){
261
+
thrownewRangeError('invalid input arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
262
+
}
263
+
if(opts.copy){
264
+
// TODO: pluck data
265
+
}else{
266
+
buffer=buffer.data;
267
+
}
268
+
}else{
269
+
btype=getType(buffer);
270
+
if(btype==='generic'&&opts.flatten){
271
+
buffer=flattenArray(buffer);
272
+
}
273
+
if(buffer.length!==len){
274
+
thrownewRangeError('invalid input arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
0 commit comments