A bunch of minor changes.

1. Fix a typo in auto_diff_cost_function.h
2. Fix and update Solver::Summary::FullReport() text labels.
3. Add logging of the number of residual and jacobian evaluations
   to the full report. The GradientProblemSolver already does this.

Change-Id: I41059af5f0ebe0417accbbc30b0808a4b04b9edb
diff --git a/docs/source/nnls_solving.rst b/docs/source/nnls_solving.rst
index 56b3ab9..4dd17ec 100644
--- a/docs/source/nnls_solving.rst
+++ b/docs/source/nnls_solving.rst
@@ -2045,10 +2045,18 @@
 
    Time (in seconds) spent evaluating the residual vector.
 
+.. member:: int Solver::Summary::num_residual_evaluations
+
+   Number of times only the residuals were evaluated.
+
 .. member:: double Solver::Summary::jacobian_evaluation_time_in_seconds
 
    Time (in seconds) spent evaluating the Jacobian matrix.
 
+.. member:: int Solver::Summary::num_jacobian_evaluations
+
+   Number of times only the Jacobian and the residuals were evaluated.
+
 .. member:: double Solver::Summary::inner_iteration_time_in_seconds
 
    Time (in seconds) spent doing inner iterations.
diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h
index e7893e4..490fb3d 100644
--- a/include/ceres/autodiff_cost_function.h
+++ b/include/ceres/autodiff_cost_function.h
@@ -197,7 +197,7 @@
   // Implementation details follow; clients of the autodiff cost function should
   // not have to examine below here.
   //
-  // To handle varardic cost functions, some template magic is needed. It's
+  // To handle variadic cost functions, some template magic is needed. It's
   // mostly hidden inside autodiff.h.
   virtual bool Evaluate(double const* const* parameters,
                         double* residuals,
diff --git a/include/ceres/solver.h b/include/ceres/solver.h
index 96391ba..3a55a65 100644
--- a/include/ceres/solver.h
+++ b/include/ceres/solver.h
@@ -844,9 +844,15 @@
     // Time (in seconds) spent evaluating the residual vector.
     double residual_evaluation_time_in_seconds;
 
+    // Number of residual only evaluations.
+    int num_residual_evaluations;
+
     // Time (in seconds) spent evaluating the jacobian matrix.
     double jacobian_evaluation_time_in_seconds;
 
+    // Number of Jacobian (and residual) evaluations.
+    int num_jacobian_evaluations;
+
     // Time (in seconds) spent doing inner iterations.
     double inner_iteration_time_in_seconds;
 
diff --git a/internal/ceres/execution_summary.h b/internal/ceres/execution_summary.h
index aa9929d..80f1af8 100644
--- a/internal/ceres/execution_summary.h
+++ b/internal/ceres/execution_summary.h
@@ -44,6 +44,12 @@
 // Struct used by various objects to report statistics and other
 // information about their execution. e.g., ExecutionSummary::times
 // can be used for reporting times associated with various activities.
+//
+// TODO(https://github.com/ceres-solver/ceres-solver/issues/340):
+// Replace the two maps by one to save on a lookup, since the usage
+// pattern is to keep track of the calls and the time increment at the
+// same time.
+//
 class ExecutionSummary {
  public:
   void IncrementTimeBy(const std::string& name, const double value) {
@@ -76,6 +82,7 @@
 
   ~ScopedExecutionTimer() {
     summary_->IncrementTimeBy(name_, WallTimeInSeconds() - start_time_);
+    summary_->IncrementCall(name_);
   }
 
  private:
diff --git a/internal/ceres/gradient_problem_evaluator.h b/internal/ceres/gradient_problem_evaluator.h
index 9ccd10e..69e0e8a 100644
--- a/internal/ceres/gradient_problem_evaluator.h
+++ b/internal/ceres/gradient_problem_evaluator.h
@@ -67,8 +67,6 @@
     ScopedExecutionTimer call_type_timer(
         gradient == NULL ? "Evaluator::Residual" : "Evaluator::Jacobian",
         &execution_summary_);
-    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 920d735..b22c5a1 100644
--- a/internal/ceres/gradient_problem_solver.cc
+++ b/internal/ceres/gradient_problem_solver.cc
@@ -276,7 +276,7 @@
   StringAppendF(&report, "\n  Cost evaluation     %23.6f (%d)\n",
                 cost_evaluation_time_in_seconds,
                 num_cost_evaluations);
-  StringAppendF(&report, "  Gradient evaluation %23.6f (%d)\n",
+  StringAppendF(&report, "  Gradient & cost evaluation %16.6f (%d)\n",
                 gradient_evaluation_time_in_seconds,
                 num_gradient_evaluations);
   StringAppendF(&report, "  Polynomial minimization   %17.6f\n",
diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc
index bee0e19..4d1db50 100644
--- a/internal/ceres/solver.cc
+++ b/internal/ceres/solver.cc
@@ -404,6 +404,13 @@
         FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0);
     summary->jacobian_evaluation_time_in_seconds =
         FindWithDefault(evaluator_time_statistics, "Evaluator::Jacobian", 0.0);
+
+    const map<string, int>& evaluator_call_statistics =
+        pp.evaluator->CallStatistics();
+    summary->num_residual_evaluations =
+        FindWithDefault(evaluator_call_statistics, "Evaluator::Residual", 0);
+    summary->num_jacobian_evaluations =
+        FindWithDefault(evaluator_call_statistics, "Evaluator::Jacobian", 0);
   }
 
   // Again, like the evaluator, there may or may not be a linear
@@ -627,7 +634,9 @@
       total_time_in_seconds(-1.0),
       linear_solver_time_in_seconds(-1.0),
       residual_evaluation_time_in_seconds(-1.0),
+      num_residual_evaluations(-1),
       jacobian_evaluation_time_in_seconds(-1.0),
+      num_jacobian_evaluations(-1),
       inner_iteration_time_in_seconds(-1.0),
       line_search_cost_evaluation_time_in_seconds(-1.0),
       line_search_gradient_evaluation_time_in_seconds(-1.0),
@@ -696,7 +705,7 @@
   }
   StringAppendF(&report, "Residual blocks     % 25d% 25d\n",
                 num_residual_blocks, num_residual_blocks_reduced);
-  StringAppendF(&report, "Residual            % 25d% 25d\n",
+  StringAppendF(&report, "Residuals           % 25d% 25d\n",
                 num_residuals, num_residuals_reduced);
 
   if (minimizer_type == TRUST_REGION) {
@@ -866,14 +875,14 @@
   StringAppendF(&report, "Preprocessor        %25.6f\n",
                 preprocessor_time_in_seconds);
 
-  StringAppendF(&report, "\n  Residual evaluation %23.6f\n",
-                residual_evaluation_time_in_seconds);
+  StringAppendF(&report, "\n  Residual only evaluation %18.6f (%d)\n",
+                residual_evaluation_time_in_seconds, num_residual_evaluations);
   if (line_search_used) {
     StringAppendF(&report, "    Line search cost evaluation    %10.6f\n",
                   line_search_cost_evaluation_time_in_seconds);
   }
-  StringAppendF(&report, "  Jacobian evaluation %23.6f\n",
-                jacobian_evaluation_time_in_seconds);
+  StringAppendF(&report, "  Jacobian & residual evaluation %12.6f (%d)\n",
+                jacobian_evaluation_time_in_seconds, num_jacobian_evaluations);
   if (line_search_used) {
     StringAppendF(&report, "    Line search gradient evaluation   %6.6f\n",
                   line_search_gradient_evaluation_time_in_seconds);