mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-30 00:50:37 +08:00
Remove RuntimeNumericDiffCostFunction.
Move the GradientCheckingCostFunction to DynamicNumericDiffCostFunction. Also fix a const correctness issue with DynamicNumericDiffCostFunction. Change-Id: Id446810f43374e7b7db7fe4dd01a891e3c54abb9
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
#include "ceres/cost_function.h"
|
||||
#include "ceres/internal/scoped_ptr.h"
|
||||
#include "ceres/internal/eigen.h"
|
||||
#include "ceres/internal/numeric_diff.h"
|
||||
#include "glog/logging.h"
|
||||
|
||||
namespace ceres {
|
||||
@@ -74,7 +75,7 @@ namespace ceres {
|
||||
template <typename CostFunctor, NumericDiffMethod method = CENTRAL>
|
||||
class DynamicNumericDiffCostFunction : public CostFunction {
|
||||
public:
|
||||
explicit DynamicNumericDiffCostFunction(CostFunctor* functor,
|
||||
explicit DynamicNumericDiffCostFunction(const CostFunctor* functor,
|
||||
Ownership ownership = TAKE_OWNERSHIP,
|
||||
double relative_step_size = 1e-6)
|
||||
: functor_(functor),
|
||||
@@ -108,7 +109,7 @@ class DynamicNumericDiffCostFunction : public CostFunction {
|
||||
<< "You must call DynamicNumericDiffCostFunction::AddParameterBlock() "
|
||||
<< "before DynamicNumericDiffCostFunction::Evaluate().";
|
||||
|
||||
const bool status = (*functor_)(parameters, residuals);
|
||||
const bool status = EvaluateCostFunctor(parameters, residuals);
|
||||
if (jacobians == NULL || !status) {
|
||||
return status;
|
||||
}
|
||||
@@ -194,7 +195,7 @@ class DynamicNumericDiffCostFunction : public CostFunction {
|
||||
x_plus_delta(j) = x(j) + step_size(j);
|
||||
|
||||
ResidualVector residuals(num_residuals);
|
||||
if (!(*functor_)(parameters, &residuals[0])) {
|
||||
if (!EvaluateCostFunctor(parameters, &residuals[0])) {
|
||||
// Something went wrong; bail.
|
||||
return false;
|
||||
}
|
||||
@@ -210,7 +211,7 @@ class DynamicNumericDiffCostFunction : public CostFunction {
|
||||
// Compute the function on the other side of x(j).
|
||||
x_plus_delta(j) = x(j) - step_size(j);
|
||||
|
||||
if (!(*functor_)(parameters, &residuals[0])) {
|
||||
if (!EvaluateCostFunctor(parameters, &residuals[0])) {
|
||||
// Something went wrong; bail.
|
||||
return false;
|
||||
}
|
||||
@@ -230,7 +231,31 @@ class DynamicNumericDiffCostFunction : public CostFunction {
|
||||
return true;
|
||||
}
|
||||
|
||||
internal::scoped_ptr<CostFunctor> functor_;
|
||||
bool EvaluateCostFunctor(double const* const* parameters,
|
||||
double* residuals) const {
|
||||
return EvaluateCostFunctorImpl(functor_.get(),
|
||||
parameters,
|
||||
residuals,
|
||||
functor_.get());
|
||||
}
|
||||
|
||||
// Helper templates to allow evaluation of a functor or a
|
||||
// CostFunction.
|
||||
bool EvaluateCostFunctorImpl(const CostFunctor* functor,
|
||||
double const* const* parameters,
|
||||
double* residuals,
|
||||
const void* /* NOT USED */) const {
|
||||
return (*functor)(parameters, residuals);
|
||||
}
|
||||
|
||||
bool EvaluateCostFunctorImpl(const CostFunctor* functor,
|
||||
double const* const* parameters,
|
||||
double* residuals,
|
||||
const CostFunction* /* NOT USED */) const {
|
||||
return functor->Evaluate(parameters, residuals, NULL);
|
||||
}
|
||||
|
||||
internal::scoped_ptr<const CostFunctor> functor_;
|
||||
Ownership ownership_;
|
||||
const double relative_step_size_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user