mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-30 09:00:37 +08:00
Expand check for lack of a sparse linear algebra library.
The LinearSolver factory was creating a NULL linear solver if only Eigen's sparse linear algebra backend was available. Thanks to Michael Samples and Domink Reitzle for reporting this. Change-Id: I35e3a6c0fd0da2a31934adb5dfe4cad29577cc73
This commit is contained in:
@@ -75,14 +75,18 @@ LinearSolver* LinearSolver::Create(const LinearSolver::Options& options) {
|
||||
return new CgnrSolver(options);
|
||||
|
||||
case SPARSE_NORMAL_CHOLESKY:
|
||||
#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE)
|
||||
#if defined(CERES_NO_SUITESPARSE) && \
|
||||
defined(CERES_NO_CXSPARSE) && \
|
||||
!defined(CERES_USE_EIGEN_SPARSE)
|
||||
return NULL;
|
||||
#else
|
||||
return new SparseNormalCholeskySolver(options);
|
||||
#endif
|
||||
|
||||
case SPARSE_SCHUR:
|
||||
#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE)
|
||||
#if defined(CERES_NO_SUITESPARSE) && \
|
||||
defined(CERES_NO_CXSPARSE) && \
|
||||
!defined(CERES_USE_EIGEN_SPARSE)
|
||||
return NULL;
|
||||
#else
|
||||
return new SparseSchurComplementSolver(options);
|
||||
|
||||
@@ -247,6 +247,14 @@ TEST(Solver, SparseNormalCholeskyNoSuiteSparse) {
|
||||
string message;
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
}
|
||||
|
||||
TEST(Solver, SparseSchurNoSuiteSparse) {
|
||||
Solver::Options options;
|
||||
options.sparse_linear_algebra_library_type = SUITE_SPARSE;
|
||||
options.linear_solver_type = SPARSE_SCHUR;
|
||||
string message;
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CERES_NO_CXSPARSE)
|
||||
@@ -257,6 +265,32 @@ TEST(Solver, SparseNormalCholeskyNoCXSparse) {
|
||||
string message;
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
}
|
||||
|
||||
TEST(Solver, SparseSchurNoCXSparse) {
|
||||
Solver::Options options;
|
||||
options.sparse_linear_algebra_library_type = CX_SPARSE;
|
||||
options.linear_solver_type = SPARSE_SCHUR;
|
||||
string message;
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(CERES_USE_EIGEN_SPARSE)
|
||||
TEST(Solver, SparseNormalCholeskyNoEigenSparse) {
|
||||
Solver::Options options;
|
||||
options.sparse_linear_algebra_library_type = EIGEN_SPARSE;
|
||||
options.linear_solver_type = SPARSE_NORMAL_CHOLESKY;
|
||||
string message;
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
}
|
||||
|
||||
TEST(Solver, SparseSchurNoEigenSparse) {
|
||||
Solver::Options options;
|
||||
options.sparse_linear_algebra_library_type = EIGEN_SPARSE;
|
||||
options.linear_solver_type = SPARSE_SCHUR;
|
||||
string message;
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(Solver, IterativeLinearSolverForDogleg) {
|
||||
@@ -284,7 +318,9 @@ TEST(Solver, LinearSolverTypeNormalOperation) {
|
||||
EXPECT_TRUE(options.IsValid(&message));
|
||||
|
||||
options.linear_solver_type = SPARSE_SCHUR;
|
||||
#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE)
|
||||
#if defined(CERES_NO_SUITESPARSE) && \
|
||||
defined(CERES_NO_CXSPARSE) && \
|
||||
!defined(CERES_USE_EIGEN_SPARSE)
|
||||
EXPECT_FALSE(options.IsValid(&message));
|
||||
#else
|
||||
EXPECT_TRUE(options.IsValid(&message));
|
||||
@@ -311,7 +347,7 @@ class DummyCostFunction : public SizedCostFunction<kNumResiduals, N1, N2, N3> {
|
||||
TEST(Solver, FixedCostForConstantProblem) {
|
||||
double x = 1.0;
|
||||
Problem problem;
|
||||
problem.AddResidualBlock(new DummyCostFunction<2,1>(), NULL, &x);
|
||||
problem.AddResidualBlock(new DummyCostFunction<2, 1>(), NULL, &x);
|
||||
problem.SetParameterBlockConstant(&x);
|
||||
const double expected_cost = 41.0 / 2.0; // 1/2 * ((4 + 0)^2 + (4 + 1)^2)
|
||||
Solver::Options options;
|
||||
|
||||
Reference in New Issue
Block a user