torch/torch7-distro — pull request #189 by paidi (2013-10-29 18:55:25+00:00)
Title: Fix SparseLinear

Fixed an issue with SparseLinear (Issue #75 on github) and added a test along with a new class
SparseJacobian to test sparse modules (only works for sparse modules with 1D inputs at the moment)

After this change, the example in the documentation works

t7> require 'nn'
t7> module= nn.SparseLinear(10000,2) -- 10000 inputs, 2 outputs
t7> x=torch.Tensor({{1, 0.1},{2, 0.3},{10, 0.3},{31, 0.2}})
t7> print(x)
1.0000 0.1000
2.0000 0.3000
10.0000 0.3000
31.0000 0.2000
[torch.DoubleTensor of dimension 4x2]

t7> module:forward(x)
t7> =module:forward(x)
0.0169
-0.2129
[torch.DoubleTensor of dimension 2]