summaryrefslogtreecommitdiffstats
path: root/contrib/lua-torch/nn/Log.lua
blob: e8f236bfb79cf524aa02bef8e2da9ce9844bbe27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local Log, parent = torch.class('nn.Log', 'nn.Module')

function Log:__init()
   parent.__init(self)
end

function Log:updateOutput(input)
   self.output:resizeAs(input)
   self.output:copy(input)
   self.output:log()
   return self.output
end

function Log:updateGradInput(input, gradOutput)
   self.gradInput:resizeAs(input)
   self.gradInput:fill(1)
   self.gradInput:cdiv(input)
   self.gradInput:cmul(gradOutput)
   return self.gradInput
end