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:
Diffstat (limited to 'ZeroGrad.lua')
-rw-r--r--ZeroGrad.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/ZeroGrad.lua b/ZeroGrad.lua
new file mode 100644
index 0000000..7c941ce
--- /dev/null
+++ b/ZeroGrad.lua
@@ -0,0 +1,14 @@
+local ZeroGrad, parent = torch.class('nn.ZeroGrad', 'nn.Module')
+
+function ZeroGrad:updateOutput(input)
+ self.output:set(input)
+ return self.output
+end
+
+-- the gradient is simply zeroed.
+-- useful when you don't want to backpropgate through certain paths.
+function ZeroGrad:updateGradInput(input, gradOutput)
+ self.gradInput = nn.utils.recursiveResizeAs(self.gradInput, input)
+ self.gradInput = nn.utils.recursiveFill(self.gradInput, 0)
+ return self.gradInput
+end