From f258e4624f5bd86105ea28b9b92dd70a3f4a3a44 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 15 Aug 2013 14:50:08 +0600 Subject: [PATCH] Move most of suitesparse/cxsparse ifdef code to their headers Main purpose of this is to make implementation files free from endless ifdef blocks every time this libraries are needed to be included. This would hopefully prevent compilation errors in the future caused by missing ifdef around header include. This also includes some stubs added to suitesparse/cxsparse headers to make code even more free from ifdefs. Change-Id: Ic8554e7df31d8c4751583fe004b99e71b3c9087b --- internal/ceres/covariance_impl.cc | 11 ----------- internal/ceres/cxsparse.h | 5 +++++ internal/ceres/schur_complement_solver.cc | 16 ++++------------ internal/ceres/schur_complement_solver.h | 4 ---- internal/ceres/sparse_normal_cholesky_solver.cc | 16 ++++------------ internal/ceres/sparse_normal_cholesky_solver.h | 4 ---- internal/ceres/suitesparse.h | 12 ++++++++++++ internal/ceres/visibility.cc | 2 +- 8 files changed, 26 insertions(+), 44 deletions(-) diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc index ca5be4948..61feb6bde 100644 --- a/internal/ceres/covariance_impl.cc +++ b/internal/ceres/covariance_impl.cc @@ -49,10 +49,6 @@ #include "ceres/wall_time.h" #include "glog/logging.h" -#ifndef CERES_NO_SUITESPARSE -# include "SuiteSparseQR.hpp" -#endif - namespace ceres { namespace internal { namespace { @@ -607,15 +603,8 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingSparseQR() { const int num_cols = jacobian.num_cols; const int num_nonzeros = jacobian.values.size(); - // UF_long is deprecated but SuiteSparse_long is only available in - // newer versions of SuiteSparse. -#if (SUITESPARSE_VERSION < 4002) - vector transpose_rows(num_cols + 1, 0); - vector transpose_cols(num_nonzeros, 0); -#else vector transpose_rows(num_cols + 1, 0); vector transpose_cols(num_nonzeros, 0); -#endif vector transpose_values(num_nonzeros, 0); diff --git a/internal/ceres/cxsparse.h b/internal/ceres/cxsparse.h index 60043018b..cd87908a4 100644 --- a/internal/ceres/cxsparse.h +++ b/internal/ceres/cxsparse.h @@ -125,6 +125,11 @@ class CXSparse { } // namespace internal } // namespace ceres +#else // CERES_NO_CXSPARSE + +class CXSparse {}; +typedef void cs_dis; + #endif // CERES_NO_CXSPARSE #endif // CERES_INTERNAL_CXSPARSE_H_ diff --git a/internal/ceres/schur_complement_solver.cc b/internal/ceres/schur_complement_solver.cc index c21d3b5ab..b192aa117 100644 --- a/internal/ceres/schur_complement_solver.cc +++ b/internal/ceres/schur_complement_solver.cc @@ -33,16 +33,13 @@ #include #include -#ifndef CERES_NO_CXSPARSE -#include "cs.h" -#endif // CERES_NO_CXSPARSE - #include "Eigen/Dense" #include "ceres/block_random_access_dense_matrix.h" #include "ceres/block_random_access_matrix.h" #include "ceres/block_random_access_sparse_matrix.h" #include "ceres/block_sparse_matrix.h" #include "ceres/block_structure.h" +#include "ceres/cxsparse.h" #include "ceres/detect_structure.h" #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" @@ -153,14 +150,9 @@ bool DenseSchurComplementSolver::SolveReducedLinearSystem(double* solution) { SparseSchurComplementSolver::SparseSchurComplementSolver( const LinearSolver::Options& options) - : SchurComplementSolver(options) { -#ifndef CERES_NO_SUITESPARSE - factor_ = NULL; -#endif // CERES_NO_SUITESPARSE - -#ifndef CERES_NO_CXSPARSE - cxsparse_factor_ = NULL; -#endif // CERES_NO_CXSPARSE + : SchurComplementSolver(options), + factor_(NULL), + cxsparse_factor_(NULL) { } SparseSchurComplementSolver::~SparseSchurComplementSolver() { diff --git a/internal/ceres/schur_complement_solver.h b/internal/ceres/schur_complement_solver.h index 9525e37f0..b5a1c74ab 100644 --- a/internal/ceres/schur_complement_solver.h +++ b/internal/ceres/schur_complement_solver.h @@ -167,18 +167,14 @@ class SparseSchurComplementSolver : public SchurComplementSolver { // Size of the blocks in the Schur complement. vector blocks_; -#ifndef CERES_NO_SUITESPARSE SuiteSparse ss_; // Symbolic factorization of the reduced linear system. Precomputed // once and reused in subsequent calls. cholmod_factor* factor_; -#endif // CERES_NO_SUITESPARSE -#ifndef CERES_NO_CXSPARSE CXSparse cxsparse_; // Cached factorization cs_dis* cxsparse_factor_; -#endif // CERES_NO_CXSPARSE CERES_DISALLOW_COPY_AND_ASSIGN(SparseSchurComplementSolver); }; diff --git a/internal/ceres/sparse_normal_cholesky_solver.cc b/internal/ceres/sparse_normal_cholesky_solver.cc index cfb0f1749..f1a52378e 100644 --- a/internal/ceres/sparse_normal_cholesky_solver.cc +++ b/internal/ceres/sparse_normal_cholesky_solver.cc @@ -36,11 +36,8 @@ #include #include -#ifndef CERES_NO_CXSPARSE -#include "cs.h" -#endif - #include "ceres/compressed_row_sparse_matrix.h" +#include "ceres/cxsparse.h" #include "ceres/internal/eigen.h" #include "ceres/internal/scoped_ptr.h" #include "ceres/linear_solver.h" @@ -54,14 +51,9 @@ namespace internal { SparseNormalCholeskySolver::SparseNormalCholeskySolver( const LinearSolver::Options& options) - : options_(options) { -#ifndef CERES_NO_SUITESPARSE - factor_ = NULL; -#endif - -#ifndef CERES_NO_CXSPARSE - cxsparse_factor_ = NULL; -#endif // CERES_NO_CXSPARSE + : factor_(NULL), + cxsparse_factor_(NULL), + options_(options) { } SparseNormalCholeskySolver::~SparseNormalCholeskySolver() { diff --git a/internal/ceres/sparse_normal_cholesky_solver.h b/internal/ceres/sparse_normal_cholesky_solver.h index ebb32e619..61111b41b 100644 --- a/internal/ceres/sparse_normal_cholesky_solver.h +++ b/internal/ceres/sparse_normal_cholesky_solver.h @@ -73,17 +73,13 @@ class SparseNormalCholeskySolver : public CompressedRowSparseMatrixSolver { const LinearSolver::PerSolveOptions& options, double* x); -#ifndef CERES_NO_SUITESPARSE SuiteSparse ss_; // Cached factorization cholmod_factor* factor_; -#endif // CERES_NO_SUITESPARSE -#ifndef CERES_NO_CXSPARSE CXSparse cxsparse_; // Cached factorization cs_dis* cxsparse_factor_; -#endif // CERES_NO_CXSPARSE const LinearSolver::Options options_; CERES_DISALLOW_COPY_AND_ASSIGN(SparseNormalCholeskySolver); diff --git a/internal/ceres/suitesparse.h b/internal/ceres/suitesparse.h index 8a5b0a80c..c1772924d 100644 --- a/internal/ceres/suitesparse.h +++ b/internal/ceres/suitesparse.h @@ -43,6 +43,7 @@ #include "ceres/internal/port.h" #include "cholmod.h" #include "glog/logging.h" +#include "SuiteSparseQR.hpp" // Before SuiteSparse version 4.2.0, cholmod_camd was only enabled // if SuiteSparse was compiled with Metis support. This makes @@ -58,6 +59,12 @@ #define CERES_NO_CAMD #endif +// UF_long is deprecated but SuiteSparse_long is only available in +// newer versions of SuiteSparse. +#if (SUITESPARSE_VERSION < 4002) +typedef UF_long SuiteSparse_long; +#endif + namespace ceres { namespace internal { @@ -261,6 +268,11 @@ class SuiteSparse { } // namespace internal } // namespace ceres +#else // CERES_NO_SUITESPARSE + +class SuiteSparse {}; +typedef void cholmod_factor; + #endif // CERES_NO_SUITESPARSE #endif // CERES_INTERNAL_SUITESPARSE_H_ diff --git a/internal/ceres/visibility.cc b/internal/ceres/visibility.cc index fcd793c00..acfa45b86 100644 --- a/internal/ceres/visibility.cc +++ b/internal/ceres/visibility.cc @@ -153,4 +153,4 @@ Graph* CreateSchurComplementGraph(const vector >& visibility) { } // namespace internal } // namespace ceres -#endif +#endif // CERES_NO_SUITESPARSE