Add tests for grad shape.
Some improvements to the gradient, but it's still transposed and partially wrong.