I didn't saw this before merging. Why did you set the sparse_grad attribute in the Type and not in the Variable? I find that strange.

So how to use this? Is that the right way to use this new feature:

import theano
import theano.tensor as tt
x = tt.matrix()
idx = tt.ivector()
sub1 = x[idx]
sub1.type.sparse_grad = True
g = theano.grad(sub1.sum(), x)
theano.printing.debugprint(g)

Before we document this feature, I would like to be sure we keep the attribute in the Type. @lamblin @jaberg what do you think?