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
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ndarray/lib/main.js
+27-30
Original file line number
Diff line number
Diff line change
@@ -236,41 +236,38 @@ function array() {
236
236
}else{
237
237
thrownewError('invalid input arguments. Must provide either a data source, array shape, or both.');
238
238
}
239
-
// For non-ndarray 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 solely based on the shape and specified memory layout order...
240
-
if(!FLG){
241
-
strides=shape2strides(shape,order);
242
-
offset=strides2offset(shape,strides);
243
-
}
244
239
// 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...
245
-
if(buffer){
246
-
if(FLG){
247
-
btype=buffer.dtype;
248
-
if(buffer.length!==len){
249
-
thrownewRangeError('invalid input arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
250
-
}
251
-
if(btype!==dtype||opts.copy){
252
-
buffer=copyView(buffer,dtype);
253
-
strides=shape2strides(shape,order);// computed, as we copied elements based on the ndarray view
254
-
offset=strides2offset(shape,strides);
255
-
}else{
256
-
strides=buffer.strides;
257
-
offset=buffer.offset;
258
-
buffer=buffer.data;
259
-
}
240
+
if(FLG){
241
+
btype=buffer.dtype;
242
+
if(buffer.length!==len){
243
+
thrownewRangeError('invalid input arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
244
+
}
245
+
if(btype!==dtype||opts.copy){
246
+
buffer=copyView(buffer,dtype);
247
+
strides=shape2strides(shape,order);
248
+
offset=strides2offset(shape,strides);
260
249
}else{
261
-
btype=getType(buffer);
262
-
if(btype==='generic'&&opts.flatten){
263
-
buffer=flattenArray(buffer);
264
-
}
265
-
if(buffer.length!==len){
266
-
thrownewRangeError('invalid input arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
267
-
}
268
-
if(btype!==dtype||opts.copy){
269
-
buffer=castBuffer(buffer,len,dtype);
270
-
}
250
+
strides=buffer.strides;
251
+
offset=buffer.offset;
252
+
buffer=buffer.data;
253
+
}
254
+
}elseif(buffer){
255
+
btype=getType(buffer);
256
+
if(btype==='generic'&&opts.flatten){
257
+
buffer=flattenArray(buffer);
258
+
}
259
+
if(buffer.length!==len){
260
+
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