This can also be done in the theano fct with inc_subtensor and set_subtensor that would be made inplace. But this can be tried only if the other change to the fct give speed up.