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

avoid nnNode:label() error for string data #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ function nnNode:label()
elseif istable(data) then
local tstr = {}
for i,v in ipairs(data) do
table.insert(tstr, getstr(v))
local gsv = getstr(v) -- avoids luajit error for type(v)='string'
table.insert(tstr, gsv)
end
return '{' .. table.concat(tstr,',') .. '}'
else
Expand Down
18 changes: 18 additions & 0 deletions test/test_nngraph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,24 @@ function test.test_gradInputType()
checkDotFile(bg_tmpfile)
end

function test.test_table_string_label()
local inp = nn.Identity()()
local in1 = nn.SelectTable(1)(inp)
local in2 = nn.SelectTable(2)(inp)
local out = nn.Linear(10,10)(in1)
-- in2 propagates 'as is': it could be, say, a string debug tag
local mod = nn.gModule({inp}, {out,in2})

local mod_out = mod:forward{
torch.Tensor(10),
"nnNode:label() should handle a string without bad argument #2 to 'insert' (number expected, got string) error"
}
--print('mod_out[1] type is '..torch.type(mod_out[1]))
--print('mod_out[2] type is '..torch.type(mod_out[2])) -- string
local dot0 = mod.fg:todot()
--print(dot0)
end

function test.test_splitMore()
local nSplits = 2
local in1 = nn.Identity()()
Expand Down