torch / torch7

http://torch.ch
Other
8.97k stars 2.38k forks source link

Newly Implemented Operation not Available in Torch after Building and Installing #976

Open davidstutz opened 7 years ago

davidstutz commented 7 years ago

Hi,

I am trying to add new operations to Torch tensors. I looked at several pull requests (.e.g here) to learn how to integrate new operations. So let's assume I want to add a signtest function which simply copies sign. So I adapt the corresponding files, i.e. I add void THTensor_(signtest)(THTensor *r_, THTensor *t) in THTensorMath.h and implement it in THTensorMath.c. Then I adapt TensorMath.lua by copying the ẁrap entry for sign:

wrap("signtest",
    cname("signtest"),
    {{name=Tensor, default=true, returned=true, method={default='nil'}},
     {name=Tensor, method={default=1}}})

I go to build/ and do make and make install. I see that the corresponding libraries are correctly updated. Confirming using nm shows that the shared object files include the added operation:

00000000000c61e0 T THFloatTensor_signtest

in both libtorch.so and libTH.so. Everything seems fine. To be sure I restart the console, run th and see that torch.signtest is nil.

I installed Torch using torch/distro. The above can be reproduced when I completely reinstall Torch (using the distro) and making these changes before the new installation. It is the same when implementing new operations or renaming/copying/removing other operations.

I guess that I am missing a crucial step when building and installing Torch. But where is my error? Help is really appreciated! Thanks.

soumith commented 7 years ago

@davidstutz the last part is wrong, i.e. "build" and "make / make install". You need to do: luarocks make rocks/torch-scm-1.rockspec

The rest of what you described seems correct.

davidstutz commented 7 years ago

That didn't work either. Tried it before resorting to CMake and doing make and make install and inspecting the generated libraries. Actually, I started by following your post in the Google group.

Essentially the luarocks make command only invokes CMake, make and make install, right?