Advinc rebase

@lamblin  I encountered some problems, but I think this is a better rebase (https://github.com/Theano/Theano/pull/1239). Do you see any obvious problems? I'm still getting test errors, but I don't see how they're linked.