aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/lua-torch/nn/HardShrink.lua
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/lua-torch/nn/HardShrink.lua')
-rw-r--r--contrib/lua-torch/nn/HardShrink.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/contrib/lua-torch/nn/HardShrink.lua b/contrib/lua-torch/nn/HardShrink.lua
new file mode 100644
index 000000000..85ff5909c
--- /dev/null
+++ b/contrib/lua-torch/nn/HardShrink.lua
@@ -0,0 +1,25 @@
+local HardShrink, parent = torch.class('nn.HardShrink', 'nn.Module')
+
+function HardShrink:__init(lam)
+ parent.__init(self)
+ self.lambda = lam or 0.5
+end
+
+function HardShrink:updateOutput(input)
+ input.THNN.HardShrink_updateOutput(
+ input:cdata(),
+ self.output:cdata(),
+ self.lambda
+ )
+ return self.output
+end
+
+function HardShrink:updateGradInput(input, gradOutput)
+ input.THNN.HardShrink_updateGradInput(
+ input:cdata(),
+ gradOutput:cdata(),
+ self.gradInput:cdata(),
+ self.lambda
+ )
+ return self.gradInput
+end