mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-30 00:50:37 +08:00
Add Problem::EvaluateResidualBlockAssumingParametersUnchanged
Simplify the semantics for Problem::EvaluateResidualBlock to not ignore the presence of EvaluationCallback and add another method EvaluateResidualBlockAssumingParametersUnchanged to handle the case where the user has an EvaluationCallback but knows that the parameter blocks do not change between calls. Updated the documentation for the methods and EvaluationCallback to reflect these semantics. Also added tests for Evaluation related methods calling i EvaluationCallback when its present. https://github.com/ceres-solver/ceres-solver/issues/483 Change-Id: If0a0c95c2f1f92e9183a90df240104a69a71c46d
This commit is contained in:
@@ -601,7 +601,6 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options,
|
||||
CRSMatrix* jacobian) {
|
||||
if (cost == nullptr && residuals == nullptr && gradient == nullptr &&
|
||||
jacobian == nullptr) {
|
||||
LOG(INFO) << "Nothing to do.";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -768,9 +767,15 @@ bool ProblemImpl::Evaluate(const Problem::EvaluateOptions& evaluate_options,
|
||||
|
||||
bool ProblemImpl::EvaluateResidualBlock(ResidualBlock* residual_block,
|
||||
bool apply_loss_function,
|
||||
bool new_point,
|
||||
double* cost,
|
||||
double* residuals,
|
||||
double** jacobians) const {
|
||||
auto evaluation_callback = program_->mutable_evaluation_callback();
|
||||
if (evaluation_callback) {
|
||||
evaluation_callback->PrepareForEvaluation(jacobians != nullptr, new_point);
|
||||
}
|
||||
|
||||
ParameterBlock* const* parameter_blocks = residual_block->parameter_blocks();
|
||||
const int num_parameter_blocks = residual_block->NumParameterBlocks();
|
||||
for (int i = 0; i < num_parameter_blocks; ++i) {
|
||||
@@ -789,7 +794,8 @@ bool ProblemImpl::EvaluateResidualBlock(ResidualBlock* residual_block,
|
||||
}
|
||||
|
||||
double dummy_cost = 0.0;
|
||||
FixedArray<double> scratch(residual_block->NumScratchDoublesForEvaluate());
|
||||
FixedArray<double, 32> scratch(
|
||||
residual_block->NumScratchDoublesForEvaluate());
|
||||
return residual_block->Evaluate(apply_loss_function,
|
||||
cost ? cost : &dummy_cost,
|
||||
residuals,
|
||||
|
||||
Reference in New Issue
Block a user