Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Sqrt.lua - github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c0427b3923b8719e810dbd82d08801686f50e3b (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

local Sqrt, parent = torch.class('nn.Sqrt','nn.Module')

function Sqrt:__init(args)
   parent.__init(self)
   if args then
      error(xlua.usage('nn.Sqrt',
                          'a simple component-wise mapping: sqrt()',
                          'sq = nn.Sqrt()\n'..
                             'sqrt = sq:forward(sometensor)',
                          {type='nil', help='no arg required'}))
   end
end

function Sqrt:forward(input)
   self.output:resizeAs(input):copy(input)
   self.output:sqrt()
   return self.output
end

function Sqrt:backward(input, gradOutput)
   self.gradInput:resizeAs(input):copy(gradOutput)
   self.gradInput:cdiv(self.output):mul(0.5)
   return self.gradInput
end
   

function Sqrt:write(file)
   parent.write(self,file)
end

function Sqrt:read(file)
   parent.read(self,file)
end