One alternative is to use complex step derivative approximation, since we can use complex number with eigen’s sparse solver.