ordering -> linear_solver_ordering. Change-Id: If4af72da90725db2a2d4f397f4cb671c2e863a98
diff --git a/docs/changes.tex b/docs/changes.tex index ef899d6..a57d4dd 100644 --- a/docs/changes.tex +++ b/docs/changes.tex
@@ -28,12 +28,12 @@ \subsubsection{After} \begin{minted}[mathescape]{c++} options.linear_solver_type = ceres::DENSE_SCHUR; -options.ordering = new ceres::Ordering; +options.ordering = new ceres::ParameterBlockOrdering; for (int i = 0; i < num_points; ++i) { - options.ordering.AddElementToGroup(my_points[i], 0); + options.linear_solver_ordering->AddElementToGroup(my_points[i], 0); } for (int i = 0; i < num_cameras; ++i) { - options.ordering.AddElementToGroup(my_cameras[i], 1); + options.linear_solver_ordering->AddElementToGroup(my_cameras[i], 1); } \end{minted} \subsection{New Features}
diff --git a/docs/solving.tex b/docs/solving.tex index 4fe8356..ee8a3b8 100644 --- a/docs/solving.tex +++ b/docs/solving.tex
@@ -371,7 +371,7 @@ exact order in which the variables should be eliminated, and a variety of possibilities in between. -Instances of the \texttt{Ordering} class are used to communicate this +Instances of the \texttt{ParameterBlockOrdering} class are used to communicate this information to Ceres. Formally an ordering is an ordered partitioning of the parameter @@ -564,10 +564,10 @@ the inner optimization phase. Each group must be an independent set. \end{enumerate} -\item{\texttt{ordering} (\texttt{NULL})} An instance of the ordering - object informs the solver about the desired order in which parameter - blocks should be eliminated by the linear solvers. See - section~\ref{sec:ordering} for more details. +\item{\texttt{linear\_solver\_ordering} (\texttt{NULL})} An instance + of the ordering object informs the solver about the desired order in + which parameter blocks should be eliminated by the linear + solvers. See section~\ref{sec:ordering} for more details. If \texttt{NULL}, the solver is free to choose an ordering that it thinks is best. Note: currently, this option only has an effect on
diff --git a/examples/bundle_adjuster.cc b/examples/bundle_adjuster.cc index b24962a..78dbd01 100644 --- a/examples/bundle_adjuster.cc +++ b/examples/bundle_adjuster.cc
@@ -215,7 +215,7 @@ } } - options->ordering = ordering; + options->linear_solver_ordering = ordering; } void SetMinimizerOptions(Solver::Options* options) {
diff --git a/include/ceres/solver.h b/include/ceres/solver.h index eb882ab..62fb087 100644 --- a/include/ceres/solver.h +++ b/include/ceres/solver.h
@@ -96,7 +96,7 @@ #else use_block_amd = true; #endif - ordering = NULL; + linear_solver_ordering = NULL; use_inner_iterations = false; inner_iteration_ordering = NULL; linear_solver_min_num_iterations = 1; @@ -300,7 +300,7 @@ // // Once assigned, Solver::Options owns this pointer and will // deallocate the memory when destroyed. - ParameterBlockOrdering* ordering; + ParameterBlockOrdering* linear_solver_ordering; // By virtue of the modeling layer in Ceres being block oriented, // all the matrices used by Ceres are also block oriented. When
diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc index a6c804b..450a710 100644 --- a/internal/ceres/solver.cc +++ b/internal/ceres/solver.cc
@@ -42,7 +42,7 @@ namespace ceres { Solver::Options::~Options() { - delete ordering; + delete linear_solver_ordering; delete inner_iteration_ordering; }
diff --git a/internal/ceres/solver_impl.cc b/internal/ceres/solver_impl.cc index 03fe921..ea697e2 100644 --- a/internal/ceres/solver_impl.cc +++ b/internal/ceres/solver_impl.cc
@@ -206,7 +206,7 @@ double solver_start_time = WallTimeInSeconds(); Solver::Options options(original_options); - options.ordering = NULL; + options.linear_solver_ordering = NULL; options.inner_iteration_ordering = NULL; Program* original_program = original_problem_impl->mutable_program(); @@ -252,20 +252,21 @@ summary->trust_region_strategy_type = options.trust_region_strategy_type; summary->dogleg_type = options.dogleg_type; - if (original_options.ordering != NULL) { + if (original_options.linear_solver_ordering != NULL) { if (!IsOrderingValid(original_options, problem_impl, &summary->error)) { LOG(WARNING) << summary->error; return; } - options.ordering = new ParameterBlockOrdering(*original_options.ordering); + options.linear_solver_ordering = + new ParameterBlockOrdering(*original_options.linear_solver_ordering); } else { - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; const ProblemImpl::ParameterMap& parameter_map = problem_impl->parameter_map(); for (ProblemImpl::ParameterMap::const_iterator it = parameter_map.begin(); it != parameter_map.end(); ++it) { - options.ordering->AddElementToGroup(it->first, 0); + options.linear_solver_ordering->AddElementToGroup(it->first, 0); } } @@ -331,7 +332,9 @@ // Only Schur types require the lexicographic reordering. if (IsSchurType(options.linear_solver_type)) { const int num_eliminate_blocks = - options.ordering->group_to_elements().begin()->second.size(); + options.linear_solver_ordering + ->group_to_elements().begin() + ->second.size(); if (!LexicographicallyOrderResidualBlocks(num_eliminate_blocks, reduced_program.get(), &summary->error)) { @@ -449,7 +452,7 @@ bool SolverImpl::IsOrderingValid(const Solver::Options& options, const ProblemImpl* problem_impl, string* error) { - if (options.ordering->NumElements() != + if (options.linear_solver_ordering->NumElements() != problem_impl->NumParameterBlocks()) { *error = "Number of parameter blocks in user supplied ordering " "does not match the number of parameter blocks in the problem"; @@ -461,7 +464,8 @@ for (vector<ParameterBlock*>::const_iterator it = parameter_blocks.begin(); it != parameter_blocks.end(); ++it) { - if (!options.ordering->IsMember(const_cast<double*>((*it)->user_state()))) { + if (!options.linear_solver_ordering + ->IsMember(const_cast<double*>((*it)->user_state()))) { *error = "Problem contains a parameter block that is not in " "the user specified ordering."; return false; @@ -469,10 +473,10 @@ } if (IsSchurType(options.linear_solver_type) && - options.ordering->NumGroups() > 1) { + options.linear_solver_ordering->NumGroups() > 1) { const vector<ResidualBlock*>& residual_blocks = program.residual_blocks(); const set<double*>& e_blocks = - options.ordering->group_to_elements().begin()->second; + options.linear_solver_ordering->group_to_elements().begin()->second; if (!IsParameterBlockSetIndependent(e_blocks, residual_blocks)) { *error = "The user requested the use of a Schur type solver. " "But the first elimination group in the ordering is not an " @@ -597,17 +601,18 @@ ProblemImpl* problem_impl, double* fixed_cost, string* error) { - CHECK_NOTNULL(options->ordering); + CHECK_NOTNULL(options->linear_solver_ordering); Program* original_program = problem_impl->mutable_program(); scoped_ptr<Program> transformed_program(new Program(*original_program)); - ParameterBlockOrdering* ordering = options->ordering; + ParameterBlockOrdering* linear_solver_ordering = + options->linear_solver_ordering; const int min_group_id = - ordering->group_to_elements().begin()->first; - const int original_num_groups = ordering->NumGroups(); + linear_solver_ordering->group_to_elements().begin()->first; + const int original_num_groups = linear_solver_ordering->NumGroups(); if (!RemoveFixedBlocksFromProgram(transformed_program.get(), - ordering, + linear_solver_ordering, fixed_cost, error)) { return NULL; @@ -619,12 +624,12 @@ return transformed_program.release(); } - // If the user supplied an ordering with just one group, it is - // equivalent to the user supplying NULL as ordering. Ceres is - // completely free to choose the parameter block ordering as it sees - // fit. For Schur type solvers, this means that the user wishes for - // Ceres to identify the e_blocks, which we do by computing a - // maximal independent set. + // If the user supplied an linear_solver_ordering with just one + // group, it is equivalent to the user supplying NULL as + // ordering. Ceres is completely free to choose the parameter block + // ordering as it sees fit. For Schur type solvers, this means that + // the user wishes for Ceres to identify the e_blocks, which we do + // by computing a maximal independent set. if (original_num_groups == 1 && IsSchurType(options->linear_solver_type)) { vector<ParameterBlock*> schur_ordering; const int num_eliminate_blocks = ComputeSchurOrdering(*transformed_program, @@ -634,21 +639,22 @@ << "to the developers."; for (int i = 0; i < schur_ordering.size(); ++i) { - ordering->AddElementToGroup(schur_ordering[i]->mutable_user_state(), - (i < num_eliminate_blocks) ? 0 : 1); + linear_solver_ordering->AddElementToGroup( + schur_ordering[i]->mutable_user_state(), + (i < num_eliminate_blocks) ? 0 : 1); } } if (!ApplyUserOrdering(problem_impl->parameter_map(), - ordering, + linear_solver_ordering, transformed_program.get(), error)) { return NULL; } // If the user requested the use of a Schur type solver, and - // supplied a non-NULL ordering object with more than one - // elimimation group, then it can happen that after all the + // supplied a non-NULL linear_solver_ordering object with more than + // one elimimation group, then it can happen that after all the // parameter blocks which are fixed or unused have been removed from // the program and the ordering, there are no more parameter blocks // in the first elimination group. @@ -659,7 +665,7 @@ // the user's indicated preferences. if (IsSchurType(options->linear_solver_type) && original_num_groups > 1 && - ordering->GroupSize(min_group_id) == 0) { + linear_solver_ordering->GroupSize(min_group_id) == 0) { string msg = "No e_blocks remaining. Switching from "; if (options->linear_solver_type == SPARSE_SCHUR) { options->linear_solver_type = SPARSE_NORMAL_CHOLESKY; @@ -694,7 +700,7 @@ LinearSolver* SolverImpl::CreateLinearSolver(Solver::Options* options, string* error) { CHECK_NOTNULL(options); - CHECK_NOTNULL(options->ordering); + CHECK_NOTNULL(options->linear_solver_ordering); CHECK_NOTNULL(error); if (options->trust_region_strategy_type == DOGLEG) { @@ -795,7 +801,7 @@ linear_solver_options.use_block_amd = options->use_block_amd; const map<int, set<double*> >& groups = - options->ordering->group_to_elements(); + options->linear_solver_ordering->group_to_elements(); for (map<int, set<double*> >::const_iterator it = groups.begin(); it != groups.end(); ++it) { @@ -963,9 +969,11 @@ Evaluator::Options evaluator_options; evaluator_options.linear_solver_type = options.linear_solver_type; evaluator_options.num_eliminate_blocks = - (options.ordering->NumGroups() > 0 && + (options.linear_solver_ordering->NumGroups() > 0 && IsSchurType(options.linear_solver_type)) - ? options.ordering->group_to_elements().begin()->second.size() + ? (options.linear_solver_ordering + ->group_to_elements().begin() + ->second.size()) : 0; evaluator_options.num_threads = options.num_threads; return Evaluator::Create(evaluator_options, program, error);
diff --git a/internal/ceres/solver_impl_test.cc b/internal/ceres/solver_impl_test.cc index 9b01766..d4cc82b 100644 --- a/internal/ceres/solver_impl_test.cc +++ b/internal/ceres/solver_impl_test.cc
@@ -280,7 +280,7 @@ Solver::Options options; options.linear_solver_type = DENSE_SCHUR; - options.ordering = ordering; + options.linear_solver_ordering = ordering; const vector<ResidualBlock*>& residual_blocks = problem.program().residual_blocks(); @@ -342,7 +342,7 @@ Solver::Options options; options.linear_solver_type = DENSE_SCHUR; - options.ordering = ordering; + options.linear_solver_ordering = ordering; // Create the reduced program. This should remove the fixed block "z", // marking the index to -1 at the same time. x and y also get indices. @@ -416,7 +416,7 @@ Solver::Options options; options.linear_solver_type = DENSE_SCHUR; - options.ordering = ordering; + options.linear_solver_ordering = ordering; string error; scoped_ptr<Program> reduced_program( @@ -509,7 +509,7 @@ options.linear_solver_type = DENSE_QR; options.linear_solver_max_num_iterations = -1; // CreateLinearSolver assumes a non-empty ordering. - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; string error; EXPECT_EQ(SolverImpl::CreateLinearSolver(&options, &error), static_cast<LinearSolver*>(NULL)); @@ -520,7 +520,7 @@ options.linear_solver_type = DENSE_QR; options.linear_solver_min_num_iterations = -1; // CreateLinearSolver assumes a non-empty ordering. - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; string error; EXPECT_EQ(SolverImpl::CreateLinearSolver(&options, &error), static_cast<LinearSolver*>(NULL)); @@ -531,7 +531,7 @@ options.linear_solver_type = DENSE_QR; options.linear_solver_min_num_iterations = 10; options.linear_solver_max_num_iterations = 5; - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; string error; EXPECT_EQ(SolverImpl::CreateLinearSolver(&options, &error), static_cast<LinearSolver*>(NULL)); @@ -543,11 +543,11 @@ options.num_linear_solver_threads = 2; // The Schur type solvers can only be created with the Ordering // contains at least one elimination group. - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; double x; double y; - options.ordering->AddElementToGroup(&x, 0); - options.ordering->AddElementToGroup(&y, 0); + options.linear_solver_ordering->AddElementToGroup(&x, 0); + options.linear_solver_ordering->AddElementToGroup(&y, 0); string error; scoped_ptr<LinearSolver> solver( @@ -561,7 +561,7 @@ Solver::Options options; options.trust_region_strategy_type = DOGLEG; // CreateLinearSolver assumes a non-empty ordering. - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; string error; options.linear_solver_type = ITERATIVE_SCHUR; EXPECT_EQ(SolverImpl::CreateLinearSolver(&options, &error), @@ -577,7 +577,7 @@ scoped_ptr<LinearSolver> solver; options.linear_solver_type = DENSE_QR; // CreateLinearSolver assumes a non-empty ordering. - options.ordering = new ParameterBlockOrdering; + options.linear_solver_ordering = new ParameterBlockOrdering; string error; solver.reset(SolverImpl::CreateLinearSolver(&options, &error)); EXPECT_EQ(options.linear_solver_type, DENSE_QR); @@ -606,8 +606,8 @@ double x; double y; - options.ordering->AddElementToGroup(&x, 0); - options.ordering->AddElementToGroup(&y, 0); + options.linear_solver_ordering->AddElementToGroup(&x, 0); + options.linear_solver_ordering->AddElementToGroup(&y, 0); options.linear_solver_type = DENSE_SCHUR; solver.reset(SolverImpl::CreateLinearSolver(&options, &error));
diff --git a/internal/ceres/system_test.cc b/internal/ceres/system_test.cc index 8f1722a..4548bd0 100644 --- a/internal/ceres/system_test.cc +++ b/internal/ceres/system_test.cc
@@ -138,8 +138,8 @@ options.return_final_residuals = true; if (config.use_automatic_ordering) { - delete options.ordering; - options.ordering = NULL; + delete options.linear_solver_ordering; + options.linear_solver_ordering = NULL; } LOG(INFO) << "Running solver configuration: " @@ -387,15 +387,15 @@ problem_.AddResidualBlock(cost_function, NULL, camera, point); } - options_.ordering = new ParameterBlockOrdering; + options_.linear_solver_ordering = new ParameterBlockOrdering; // The points come before the cameras. for (int i = 0; i < num_points_; ++i) { - options_.ordering->AddElementToGroup(points + 3 * i, 0); + options_.linear_solver_ordering->AddElementToGroup(points + 3 * i, 0); } for (int i = 0; i < num_cameras_; ++i) { - options_.ordering->AddElementToGroup(cameras + 9 * i, 1); + options_.linear_solver_ordering->AddElementToGroup(cameras + 9 * i, 1); } options_.max_num_iterations = 25;