Note that Problem::Evaluate cannot be called from an IterationCallback Change-Id: Ieabdc2d40715e6b547ab22156ba32e9c8444b7ed
diff --git a/docs/source/nnls_modeling.rst b/docs/source/nnls_modeling.rst index b82f5ba..c68a359 100644 --- a/docs/source/nnls_modeling.rst +++ b/docs/source/nnls_modeling.rst
@@ -1737,29 +1737,45 @@ `NULL`. Which residual blocks and parameter blocks are used is controlled by the :class:`Problem::EvaluateOptions` struct below. - .. code-block:: c++ + .. NOTE:: - Problem problem; - double x = 1; - problem.Add(new MyCostFunction, NULL, &x); + The evaluation will use the values stored in the memory + locations pointed to by the parameter block pointers used at the + time of the construction of the problem, for example in the + following code: - double cost = 0.0; - problem.Evaluate(Problem::EvaluateOptions(), &cost, NULL, NULL, NULL); + .. code-block:: c++ - The cost is evaluated at `x = 1`. If you wish to evaluate the - problem at `x = 2`, then + Problem problem; + double x = 1; + problem.Add(new MyCostFunction, NULL, &x); - .. code-block:: c++ + double cost = 0.0; + problem.Evaluate(Problem::EvaluateOptions(), &cost, NULL, NULL, NULL); - x = 2; - problem.Evaluate(Problem::EvaluateOptions(), &cost, NULL, NULL, NULL); + The cost is evaluated at `x = 1`. If you wish to evaluate the + problem at `x = 2`, then - is the way to do so. + .. code-block:: c++ - **NOTE** If no local parameterizations are used, then the size of - the gradient vector is the sum of the sizes of all the parameter - blocks. If a parameter block has a local parameterization, then - it contributes "LocalSize" entries to the gradient vector. + x = 2; + problem.Evaluate(Problem::EvaluateOptions(), &cost, NULL, NULL, NULL); + + is the way to do so. + + .. NOTE:: + + If no local parameterizations are used, then the size of + the gradient vector is the sum of the sizes of all the parameter + blocks. If a parameter block has a local parameterization, then + it contributes "LocalSize" entries to the gradient vector. + + .. NOTE:: + + This function cannot be called while the problem is being + solved, for example it cannot be called from an + :class:`IterationCallback` at the end of an iteration during a + solve. .. class:: Problem::EvaluateOptions
diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 14bf6c2..27ed4ef 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h
@@ -464,6 +464,10 @@ // parameter block has a local parameterization, then it contributes // "LocalSize" entries to the gradient vector (and the number of // columns in the jacobian). + // + // Note 3: This function cannot be called while the problem is being + // solved, for example it cannot be called from an IterationCallback + // at the end of an iteration during a solve. bool Evaluate(const EvaluateOptions& options, double* cost, std::vector<double>* residuals,