Fix evaluation of initial cost and corresponding test Commit f102a68e411d11b4864e17b69a2d781e9c2692ad seems to have introduced a bug in both solver_impl.cc and solver_impl_test.cc solver_impl_test showed 3 errors, where two were due to ceres NOT failing when the test expected that, and one was due to the initial cost being wrong (-1 instead of 0.5) Ceres now does not attempt to evaluate the initial cost if options.return_initial_xxx is not set. It therefore did not fail in the tests. It also seems that the CERES_EVALUATE macro erroneously always sets final_cost, even when called with 'initial' as argument. Change-Id: Ia3c3eeb476e7023a3f80b201124010d6c67e9824
diff --git a/internal/ceres/solver_impl.cc b/internal/ceres/solver_impl.cc index a070ce6..475e71d 100644 --- a/internal/ceres/solver_impl.cc +++ b/internal/ceres/solver_impl.cc
@@ -86,7 +86,7 @@ Evaluator::Evaluate( \ original_program, \ options.num_threads, \ - &summary->final_cost, \ + &summary->which ## _cost, \ options.return_ ## which ## _residuals ? &summary->which ## _residuals : NULL, \ options.return_ ## which ## _gradient ? &summary->which ## _gradient : NULL, \ options.return_ ## which ## _jacobian ? &summary->which ## _jacobian : NULL)
diff --git a/internal/ceres/solver_impl_test.cc b/internal/ceres/solver_impl_test.cc index d918a57..5cba7d7 100644 --- a/internal/ceres/solver_impl_test.cc +++ b/internal/ceres/solver_impl_test.cc
@@ -859,6 +859,7 @@ Solver::Options options; Solver::Summary summary; double x; + options.return_initial_residuals = true; problem_impl.AddResidualBlock(new FailingCostFunction, NULL, &x); SolverImpl::Solve(options, &problem_impl, &summary); EXPECT_EQ(summary.termination_type, NUMERICAL_FAILURE); @@ -870,6 +871,8 @@ Solver::Options options; Solver::Summary summary; double x = 1; + options.return_initial_residuals = true; + options.return_final_residuals = true; problem_impl.AddResidualBlock(new UnaryIdentityCostFunction, NULL, &x); problem_impl.SetParameterBlockConstant(&x); SolverImpl::Solve(options, &problem_impl, &summary);