Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing arguments to a lua file in torch-android #67

Open
kk291 opened this issue Jun 29, 2016 · 2 comments
Open

Passing arguments to a lua file in torch-android #67

kk291 opened this issue Jun 29, 2016 · 2 comments

Comments

@kk291
Copy link

kk291 commented Jun 29, 2016

Hi,

How are we supposed to pass arguments to a lua file in torch-android?

@borisfom
Copy link
Collaborator

This is very confusing question. What exactly are you trying to achieve ?

@paramsen
Copy link
Contributor

paramsen commented Mar 10, 2017

This is actually a question regarding Torch and Lua, rather than TorchAndroid. As I understand the question @kk291 wants to know how one can pass for instance a vector (or tensor) to a Torch -script/Lua -script, in AndroidTorch.

Expecting that you have succeeded to add the compiled TorchAndroid .so/.h files to your Android project you can proceed with the following steps. The links refer to relevant lines in the bundled demo source.

  1. Create a C or C++ class that handles your integration with TorchAndroid
    1.1) Create necessary initialization/destruction code for TorchAndroid
  2. Create a function in this class that can push a Tensor (or data of arbitrary kind) to TorchAndroid [i.e. your lua -file] and read the result

Here's the relevant lines invoking a function in the Lua -script with a Tensor argument:

lua_getglobal(L, "getTopOnly");
luaT_pushudata(L, testTensor, "torch.DoubleTensor");
if (lua_pcall(L, 1, 1, 0) != 0)
    //error, retreive error
else
    //success, retreive result

One needs to know that the C Lua api is stack based, meaning you interact with the Lua inerpreter as you do with a stack, refer to the links to see how.

This is not strictly related to TorchAndroid, but just the C/C++ Lua api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants