Stricter checking of Solver::Option::num_eliminate_blocks. Change-Id: Ic8e61cedbe0eb028a32c89f77dc6b838d3a8caa4
diff --git a/internal/ceres/solver_impl.cc b/internal/ceres/solver_impl.cc index 2802a75..5d253dd 100644 --- a/internal/ceres/solver_impl.cc +++ b/internal/ceres/solver_impl.cc
@@ -215,13 +215,26 @@ } if (options.num_linear_solver_threads > 1) { LOG(WARNING) - << "OpenMP support is not compiled into this binary; " + << "OpenMP support is not compiled into this binary" << "only options.num_linear_solver_threads=1 is supported. Switching" << "to single threaded mode."; options.num_linear_solver_threads = 1; } #endif + if (IsSchurType(options.linear_solver_type) && + options.ordering_type != SCHUR && + options.num_eliminate_blocks < 1) { + summary->error = + StringPrintf("Using a Schur type solver with %s" + " ordering requires that" + " Solver::Options::num_eliminate_blocks" + " be set to a positive integer.", + OrderingTypeToString(options.ordering_type)); + LOG(WARNING) << summary->error; + return; + } + summary->linear_solver_type_given = options.linear_solver_type; summary->num_eliminate_blocks_given = original_options.num_eliminate_blocks; summary->num_threads_given = original_options.num_threads; @@ -275,7 +288,6 @@ // Create the three objects needed to minimize: the transformed program, the // evaluator, and the linear solver. - scoped_ptr<Program> reduced_program(CreateReducedProgram(&options, problem_impl, &summary->fixed_cost,
diff --git a/internal/ceres/solver_impl_test.cc b/internal/ceres/solver_impl_test.cc index 76ece8d..7d7740a 100644 --- a/internal/ceres/solver_impl_test.cc +++ b/internal/ceres/solver_impl_test.cc
@@ -542,6 +542,18 @@ #endif } +TEST(SolverImpl, ZeroNumEliminateBlocks) { + Solver::Options options; + options.num_eliminate_blocks = 0; + options.linear_solver_type = DENSE_SCHUR; + options.ordering_type = NATURAL; + ProblemImpl problem; + Solver::Summary summary; + SolverImpl::Solve(options, &problem, &summary); + EXPECT_EQ(summary.termination_type, DID_NOT_RUN); + EXPECT_EQ(summary.error.substr(0,25), "Using a Schur type solver"); +} + TEST(SolverImpl, CreateLinearSolverDenseSchurMultipleThreads) { Solver::Options options; options.num_eliminate_blocks = 1;