aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-23 18:14:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-23 18:14:15 +0100
commit714eb56e1760fdfb26afccde92664d3a2f1e8435 (patch)
tree84d1399acbb92f852b4bd64f9ea5412680b0c6ab /contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua
parent220a51ff68013dd668a45b78c60a7b8bfc10f074 (diff)
downloadrspamd-714eb56e1760fdfb26afccde92664d3a2f1e8435.tar.gz
rspamd-714eb56e1760fdfb26afccde92664d3a2f1e8435.zip
[Minor] Move lua contrib libraries to lua- prefix
Diffstat (limited to 'contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua')
-rw-r--r--contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua b/contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua
new file mode 100644
index 000000000..b78261c3d
--- /dev/null
+++ b/contrib/lua-torch/nn/SpatialAdaptiveMaxPooling.lua
@@ -0,0 +1,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