Fix blocksparse optimization that could give bad results in some cases

This changes the way "inplace" optimization for SparseBlock{Gemv,Outer}SS works.  It makes it much safer for unusual graphs and add support for add along with sub.

However due to these changes, it makes avoiding the Alloc the responsability of other optimizations (local_alloc_elemwise), which are not enabled by default and are highly recommended.  Use the flag `optimizer_including=local_alloc_elemwise` to enable it.
ok for cuda_available.

I still don't like the grab_ger. Is it documented somewhere that this is a
ger? what about grab_sboss? It don't have the same input as a ger and it
don't do the same think(even if related).

For the test, if that condition don't happen in real case, ok if @lamblin
is ok with this too. @lamblin, can you review this? I don't know enough the
code to be sure.

On Fri, Sep 26, 2014 at 2:36 PM, abergeron <notifications@github.com> wrote:

> In theano/sandbox/cuda/blocksparse.py:
>
> > @@ -693,8 +693,14 @@ def local_merge_blocksparse_beta(node):
> >                  W = node.inputs[0]
> >              if ger is None:
> >                  return None
> > +            if node.op.scalar_op == scalar.sub:
> > +                alpha = -ger.inputs[5]
> > +                W = W - ger.inputs[0]
> > +            else:
> > +                alpha = ger.inputs[5]
> > +                W = W + ger.inputs[0]
>
> Yes. I'm not sure exactly how to test this since I never had any actual
> test case. It was found through semantic analysis I did when I worked with
> Dustin a while back. As far as I know nobody ever encountered that
> particular problem since the structure it requires to show up is just not
> created by the grad function. But it's still a possibility.
>
> grab_ger is looking for a ger (SparseBlockOuterSS is a ger).
>
> I need to keep the cuda_available test since opt is not imported if it's
> False.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/Theano/Theano/pull/2136/files#r18105860>.
>