Re: [Torch5-devel] torch5 newbie question
Status: Pre-Alpha
Brought to you by:
andresy
From: Ronan C. <ro...@co...> - 2007-12-04 16:20:19
|
> How do you decide whether a class should be a C++ class or a Lua class? If Lua will not slow it down much, do it in Lua. Not only it is faster to program, but it is also more powerful: classes in Lua can use Lua and C++ classes, while classes in C++ can only use C++ classes... When you want to try quickly if an idea works, do it in Lua first as well... if it does not, no need to spend hours to debug your C++ code! > Or why do you have for example in the nn package a > StochasticGradient.lua instead of a StochasticGradient.cpp? StochasticGradient is basically a loop, which makes calls to functions. Not very CPU intensive! So Lua is great for that. It allows StochasticGradient to handle Lua GradientModules, in case you want to quickly (for trying some idea) design some dirty modules. You can also provide it some Lua datasets, which is extremely handy: as long as you have a Lua class which handles :size() and [i] StochasticGradient will handle it as a dataset! > And in the lab package you have a matelem.cpp AND a matelem.lua!? All lab functions use intensively numbers and thus are coded in C++. However, functions like rand() zeros() ... can take both integers like rand(5,2) or a IntStorage as an argument. With integers they have to handle variable numbers of arguments, and that is much easier to handle in Lua than in C++ (as low cost). So this top part is done in Lua, which then calls the underlying C++ function: once again, the CPU intensive part (well, the calculations, numerical stuff) is done in C++, and the rest in Lua. Ronan. |