Check that the Dogleg Solver uses a direct solver. Change-Id: I7947361542aecded0adc0ca775b5b0011ce9fb23
diff --git a/internal/ceres/solver_impl.cc b/internal/ceres/solver_impl.cc index 877a5af..ca35adc 100644 --- a/internal/ceres/solver_impl.cc +++ b/internal/ceres/solver_impl.cc
@@ -452,6 +452,16 @@ LinearSolver* SolverImpl::CreateLinearSolver(Solver::Options* options, string* error) { + if (options->trust_region_strategy_type == DOGLEG) { + if (options->linear_solver_type == ITERATIVE_SCHUR || + options->linear_solver_type == CGNR) { + *error = "DOGLEG only supports exact factorization based linear " + "solvers. If you want to use an iterative solver please " + "use LEVENBERG_MARQUARDT as the trust_region_strategy_type"; + return NULL; + } + } + #ifdef CERES_NO_SUITESPARSE if (options->linear_solver_type == SPARSE_NORMAL_CHOLESKY && options->sparse_linear_algebra_library == SUITE_SPARSE) {
diff --git a/internal/ceres/solver_impl_test.cc b/internal/ceres/solver_impl_test.cc index 20190f1..81775fb 100644 --- a/internal/ceres/solver_impl_test.cc +++ b/internal/ceres/solver_impl_test.cc
@@ -498,6 +498,19 @@ EXPECT_EQ(options.num_linear_solver_threads, 1); } +TEST(SolverImpl, CreateIterativeLinearSolverForDogleg) { + Solver::Options options; + options.trust_region_strategy_type = DOGLEG; + string error; + options.linear_solver_type = ITERATIVE_SCHUR; + EXPECT_EQ(SolverImpl::CreateLinearSolver(&options, &error), + static_cast<LinearSolver*>(NULL)); + + options.linear_solver_type = CGNR; + EXPECT_EQ(SolverImpl::CreateLinearSolver(&options, &error), + static_cast<LinearSolver*>(NULL)); +} + TEST(SolverImpl, CreateLinearSolverNormalOperation) { Solver::Options options; scoped_ptr<LinearSolver> solver;