diff options
author | koray kavukcuoglu <koray@kavukcuoglu.org> | 2013-03-19 20:31:41 +0400 |
---|---|---|
committer | koray kavukcuoglu <koray@kavukcuoglu.org> | 2013-03-19 20:31:41 +0400 |
commit | 1e6fe1c4194d16c8245642f46454ce27c9cec48a (patch) | |
tree | 685f684e2c61c284b339e604dbd774bfa74edf66 /CMulTable.lua | |
parent | edf13338e79ec336b5d5fb0b7f95fc8864f747cc (diff) |
CMulTable updateGradInput now uses proper but slow gradient calculation. The old one is available in updateGradInput_efficient function.
Diffstat (limited to 'CMulTable.lua')
-rw-r--r-- | CMulTable.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/CMulTable.lua b/CMulTable.lua index f82776b..0e327be 100644 --- a/CMulTable.lua +++ b/CMulTable.lua @@ -14,7 +14,7 @@ function CMulTable:updateOutput(input) return self.output end -function CMulTable:updateGradInput(input, gradOutput) +function CMulTable:updateGradInput_efficient(input, gradOutput) self.tout = self.tout or input[1].new() self.tout:resizeAs(self.output) for i=1,#input do @@ -25,3 +25,17 @@ function CMulTable:updateGradInput(input, gradOutput) end return self.gradInput end + +function CMulTable:updateGradInput(input, gradOutput) + for i=1,#input do + self.gradInput[i] = self.gradInput[i] or input[1].new() + self.gradInput[i]:resizeAs(input[i]):copy(gradOutput) + for j=1,#input do + if i~=j then + self.gradInput[i]:cmul(input[j]) + end + end + end + return self.gradInput +end + |