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

Square.lua - github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30e8cb9f74aee5853e60fe911ab6537c0d1ed228 (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
local Square, parent = torch.class('nn.Square','nn.Module')

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

function Square:forward(input)
   self.output:resizeAs(input):copy(input)
   self.output:cmul(input)
   return self.output
end

function Square:backward(input, gradOutput)
   self.gradInput:resizeAs(input):copy(gradOutput)
   self.gradInput:cmul(input):mul(2)
   return self.gradInput
end
   

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

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