Expand file tree
/
Copy pathCAddTable.lua
More file actions
Latest commit
36 lines (31 loc) · 824 Bytes
/
Copy pathCAddTable.lua
File metadata and controls
36 lines (31 loc) · 824 Bytes
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
localCAddTable, parent=torch.class('nn.CAddTable', 'nn.Module')
functionCAddTable:__init(ip)
parent.__init(self)
self.inplace=ip
self.gradInput= {}
end
functionCAddTable:updateOutput(input)
ifself.inplacethen
self.output:set(input[1])
else
self.output:resizeAs(input[1]):copy(input[1])
end
fori=2,#inputdo
self.output:add(input[i])
end
returnself.output
end
functionCAddTable:updateGradInput(input, gradOutput)
fori=1,#inputdo
self.gradInput[i] =self.gradInput[i] orinput[1].new()
ifself.inplacethen
self.gradInput[i]:set(gradOutput)
else
self.gradInput[i]:resizeAs(input[i]):copy(gradOutput)
end
end
fori=#input+1, #self.gradInputdo
self.gradInput[i] =nil
end
returnself.gradInput
end