forked from torch/nn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CAddTable.lua
36 lines (31 loc) · 824 Bytes
/
CAddTable.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local CAddTable, parent = torch.class('nn.CAddTable', 'nn.Module')
function CAddTable:__init(ip)
parent.__init(self)
self.inplace = ip
self.gradInput = {}
end
function CAddTable:updateOutput(input)
if self.inplace then
self.output:set(input[1])
else
self.output:resizeAs(input[1]):copy(input[1])
end
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 input[1].new()
if self.inplace then
self.gradInput[i]:set(gradOutput)
else
self.gradInput[i]:resizeAs(input[i]):copy(gradOutput)
end
end
for i=#input+1, #self.gradInput do
self.gradInput[i] = nil
end
return self.gradInput
end