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

github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMulTable.lua16
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
+