Skip to content

Commit

Permalink
fd -> fd_centered
Browse files Browse the repository at this point in the history
  • Loading branch information
Huangzizhou committed Sep 5, 2024
1 parent c2921f1 commit baa3f10
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/polysolve/nonlinear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,18 @@ namespace polysolve::nonlinear
objFunc.solution_changed(x1);
double J1 = objFunc(x1);

double fd = (J2 - J1) / 2 / gradient_fd_eps;
double fd_centered = (J2 - J1) / 2 / gradient_fd_eps;
double fd_right = (J2 - J) / gradient_fd_eps;
double fd_left = (J - J1) / gradient_fd_eps;
double analytic = direc.dot(grad);

match = abs(fd - analytic) < 1e-8 || abs(fd - analytic) < 1e-4 * abs(analytic);
match = abs(fd_centered - analytic) < 1e-8 || abs(fd_centered - analytic) < 1e-4 * abs(analytic);

// Log error in either case to make it more visible in the logs.
if (match)
m_logger.debug("step size: {}, finite difference: {} {} {}, derivative: {}", gradient_fd_eps, fd, fd_left, fd_right, analytic);
m_logger.debug("step size: {}, finite difference: {} {} {}, derivative: {}", gradient_fd_eps, fd_centered, fd_left, fd_right, analytic);
else
m_logger.error("step size: {}, finite difference: {} {} {}, derivative: {}", gradient_fd_eps, fd, fd_left, fd_right, analytic);
m_logger.error("step size: {}, finite difference: {} {} {}, derivative: {}", gradient_fd_eps, fd_centered, fd_left, fd_right, analytic);

Check warning on line 612 in src/polysolve/nonlinear/Solver.cpp

View check run for this annotation

Codecov / codecov/patch

src/polysolve/nonlinear/Solver.cpp#L612

Added line #L612 was not covered by tests
}
break;
case FiniteDiffStrategy::FULL_FINITE_DIFF:
Expand Down

0 comments on commit baa3f10

Please sign in to comment.