aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/lua-torch/nn/Sqrt.lua
blob: df354a1754f1537750d22fe4ae7bff82f8848ace (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
local Sqrt, parent = torch.class('nn.Sqrt','nn.Module')

function Sqrt:__init(b)
   parent.__init(self)
   self.eps = b or 0
end

function Sqrt:updateOutput(input)
   self.eps = self.eps or 0
   input.THNN.Sqrt_updateOutput(
      input:cdata(),
      self.output:cdata(),
      self.eps
   )
   return self.output
end

function Sqrt:updateGradInput(input, gradOutput)
   input.THNN.Sqrt_updateGradInput(
      input:cdata(),
      gradOutput:cdata(),
      self.gradInput:cdata(),
      self.output:cdata()
   )
   return self.gradInput
end