Make the Evaluator statistics key strings consistent We keep track of evaluator call and time statistics via a hashmap containing magic strings. These strings need to be consistent across the GradientProblemSolver and Solver as the LineSearchMinimizer is used by both of these solvers. Previously they were inconsistent in a manner that GradientProblemSolver was not getting information about the evaluation timing, and in the process of fixing that I made it so that the TrustRegionMinimizer when solving bounds constrained probelms will access/update this information correctly. So while I look for a more elegant solution, this CL is meant to fix the inconsistency by making sure that the same magic strings are used everywhere. Change-Id: I120ca0bd1c2f77fde2db15edd9e33286a49dbae9
diff --git a/internal/ceres/gradient_problem_evaluator.h b/internal/ceres/gradient_problem_evaluator.h index ca49c24..9ccd10e 100644 --- a/internal/ceres/gradient_problem_evaluator.h +++ b/internal/ceres/gradient_problem_evaluator.h
@@ -57,11 +57,18 @@ SparseMatrix* jacobian) { CHECK(jacobian == NULL); ScopedExecutionTimer total_timer("Evaluator::Total", &execution_summary_); + // The reason we use Residual and Jacobian here even when we are + // only computing the cost and gradient has to do with the fact + // that the line search minimizer code is used by both the + // GradientProblemSolver and the main CeresSolver coder where the + // Evaluator evaluates the Jacobian, and these magic strings need + // to be consistent across the code base for the time accounting + // to work. ScopedExecutionTimer call_type_timer( - gradient == NULL ? "Evaluator::Cost" : "Evaluator::Gradient", + gradient == NULL ? "Evaluator::Residual" : "Evaluator::Jacobian", &execution_summary_); - execution_summary_.IncrementCall(gradient == NULL ? "Evaluator::Cost" - : "Evaluator::Gradient"); + execution_summary_.IncrementCall(gradient == NULL ? "Evaluator::Residual" + : "Evaluator::Jacobian"); return problem_.Evaluate(state, cost, gradient); }
diff --git a/internal/ceres/gradient_problem_solver.cc b/internal/ceres/gradient_problem_solver.cc index 478818b..ba36dd7 100644 --- a/internal/ceres/gradient_problem_solver.cc +++ b/internal/ceres/gradient_problem_solver.cc
@@ -166,15 +166,15 @@ const std::map<string, double>& evaluator_time_statistics = minimizer_options.evaluator->TimeStatistics(); summary->cost_evaluation_time_in_seconds = - FindWithDefault(evaluator_time_statistics, "Evaluator::Cost", 0.0); + FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0); summary->gradient_evaluation_time_in_seconds = - FindWithDefault(evaluator_time_statistics, "Evaluator::Gradient", 0.0); + FindWithDefault(evaluator_time_statistics, "Evaluator::Jacobian", 0.0); const std::map<string, int>& evaluator_call_statistics = minimizer_options.evaluator->CallStatistics(); summary->num_cost_evaluations = - FindWithDefault(evaluator_call_statistics, "Evaluator::Cost", 0); + FindWithDefault(evaluator_call_statistics, "Evaluator::Residual", 0); summary->num_gradient_evaluations = - FindWithDefault(evaluator_call_statistics, "Evaluator::Gradient", 0); + FindWithDefault(evaluator_call_statistics, "Evaluator::Jacobian", 0); summary->total_time_in_seconds = WallTimeInSeconds() - start_time; }