From 1e6fe1c4194d16c8245642f46454ce27c9cec48a Mon Sep 17 00:00:00 2001 From: koray kavukcuoglu Date: Tue, 19 Mar 2013 16:31:41 +0000 Subject: CMulTable updateGradInput now uses proper but slow gradient calculation. The old one is available in updateGradInput_efficient function. --- CMulTable.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 + -- cgit v1.2.3