mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Ensure that partial evaluation of residuals triggers an error
ResidualBlock evaluation has logic to ensure that CostFunction should always fill out the residual and jacobian arrays completely by using a special value to pre-populate these arrays. This works for CostFunctions with analytical Jacobians but not for AutoDiffCostFunction and NumericDiffCostFunction Jacobians. There is no way to fix this for NumericDiffCostFunctions without introducing significant performance penalties but the residual evaluation fails, which should be enough to catch such errors. For AutoDiffCostFunction the way the Jets are default initialized was sidestepping this check. So now, the Jet that is used to capture the output residuals is now initialized with kImpossibleValue, which will ensure that if the user forgets to fill all output fields, it triggers an evaluation error. This change required that ceres::internal::kImpossibleValue be moved out of array_utils.h/cc to types.h. Change-Id: I35bb0946cf0785a5d43c7b5459a2272848fb2a9b
This commit is contained in:
@@ -424,6 +424,13 @@ enum CovarianceAlgorithmType {
|
||||
EIGEN_SPARSE_QR
|
||||
};
|
||||
|
||||
// It is a near impossibility that user code generates this exact
|
||||
// value in normal operation, thus we will use it to fill arrays
|
||||
// before passing them to user code. If on return an element of the
|
||||
// array still contains this value, we will assume that the user code
|
||||
// did not write to that memory location.
|
||||
const double kImpossibleValue = 1e302;
|
||||
|
||||
CERES_EXPORT const char* LinearSolverTypeToString(
|
||||
LinearSolverType type);
|
||||
CERES_EXPORT bool StringToLinearSolverType(std::string value,
|
||||
|
||||
Reference in New Issue
Block a user