The problem with using jacobian is that it produces too big matrices, and I run into memory problems.
For example if input is 10x2 and output is 10x1, the jacobian is 10x20, and I only need the diagonal elements of the two 10x10 matrices stack to each other.