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-19 20:43:25 +0300
committerMalcolm Reynolds <mareynolds@google.com>2015-11-19 20:43:25 +0300
commitf8a3fd2b7b9e413f2e7e0524ff29f2f89e9e2419 (patch)
tree2c0b361afc064844204f8d232934772d1bfb8e5f /utils.lua
parent233e126b08414b9e4fad022da02c6f3af3225493 (diff)
Make error messages clearer, disallow empty table in inputs.
This is intended to address the common class of errors I see where people make a mistake connecting up their modules, but the error message is either unclear, or doesn't point towards where the mistake actually is. The 'what is this in the input' is now explicit about what the problem is, and if people pass in a nn.Module (meaning they probably forgot a set of parentheses) instead of a nngraph.Node, we say this explicitly. The '1 of split(2) outputs unused' (which previously provided no information about which split was incorrect) now includes file / line number of both the place where the Node was constructed, and the place where :split() was called. Hopefully this should reduce debugging time drastically. Finally, I have disallow passing an empty table as the input connections, ie 'nn.Identity()({})' will error. I cannot see a use case for this (if you have no input connections, just leave the second parens empty). The risk of this is when people do 'nn.Identity()({variableWithTypo})', thinking they have made a connection but actually they haven't. This is likely to cause errors much later on, whereas with this commit it errors straight away. This *could* break existing code, but theres an easy to apply fix that needs to be done at each callsite. Koray has approved this restriction to the API, but I appreciate others may have a view here..
Diffstat (limited to 'utils.lua')
-rw-r--r--utils.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/utils.lua b/utils.lua
index c0bccb2..e2686f0 100644
--- a/utils.lua
+++ b/utils.lua
@@ -8,4 +8,21 @@ function utils.istable(x)
return type(x) == 'table' and not torch.typename(x)
end
+--[[ Returns a useful error message when a nngraph.Node is expected. ]]
+function utils.expectingNodeErrorMessage(badVal, array, idx)
+ if badVal == nil then
+ return string.format('%s[%d] is nil (typo / bad index?)', array, idx)
+ elseif torch.isTypeOf(badVal, 'nn.Module') then
+ local errStr = '%s[%d] is an nn.Module, specifically a %s, but the ' ..
+ 'only valid thing to pass is an instance of ' ..
+ 'nngraph.Node. Did you forget a second set of parens, ' ..
+ 'which convert a nn.Module to a nngraph.Node?'
+ return string.format(errStr, array, idx, torch.typename(badVal))
+ else
+ local errStr = '%s[%d] should be an nngraph.Node but is of type %s'
+ return string.format(errStr, array, idx,
+ torch.typename(badVal) or type(badVal))
+ end
+end
+
return utils