Add Problem::IsParameterBlockPresent.
This allows the user to query the Problem to see if a
parameter block is already present or not.
Change-Id: If786f6c008cc644f3398597901d718d12a6d865d
diff --git a/include/ceres/problem.h b/include/ceres/problem.h
index bed792a..b8759eb 100644
--- a/include/ceres/problem.h
+++ b/include/ceres/problem.h
@@ -349,6 +349,9 @@
// block, then ParameterBlockLocalSize = ParameterBlockSize.
int ParameterBlockLocalSize(const double* values) const;
+ // Is the given parameter block present in this problem or not?
+ bool HasParameterBlock(const double* values) const;
+
// Fills the passed parameter_blocks vector with pointers to the
// parameter blocks currently in the problem. After this call,
// parameter_block.size() == NumParameterBlocks.
diff --git a/internal/ceres/problem.cc b/internal/ceres/problem.cc
index 9bdc1ef..674694d 100644
--- a/internal/ceres/problem.cc
+++ b/internal/ceres/problem.cc
@@ -231,6 +231,10 @@
return problem_impl_->ParameterBlockLocalSize(parameter_block);
};
+bool Problem::HasParameterBlock(const double* values) const {
+ return problem_impl_->HasParameterBlock(values);
+}
+
void Problem::GetParameterBlocks(vector<double*>* parameter_blocks) const {
problem_impl_->GetParameterBlocks(parameter_blocks);
}
diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc
index d9fb2af..7c86efb 100644
--- a/internal/ceres/problem_impl.cc
+++ b/internal/ceres/problem_impl.cc
@@ -791,6 +791,11 @@
parameter_block_map_, const_cast<double*>(parameter_block))->LocalSize();
};
+bool ProblemImpl::HasParameterBlock(const double* parameter_block) const {
+ return (parameter_block_map_.find(const_cast<double*>(parameter_block)) !=
+ parameter_block_map_.end());
+}
+
void ProblemImpl::GetParameterBlocks(vector<double*>* parameter_blocks) const {
CHECK_NOTNULL(parameter_blocks);
parameter_blocks->resize(0);
diff --git a/internal/ceres/problem_impl.h b/internal/ceres/problem_impl.h
index e846c03..7b5547b 100644
--- a/internal/ceres/problem_impl.h
+++ b/internal/ceres/problem_impl.h
@@ -147,6 +147,9 @@
int ParameterBlockSize(const double* parameter_block) const;
int ParameterBlockLocalSize(const double* parameter_block) const;
+
+ bool HasParameterBlock(const double* parameter_block) const;
+
void GetParameterBlocks(vector<double*>* parameter_blocks) const;
void GetResidualBlocks(vector<ResidualBlockId>* residual_blocks) const;
diff --git a/internal/ceres/problem_test.cc b/internal/ceres/problem_test.cc
index eb75e3a..db082ec 100644
--- a/internal/ceres/problem_test.cc
+++ b/internal/ceres/problem_test.cc
@@ -556,7 +556,9 @@
EXPECT_TRUE(parameter_blocks[0] == x || parameter_blocks[0] == y);
EXPECT_TRUE(parameter_blocks[1] == x || parameter_blocks[1] == y);
+ EXPECT_TRUE(problem.HasParameterBlock(x));
problem.RemoveParameterBlock(x);
+ EXPECT_FALSE(problem.HasParameterBlock(x));
problem.GetParameterBlocks(¶meter_blocks);
EXPECT_EQ(parameter_blocks.size(), 1);
EXPECT_TRUE(parameter_blocks[0] == y);