torch / tds

Torch C data structures
Other
80 stars 25 forks source link

[bug] can not get tensor element properly, always get ByteTensor #27

Closed BTNC closed 7 years ago

BTNC commented 7 years ago

Hi,

In elem.lua line 14, ctypes' getfunc is indexed by its free function address. In elem.lua line 101, different tensor types' getfunc are indexed by their free function address. However, their free function address are same, as a result different tensor types will have the same getfunc as THByteTensor. In line 122, the upvalue "tensor_type_id" is torch.ByteTensor, so the returned tensor is always ByteTensor.

> a = tds.hash()
> a[1] = torch.rand(5)
> print(a)
tds.Hash[1]{
1 :    0
       0
     128
     125
     216
    [torch.ByteTensor of size 5]

}
> b = tds.vec(3, 5, torch.ones(3), 9)
> print(b)
tds.Vec[4]{
    1 : 3
    2 : 5
    3 :  0
         0
         0
        [torch.ByteTensor of size 3]

    4 : 9
}

Thanks,