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

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

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

function CDivTable:__init()
   parent.__init(self)
   self.gradInput = {}
end

function CDivTable:forward(input)
   self.output:resizeAs(input[1]):copy(input[1])
   self.output:cdiv(input[2])
   return self.output
end

function CDivTable:backward(input, gradOutput)
   self.gradInput[1] = self.gradInput[1] or torch.Tensor()
   self.gradInput[2] = self.gradInput[2] or torch.Tensor()
   self.gradInput[1]:resizeAs(input[1]):copy(gradOutput):cdiv(input[2])
   self.gradInput[2]:resizeAs(input[2]):zero():addcdiv(-1,self.gradInput[1],input[2]):cmul(input[1])
   return self.gradInput
end

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

function CDivTable:read(file)
   parent.read(self, file)
   self.gradInput = {}
end