diff --git a/docs/source/modeling.rst b/docs/source/modeling.rst index a5e875d83..99c1e7c54 100644 --- a/docs/source/modeling.rst +++ b/docs/source/modeling.rst @@ -371,8 +371,8 @@ residuals and their derivatives. This is done using int N7 = 0, // Number of parameters in block 7. int N8 = 0, // Number of parameters in block 8. int N9 = 0> // Number of parameters in block 9. - class NumericDiffCostFunction - : public SizedCostFunction { + class NumericDiffCostFunction : public + SizedCostFunction { }; To get a numerically differentiated :class:`CostFunction`, you must @@ -458,15 +458,15 @@ residuals and their derivatives. This is done using CostFunction* cost_function = new NumericDiffCostFunction( - new CostFunctorWithDynamicNumResiduals(1.0), ^ ^ ^ - TAKE_OWNERSHIP, | | | - runtime_number_of_residuals); <----+ | | | - | | | | - | | | | - Actual number of residuals ------+ | | | - Indicate dynamic number of residuals --------+ | | - Dimension of x ------------------------------------+ | - Dimension of y ---------------------------------------+ + new CostFunctorWithDynamicNumResiduals(1.0), ^ ^ ^ + TAKE_OWNERSHIP, | | | + runtime_number_of_residuals); <----+ | | | + | | | | + | | | | + Actual number of residuals ------+ | | | + Indicate dynamic number of residuals --------------------+ | | + Dimension of x ------------------------------------------------+ | + Dimension of y ---------------------------------------------------+ The framework can currently accommodate cost functions of up to 10 diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h index cb6801f42..79f90c505 100644 --- a/include/ceres/autodiff_cost_function.h +++ b/include/ceres/autodiff_cost_function.h @@ -186,7 +186,9 @@ class AutoDiffCostFunction : public SizedCostFunction + SizedCostFunction ::set_num_residuals(num_residuals); } @@ -209,7 +211,9 @@ class AutoDiffCostFunction : public SizedCostFunction::Differentiate( *functor_, parameters, - SizedCostFunction + SizedCostFunction ::num_residuals(), residuals, jacobians); diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h index c30e0f145..9f7000050 100644 --- a/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/include/ceres/dynamic_numeric_diff_cost_function.h @@ -108,8 +108,8 @@ class DynamicNumericDiffCostFunction : public CostFunction { << "You must call DynamicNumericDiffCostFunction::AddParameterBlock() " << "before DynamicNumericDiffCostFunction::Evaluate()."; - bool status = (*functor_)(parameters, residuals); - if (jacobians == NULL) { + const bool status = (*functor_)(parameters, residuals); + if (jacobians == NULL || !status) { return status; } diff --git a/include/ceres/numeric_diff_cost_function.h b/include/ceres/numeric_diff_cost_function.h index 94573e514..de6b74ad5 100644 --- a/include/ceres/numeric_diff_cost_function.h +++ b/include/ceres/numeric_diff_cost_function.h @@ -100,15 +100,15 @@ // // CostFunction* cost_function // = new NumericDiffCostFunction( -// new CostFunctorWithDynamicNumResiduals(1.0), ^ ^ ^ -// TAKE_OWNERSHIP, | | | -// runtime_number_of_residuals); <----+ | | | -// | | | | -// | | | | -// Actual number of residuals ------+ | | | -// Indicate dynamic number of residuals --------+ | | -// Dimension of x ------------------------------------+ | -// Dimension of y ---------------------------------------+ +// new CostFunctorWithDynamicNumResiduals(1.0), ^ ^ ^ +// TAKE_OWNERSHIP, | | | +// runtime_number_of_residuals); <----+ | | | +// | | | | +// | | | | +// Actual number of residuals ------+ | | | +// Indicate dynamic number of residuals --------------------+ | | +// Dimension of x ------------------------------------------------+ | +// Dimension of y ---------------------------------------------------+ // // The framework can currently accommodate cost functions of up to 10 // independent variables, and there is no limit on the dimensionality @@ -197,7 +197,9 @@ class NumericDiffCostFunction ownership_(ownership), relative_step_size_(relative_step_size) { if (kNumResiduals == DYNAMIC) { - SizedCostFunction + SizedCostFunction ::set_num_residuals(num_residuals); } } @@ -277,7 +279,9 @@ class NumericDiffCostFunction functor_.get(), \ residuals, \ relative_step_size_, \ - SizedCostFunction::num_residuals(), \ + SizedCostFunction::num_residuals(), \ parameters_reference_copy.get(), \ jacobians[block])) { \ return false; \