diff options
Diffstat (limited to 'contrib/lua-torch/nn/Log.lua')
-rw-r--r-- | contrib/lua-torch/nn/Log.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/lua-torch/nn/Log.lua b/contrib/lua-torch/nn/Log.lua new file mode 100644 index 000000000..e8f236bfb --- /dev/null +++ b/contrib/lua-torch/nn/Log.lua @@ -0,0 +1,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 |