nicolaspanel / numjs

Like NumPy, in JavaScript
MIT License
2.4k stars 184 forks source link

Error when reshaping array #112

Open fullmetalfelix opened 2 years ago

fullmetalfelix commented 2 years ago

Hi,

I found some erratic behaviour when using the reshape method. Basically I parse 3D data out of a binary file and got a 4x512x512 tensor. I then slice it into 4 matrixes 512x512, but the slice function actually returns a 1x512x512 for each slice. I then use reshape on each one to get the data as 2D matrixes.

Here is the debug output, showing the data shape after each operation/iteration:

extracting trace forward/up 0 fluid.spm.js:2970:10 data after scan slice Array(3) [ 1, 512, 512 ] data after reshape Array [ 512, 512 ]

extracting trace backward/up 1 fluid.spm.js:2970:10 data after scan slice Array(3) [ 1, 512, 512 ] data after reshape Array [ 512, 512 ]

extracting trace forward/down 2 fluid.spm.js:2970:10 data after scan slice Array(3) [ 1, 512, 512 ]

The first two are reshaped, the last is apparently sliced correctly but gives an error on reshape:

Uncaught TypeError: array is undefined baseFlatten http://localhost:5000/static/js/numjs.js:24812 baseFlatten http://localhost:5000/static/js/numjs.js:24820 baseFlatten http://localhost:5000/static/js/numjs.js:24820 baseFlatten http://localhost:5000/static/js/numjs.js:24820 flatten http://localhost:5000/static/js/numjs.js:23957 reshape http://localhost:5000/static/js/numjs.js:24042

I also checked the actual tensors after slicing and indeed they appear all fine. Any idea why this happened?