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

github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Zagoruyko <zagoruyko2@gmail.com>2016-02-04 17:53:04 +0300
committerSergey Zagoruyko <zagoruyko2@gmail.com>2016-02-09 21:08:41 +0300
commitb4ebdf2f95ee9f1429825a0d7b0948721e407d82 (patch)
tree77b6183d0c258d07d5f5e6338c48ccb5fc5a877b /Identity.lua
parent4a433463fcd17c4ec3242586da7e9fc859feb3ae (diff)
nn.clearState
Diffstat (limited to 'Identity.lua')
-rw-r--r--Identity.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/Identity.lua b/Identity.lua
index 088cc34..5e6ccb6 100644
--- a/Identity.lua
+++ b/Identity.lua
@@ -10,3 +10,21 @@ function Identity:updateGradInput(input, gradOutput)
self.gradInput = gradOutput
return self.gradInput
end
+
+function Identity:clearState()
+ -- don't call set because it might reset referenced tensors
+ local function clear(f)
+ if self[f] then
+ if torch.isTensor(self[f]) then
+ self[f] = self[f].new()
+ elseif type(self[f]) == 'table' then
+ self[f] = {}
+ else
+ self[f] = nil
+ end
+ end
+ end
+ clear('output')
+ clear('gradInput')
+ return self
+end