From d1c7da6a9f760c31a1b27477e27b124e84d556ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1id=C3=AD=20Creed?= Date: Tue, 29 Oct 2013 17:56:45 +0000 Subject: Fix SparseLinear Fixed an issue with SparseLinear and added a test along with a new class SparseJacobian (for testing sparse modules) --- SparseLinear.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'SparseLinear.lua') 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 -- cgit v1.2.3