torch / tds

Torch C data structures
Other
80 stars 25 forks source link

error with "tostring" method #6

Closed ghostcow closed 8 years ago

ghostcow commented 8 years ago

when printing a tds hash table, torch seems to try and use the "__ipairs" internal method and crashes because that method is not defined in the "hash" object.

when running

tds = require 'tds'
imgs = torch.load('val2014.imgs.tds.t7')
print(imgs)

I get the following error:

/home/lioruzan/torch/install/share/lua/5.1/tds/hash.lua:121: 'struct tds_hash_' has no '__ipairs' metamethod
stack traceback:
    [C]: in function 'pairs'
    /home/lioruzan/torch/install/share/lua/5.1/tds/hash.lua:121: in function 'tostring'
    /home/lioruzan/torch/install/share/lua/5.1/tds/hash.lua:124: in function </home/lioruzan/torch/install/share/lua/5.1/tds/hash.lua:98>
    [C]: in function 'print_old'
    /home/lioruzan/torch/install/share/lua/5.1/env/init.lua:208: in function 'print'
    [string "local f = function() return imgs end; local r..."]:1: in main chunk
    [C]: in function 'xpcall'
    /home/lioruzan/torch/install/share/lua/5.1/itorch/main.lua:179: in function </home/lioruzan/torch/install/share/lua/5.1/itorch/main.lua:143>
    /home/lioruzan/torch/install/share/lua/5.1/lzmq/poller.lua:75: in function 'poll'
    .../lioruzan/torch/install/share/lua/5.1/lzmq/impl/loop.lua:307: in function 'poll'
    .../lioruzan/torch/install/share/lua/5.1/lzmq/impl/loop.lua:325: in function 'sleep_ex'
    .../lioruzan/torch/install/share/lua/5.1/lzmq/impl/loop.lua:370: in function 'start'
    /home/lioruzan/torch/install/share/lua/5.1/itorch/main.lua:350: in main chunk
    [C]: in function 'require'
    [string "arg={'/run/user/1000/jupyter/kernel-95b06e8b-..."]:1: in main chunk

The workaround I found was to just point back to the __pairs function:

tds.hash.__ipairs = tds.hash.__pairs

but this isn't a permanent solution

the code in hash.lua:121 calls 'pairs' (not ipairs). Is there some way the two are connected? I couldn't figure it out.

ghostcow commented 8 years ago

OK, i recreated the bug with a more simple example:

tds = require 'tds'
q = tds.hash()
for i=1,5000 do
    q[i]=torch.Tensor()
end
for i=1,100 do
    print(q)
end

after a few prints this crashes, with the following error:

/home/lioruzan/torch/install/share/lua/5.1/tds/hash.lua:121: 'struct tds_hash_' has no '__ipairs' metamethod
stack traceback:
    [C]: in function 'pairs'
    /home/lioruzan/torch/install/share/lua/5.1/tds/hash.lua:121: in function 'tostring'
    /home/lioruzan/torch/install/share/lua/5.1/trepl/init.lua:251: in function 'rawprint'
    /home/lioruzan/torch/install/share/lua/5.1/trepl/init.lua:283: in function 'print'
    [string "for i=1,100 do..."]:2: in main chunk
    [C]: in function 'xpcall'
    /home/lioruzan/torch/install/share/lua/5.1/trepl/init.lua:663: in function 'repl'
    ...uzan/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
    [C]: at 0x00406670  

this was run in a 'th' console on ubuntu 14.04.

I tried looking into the call stack but I couldn't find anything. why does 'struct tdshash' even show up in lua? isn't this supposed to be a 'hash' object?

andresy commented 8 years ago

cannot reproduce the bug. i guess you have a screwed up version of tds installed there, as ipairs should not be called on tds.Hash.

are you using lua or luajit? which version?

ghostcow commented 8 years ago

LuaJIT 2.1.0-alpha.

Just to be on the safe side, I ran

./upgrade.sh
./install.sh
luarocks install tds

waited till everything was updated and compiled, bug was still there.

more info about my system:

lioruzan@pc-lior:~/torch$ uname -a
Linux pc-lior 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Also worth noting that I recreated the bug on another system with a similar setup, but since I can't remember if I updated everything there too I'll focus on this computer only.

soumith commented 8 years ago

Hmmm, I reproduced the bug as well on my Ubuntu system.

soumith commented 8 years ago

It looks like a luajit bug. Maybe it's fixed in luajit 2.1 final release I have to check.

For example with JIT off, it runs smoothly:

luajit -joff bug.lua

ghostcow commented 8 years ago

Thanks Soumith!

If I don't use the ffi interface, will I break anything if I turn off LuaJIT?

soumith commented 8 years ago

@ghostcow no you wont break anything if you turn off jit (you can use FFI too)

andresy commented 8 years ago

thanks @soumith it was indeed a luajit bug updated luajit (in luajit-rocks repo) to last version

geoparser commented 8 years ago

how to update luajit again?

soumith commented 8 years ago

@geoparser you'll have to reinstall torch by: cd ~/torch ./clean.sh git pull ./install.sh

geoparser commented 8 years ago

thanks!