de-vectorized loop added to the gradient computation
Former-commit-id: b01eb5ff76527569a1eb71826178bc2059530650