def sparse_grad(var):
 assert isinstance(var.owner.op, tensor.AdvancedSubtensor1)
 ret = var.owner.op.__class__(sparse_grad=True)(*var.owner.inputs)
 return ret

def sparse_grad ( var ) : assert isinstance ( var . owner . op , tensor . AdvancedSubtensor1 ) ret = var . owner . op . __class__ ( sparse_grad = True ) ( * var . owner . inputs ) return ret
this function return a new variable whose gradient will be stored in a sparse format instead of dense .