GradientCheckingProblem's parameter blocks are initialized correctly. Ensure that when a new problem object is constructed for validing gradients, the parameter blocks have their data pointers point to the user's parameter blocks. We used to do this inside solver_impl.cc, but doing this at construction is the right thing to do. Change-Id: I3bfdc89bb0027c8d67cde937e8f2fa385d89c30c
diff --git a/internal/ceres/gradient_checking_cost_function.cc b/internal/ceres/gradient_checking_cost_function.cc index bca22e6..3272848 100644 --- a/internal/ceres/gradient_checking_cost_function.cc +++ b/internal/ceres/gradient_checking_cost_function.cc
@@ -310,6 +310,17 @@ parameter_blocks); } + // Normally, when a problem is given to the solver, we guarantee + // that the state pointers for each parameter block point to the + // user provided data. Since we are creating this new problem from a + // problem given to us at an arbitrary stage of the solve, we cannot + // depend on this being the case, so we explicitly call + // SetParameterBlockStatePtrsToUserStatePtrs to ensure that this is + // the case. + gradient_checking_problem_impl + ->mutable_program() + ->SetParameterBlockStatePtrsToUserStatePtrs(); + return gradient_checking_problem_impl; }