htwaijry / npy4th

Numpy format for Torch
Other
68 stars 8 forks source link

Wrong row/column majoring #2

Closed joeyhng closed 8 years ago

joeyhng commented 9 years ago

The row/column major is wrong for this file: https://drive.google.com/file/d/0B0ndkyl_LuI0MXpjTnBQeUtOM0k/view

Using npy4th:

th> npy4th = require 'npy4th'
                                                                      [0.0002s]
th> c = npy4th.loadnpy('fail.npy')
                                                                      [0.0017s]
th> c[{{1, 4}, {1, 4}}]
 8.7540  8.7540  1.3647 -0.2838
 0.6793  0.5285  1.8224  1.1073
 1.1149  1.7027  1.5232  1.3419
 1.7833  2.0152 -0.3040 -1.1487
[torch.FloatTensor of size 4x4]

Using Python:

In [1]: import numpy as np

In [2]: c = np.load('fail.npy')

In [3]: c[0:4,0:4]
Out[3]: 
array([[  8.75396729,  10.97304058, -13.58637428,  -9.8517437 ],
       [  8.75396729,  10.97304058, -13.58637428,  -9.8517437 ],
       [  1.36473918,   1.95315695,  -3.34651899,   4.10217953],
       [ -0.28375456,   1.34132934,  -2.27433491,   5.4811039 ]], dtype=float32)
joeyhng commented 9 years ago

This issue seems to occur when the npy file has fortran order.

htwaijry commented 8 years ago

I put in a quick fix for that .. thanks for finding it out!