Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/nngraph.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Reynolds <mareynolds@google.com>2015-11-20 19:38:55 +0300
committerMalcolm Reynolds <mareynolds@google.com>2015-11-20 19:38:55 +0300
commita7a661df1ddecc620a2e6a53de384b5e8995896a (patch)
tree9829cd593df3d301b4616920aa9d67bc15a6051b
parentf8a3fd2b7b9e413f2e7e0524ff29f2f89e9e2419 (diff)
Fix for Lua 5.2+ which removed table.maxn
-rw-r--r--gmodule.lua4
-rw-r--r--init.lua2
-rw-r--r--utils.lua14
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))
diff --git a/init.lua b/init.lua
index 8b45341..1eae7cb 100644
--- a/init.lua
+++ b/init.lua
@@ -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))
diff --git a/utils.lua b/utils.lua
index e2686f0..1b39607 100644
--- a/utils.lua
+++ b/utils.lua
@@ -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