More asserts in gradient calculation