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:
authorSoumith Chintala <soumith@gmail.com>2016-01-26 00:48:15 +0300
committerSoumith Chintala <soumith@gmail.com>2016-01-26 00:48:15 +0300
commitc3f2c36fb90ddf0a8988c7bf0a3ad97e09132a95 (patch)
treee1545897f1875bb19fe9f96b9922df15873f0852 /CAddTable.lua
parentb3acec112122eec76c7073e034486ab1c7c9e73b (diff)
Revert "In-place option for CAddTable"
Diffstat (limited to 'CAddTable.lua')
-rw-r--r--CAddTable.lua24
1 files changed, 11 insertions, 13 deletions
diff --git a/CAddTable.lua b/CAddTable.lua
index 40caead..42e77fd 100644
--- a/CAddTable.lua
+++ b/CAddTable.lua
@@ -1,17 +1,13 @@
+
local CAddTable, parent = torch.class('nn.CAddTable', 'nn.Module')
-function CAddTable:__init(ip)
+function CAddTable:__init()
parent.__init(self)
- self.inplace = ip
self.gradInput = {}
end
function CAddTable:updateOutput(input)
- if self.inplace then
- self.output = input[1]
- else
- self.output:resizeAs(input[1]):copy(input[1])
- end
+ self.output:resizeAs(input[1]):copy(input[1])
for i=2,#input do
self.output:add(input[i])
end
@@ -20,12 +16,14 @@ end
function CAddTable:updateGradInput(input, gradOutput)
for i=1,#input do
- if self.inplace then
- self.gradInput[i] = gradOutput
- else
- self.gradInput[i] = self.gradInput[i] or input[1].new()
- self.gradInput[i]:resizeAs(gradOutput):copy(gradOutput)
- end
+ self.gradInput[i] = self.gradInput[i] or input[1].new()
+ self.gradInput[i]:resizeAs(input[i])
+ self.gradInput[i]:copy(gradOutput)
end
+
+ for i=#input+1, #self.gradInput do
+ self.gradInput[i] = nil
+ end
+
return self.gradInput
end