mylib =require('mylib')
obj = mylib.new()
data = torch.DoubleTensor({1,2,3,4})
obj:setdata(data)
--stores [1,2,3,4] in the back-end C++ object
obj:getdata()
--prints [1,2,3,4]--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+unsubscribe@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at https://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.
luaT API does the job but perhaps using FFI is much simpler to use
On Sun, Aug 21, 2016 at 12:50 PM, Marc via torch7 <torch7+APn2wQdnymDJozVf8_V0EtywE2hwOHxh0LaHwrQ2ReSJTZnRirA-...@googlegroups.com> wrote:
I am binding C (and C++) code to Lua 5.2. I have been able to pass primitives back and forth no problem with the Lua 5.2 C API. However, I've struggled to figure out how to pass a Torch Tensor (like torch.DoubleTensor({1,2,3,4})) to my C program in order to operate on the data.For example, my wrapped class now allows something likemylib =require('mylib')
obj = mylib.new()
I would like to be able to have functions like setdata(data) and getdata() as follows.data = torch.DoubleTensor({1,2,3,4})
obj:setdata(data)
--stores [1,2,3,4] in the back-end C++ object
obj:getdata()
--prints [1,2,3,4]
I know how to write the functions and make them work, but it's the passage of Tensors that I can't seem to figure out. I suspect luaT_checkudata(...) from Torch7's luaT API might be the right tool, but I can't figure it out. Can someone provide a simple example as to how to access the underlying array of a Torch Tensor in C?Thanks!
--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+un...@googlegroups.com.
Hi,You can use luaT functions to get the elements in C with:Here is a small example how to get the arguments from the stack to C objects https://github.com/albanD/c-in-lua/blob/refacto/cModule/src.c#L14-L26
You can then use https://github.com/torch/torch7/tree/master/lib/luaT#void-luat_pushudatalua_state-l-void-udata-const-char-tname to return a tensor.
On Sunday, August 21, 2016 at 11:30:08 PM UTC+1, Marc wrote:
I'll keep that in mind, but I have already done a fair bit of work using the Lua C APIs and I'd like to finish in that realm. Do you have a solution to the OP?
On Sunday, August 21, 2016 at 4:09:37 PM UTC-4, Jonghoon Jin wrote:
luaT API does the job but perhaps using FFI is much simpler to use