blob: 9603b4ba10c270e7c41658f8816c169af479973e (
plain)
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
|
local CAddTable, parent = torch.class('nn.CAddTable', 'nn.Module')
function CAddTable:__init()
parent.__init(self)
self.gradInput = {}
end
function CAddTable:forward(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:backward(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
function CAddTable:write(file)
parent.write(self, file)
end
function CAddTable:read(file)
parent.read(self, file)
self.gradInput = {}
end
|