Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

"failed to parse generated code." #114

Open
tuananhle7 opened this issue Apr 29, 2016 · 1 comment
Open

"failed to parse generated code." #114

tuananhle7 opened this issue Apr 29, 2016 · 1 comment

Comments

@tuananhle7
Copy link

Running the following:

grad = require 'autograd'
params = {
    [":a1"] = 1,
    [":a2"] = 2
}
f = function(params, x)
    val = x["value"]
    w = params[x["address"].raw]
    return w * val
end
df = grad(f, {optimize = true})
x = {value = 47, address = ":a1"}
dparam, loss = df(params, x)

produces

return function(locals, rlocals, vlocals)
local nn = require('autograd').nn
local util = require('autograd.util')
return function(p1, p2)
    locals[1] = p2.value * 1
    locals[2] = p1.:a1 * p2.value
    return {
        :a1 = locals[1],
    }, locals[2]
end
end

[string "return function(locals, rlocals, vlocals)..."]:6: '<name>' expected near ':'
/Users/username/torch/install/bin/luajit: ...re/lua/5.1/autograd/runtime/codegen/backend/lua/init.lua:757: failed to parse generated code.
stack traceback:
    [C]: in function 'error'
    ...re/lua/5.1/autograd/runtime/codegen/backend/lua/init.lua:757: in function 'generateFn'
    .../install/share/lua/5.1/autograd/runtime/codegen/init.lua:140: in function 'df'
    test2.lua:25: in main chunk
    [C]: in function 'dofile'
    ...nhle/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x010c506bc0

while running

grad = require 'autograd'
params = {
    ["a1"] = 1,
    ["a2"] = 2
}
f = function(params, x)
    val = x["value"]
    w = params[x["address"].raw]
    return w * val
end
df = grad(f, {optimize = true})
x = {value = 47, address = "a1"}
dparam, loss = df(params, x)

doesn't.

In the first case, keys of params are strings that start with a colon while in the second they don't.

@alexbw
Copy link
Collaborator

alexbw commented Apr 29, 2016

Hrm, seems like we should be doing table lookups using brackets, and not dot, syntax.

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

No branches or pull requests

2 participants