diff options
author | Páidí Creed <paidi@swiftkey.net> | 2013-10-29 21:56:45 +0400 |
---|---|---|
committer | Páidí Creed <paidi@swiftkey.net> | 2013-10-29 22:45:08 +0400 |
commit | d1c7da6a9f760c31a1b27477e27b124e84d556ab (patch) | |
tree | f660c11b767e63194f569472220a529824fb9748 /SparseLinear.lua | |
parent | 55e19082fbdfdad68fc450e41f860d8138bc2861 (diff) |
Fix SparseLinear
Fixed an issue with SparseLinear and added a test along with a new class
SparseJacobian (for testing sparse modules)
Diffstat (limited to 'SparseLinear.lua')
-rw-r--r-- | SparseLinear.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/SparseLinear.lua b/SparseLinear.lua index f1a2be5..735d0ed 100644 --- a/SparseLinear.lua +++ b/SparseLinear.lua @@ -42,3 +42,20 @@ end function SparseLinear:accGradParameters(input, gradOutput, scale) return input.nn.SparseLinear_accGradParameters(self, input, gradOutput, scale) end + +function SparseLinear:updateGradInput(input, gradOutput) + if self.gradInput then + self.gradInput:resize(input:size()) + self.gradInput:copy(input) + local numNonzero = self.gradInput:size(1) + for e=1,numNonzero do + local g = 0 + local i = self.gradInput[{e,1}] + for j=1,self.output:size(1) do + g = g + self.weight[{j,i}] * gradOutput[j] + end + self.gradInput[{e,2}] = g + end + return self.gradInput + end +end
\ No newline at end of file |