-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplicate.lua
More file actions
29 lines (26 loc) · 757 Bytes
/
Replicate.lua
File metadata and controls
29 lines (26 loc) · 757 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
local Replicate, parent = torch.class('nn.Replicate','nn.Module')
function Replicate:__init(nf)
parent.__init(self)
self.nfeatures = nf
end
function Replicate:updateOutput(input)
local sz = torch.LongStorage(input:dim()+1)
sz[1] = self.nfeatures
for i = 1,input:dim() do
sz[i+1] = input:size(i)
end
local st = torch.LongStorage(input:dim()+1)
st[1] = 0
for i = 1,input:dim() do
st[i+1] = input:stride(i)
end
self.output = input.new(input:storage(),input:storageOffset(),sz,st)
return self.output
end
function Replicate:updateGradInput(input, gradOutput)
self.gradInput:resizeAs(input):zero()
for k = 1,gradOutput:size(1) do
self.gradInput:add(gradOutput[k])
end
return self.gradInput
end