blob: b78261c3df140159d307425b902c61fcdfad9566 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
|
local SpatialAdaptiveMaxPooling, parent = torch.class('nn.SpatialAdaptiveMaxPooling', 'nn.Module')
function SpatialAdaptiveMaxPooling:__init(W, H)
parent.__init(self)
self.W = W
self.H = H
end
function SpatialAdaptiveMaxPooling:updateOutput(input)
self.indices = self.indices or torch.LongTensor()
if torch.typename(input):find('torch%.Cuda.*Tensor') then
self.indices = torch.CudaLongTensor and self.indices:cudaLong() or self.indices
else
self.indices = self.indices:long()
end
input.THNN.SpatialAdaptiveMaxPooling_updateOutput(
input:cdata(),
self.output:cdata(),
self.indices:cdata(),
self.W, self.H
)
return self.output
end
function SpatialAdaptiveMaxPooling:updateGradInput(input, gradOutput)
input.THNN.SpatialAdaptiveMaxPooling_updateGradInput(
input:cdata(),
gradOutput:cdata(),
self.gradInput:cdata(),
self.indices:cdata()
)
return self.gradInput
end
-- for backward compat
function SpatialAdaptiveMaxPooling:empty()
self:clearState()
end
function SpatialAdaptiveMaxPooling:clearState()
if self.indices then
self.indices:set()
end
return parent.clearState(self)
end
|