diff options
-rw-r--r-- | gmodule.lua | 4 | ||||
-rw-r--r-- | init.lua | 2 | ||||
-rw-r--r-- | utils.lua | 14 |
3 files changed, 17 insertions, 3 deletions
diff --git a/gmodule.lua b/gmodule.lua index 65cf047..99698c0 100644 --- a/gmodule.lua +++ b/gmodule.lua @@ -49,14 +49,14 @@ function gModule:__init(inputs,outputs) -- input point for the backward graph local node local outnode = nngraph.Node({input={}}) - for i = 1, table.maxn(outputs) do + for i = 1, utils.tableMaxN(outputs) do node = outputs[i] if torch.typename(node) ~= 'nngraph.Node' then error(utils.expectingNodeErrorMessage(node, 'outputs', i)) end outnode:add(node, true) end - for i = 1, table.maxn(inputs) do + for i = 1, utils.tableMaxN(inputs) do node = inputs[i] if torch.typename(node) ~= 'nngraph.Node' then error(utils.expectingNodeErrorMessage(node, 'inputs', i)) @@ -41,7 +41,7 @@ function Module:__call__(...) local mnode = nngraph.Node({module=self}) local dnode - for i = 1, table.maxn(input) do + for i = 1, utils.tableMaxN(input) do dnode = input[i] if torch.typename(dnode) ~= 'nngraph.Node' then error(utils.expectingNodeErrorMessage(dnode, 'inputs', i)) @@ -25,4 +25,18 @@ function utils.expectingNodeErrorMessage(badVal, array, idx) end end +--[[ Lua 5.2+ removed table.maxn, provide fallback implementation. ]] +if table.maxn then + utils.tableMaxN = table.maxn +else + function utils.tableMaxN(tbl) + local max = 0 + for k, v in pairs(tbl) do + if type(k) == 'number' and k > max then + max = k + end + end + return max + end + end return utils |