123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "ceres/linear_solver.h"
- #include <memory>
- #include "ceres/cgnr_solver.h"
- #include "ceres/dense_normal_cholesky_solver.h"
- #include "ceres/dense_qr_solver.h"
- #include "ceres/dynamic_sparse_normal_cholesky_solver.h"
- #include "ceres/internal/config.h"
- #include "ceres/iterative_schur_complement_solver.h"
- #include "ceres/schur_complement_solver.h"
- #include "ceres/sparse_normal_cholesky_solver.h"
- #include "ceres/types.h"
- #include "glog/logging.h"
- namespace ceres::internal {
- LinearSolver::~LinearSolver() = default;
- LinearSolverType LinearSolver::LinearSolverForZeroEBlocks(
- LinearSolverType linear_solver_type) {
- if (!IsSchurType(linear_solver_type)) {
- return linear_solver_type;
- }
- if (linear_solver_type == SPARSE_SCHUR) {
- return SPARSE_NORMAL_CHOLESKY;
- }
- if (linear_solver_type == DENSE_SCHUR) {
-
-
-
- return DENSE_QR;
- }
- if (linear_solver_type == ITERATIVE_SCHUR) {
- return CGNR;
- }
- return linear_solver_type;
- }
- std::unique_ptr<LinearSolver> LinearSolver::Create(
- const LinearSolver::Options& options) {
- CHECK(options.context != nullptr);
- switch (options.type) {
- case CGNR: {
- #ifndef CERES_NO_CUDA
- if (options.sparse_linear_algebra_library_type == CUDA_SPARSE) {
- std::string error;
- return CudaCgnrSolver::Create(options, &error);
- }
- #endif
- return std::make_unique<CgnrSolver>(options);
- } break;
- case SPARSE_NORMAL_CHOLESKY:
- #if defined(CERES_NO_SPARSE)
- return nullptr;
- #else
- if (options.dynamic_sparsity) {
- return std::make_unique<DynamicSparseNormalCholeskySolver>(options);
- }
- return std::make_unique<SparseNormalCholeskySolver>(options);
- #endif
- case SPARSE_SCHUR:
- #if defined(CERES_NO_SPARSE)
- return nullptr;
- #else
- return std::make_unique<SparseSchurComplementSolver>(options);
- #endif
- case DENSE_SCHUR:
- return std::make_unique<DenseSchurComplementSolver>(options);
- case ITERATIVE_SCHUR:
- if (options.use_explicit_schur_complement) {
- return std::make_unique<SparseSchurComplementSolver>(options);
- } else {
- return std::make_unique<IterativeSchurComplementSolver>(options);
- }
- case DENSE_QR:
- return std::make_unique<DenseQRSolver>(options);
- case DENSE_NORMAL_CHOLESKY:
- return std::make_unique<DenseNormalCholeskySolver>(options);
- default:
- LOG(FATAL) << "Unknown linear solver type :" << options.type;
- return nullptr;
- }
- }
- }
|