diff options
Diffstat (limited to 'CAddTable.lua')
-rw-r--r-- | CAddTable.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/CAddTable.lua b/CAddTable.lua new file mode 100644 index 0000000..afe3568 --- /dev/null +++ b/CAddTable.lua @@ -0,0 +1,24 @@ + +local CAddTable, parent = torch.class('nn.CAddTable', 'nn.Module') + +function CAddTable:__init() + parent.__init(self) + self.gradInput = {} +end + +function CAddTable:updateOutput(input) + self.output:resizeAs(input[1]):copy(input[1]) + for i=2,#input do + self.output:add(input[i]) + end + return self.output +end + +function CAddTable:updateGradInput(input, gradOutput) + for i=1,#input do + self.gradInput[i] = self.gradInput[i] or torch.Tensor() + self.gradInput[i]:resizeAs(input[i]) + self.gradInput[i]:copy(gradOutput) + end + return self.gradInput +end |