SparseSolverBase.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SPARSESOLVERBASE_H
11 #define EIGEN_SPARSESOLVERBASE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
21 template<typename Decomposition, typename Rhs, typename Dest>
23 solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest)
24 {
25  EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
26  typedef typename Dest::Scalar DestScalar;
27  // we process the sparse rhs per block of NbColsAtOnce columns temporarily stored into a dense matrix.
28  static const Index NbColsAtOnce = 4;
29  Index rhsCols = rhs.cols();
30  Index size = rhs.rows();
31  // the temporary matrices do not need more columns than NbColsAtOnce:
32  Index tmpCols = (std::min)(rhsCols, NbColsAtOnce);
35  for(Index k=0; k<rhsCols; k+=NbColsAtOnce)
36  {
37  Index actualCols = std::min<Index>(rhsCols-k, NbColsAtOnce);
38  tmp.leftCols(actualCols) = rhs.middleCols(k,actualCols);
39  tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols));
40  dest.middleCols(k,actualCols) = tmpX.leftCols(actualCols).sparseView();
41  }
42 }
43 
44 // Overload for vector as rhs
45 template<typename Decomposition, typename Rhs, typename Dest>
47 solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest)
48 {
49  typedef typename Dest::Scalar DestScalar;
50  Index size = rhs.rows();
53  dest_dense = dec.solve(rhs_dense);
54  dest = dest_dense.sparseView();
55 }
56 
57 } // end namespace internal
58 
66 template<typename Derived>
68 {
69  public:
70 
73  : m_isInitialized(false)
74  {}
75 
77  {}
78 
79  Derived& derived() { return *static_cast<Derived*>(this); }
80  const Derived& derived() const { return *static_cast<const Derived*>(this); }
81 
86  template<typename Rhs>
87  inline const Solve<Derived, Rhs>
88  solve(const MatrixBase<Rhs>& b) const
89  {
90  eigen_assert(m_isInitialized && "Solver is not initialized.");
91  eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
92  return Solve<Derived, Rhs>(derived(), b.derived());
93  }
94 
99  template<typename Rhs>
100  inline const Solve<Derived, Rhs>
102  {
103  eigen_assert(m_isInitialized && "Solver is not initialized.");
104  eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
105  return Solve<Derived, Rhs>(derived(), b.derived());
106  }
107 
108  #ifndef EIGEN_PARSED_BY_DOXYGEN
109 
110  template<typename Rhs,typename Dest>
112  {
114  }
115  #endif // EIGEN_PARSED_BY_DOXYGEN
116 
117  protected:
118 
119  mutable bool m_isInitialized;
120 };
121 
122 } // end namespace Eigen
123 
124 #endif // EIGEN_SPARSESOLVERBASE_H
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::noncopyable
Definition: Meta.h:422
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::SparseSolverBase::_solve_impl
void _solve_impl(const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
Definition: SparseSolverBase.h:111
Eigen::SparseSolverBase::~SparseSolverBase
~SparseSolverBase()
Definition: SparseSolverBase.h:76
b
Scalar * b
Definition: benchVecAdd.cpp:17
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::SparseSolverBase::solve
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SparseSolverBase.h:88
Eigen::SparseSolverBase::SparseSolverBase
SparseSolverBase()
Definition: SparseSolverBase.h:72
Eigen::SparseSolverBase
A base class for sparse solvers.
Definition: SparseSolverBase.h:67
Eigen::Solve
Pseudo expression representing a solving operation.
Definition: Solve.h:62
EIGEN_STATIC_ASSERT
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Eigen::SparseSolverBase::derived
Derived & derived()
Definition: SparseSolverBase.h:79
Eigen::internal::Rhs
@ Rhs
Definition: TensorContractionMapper.h:18
Eigen::internal::solve_sparse_through_dense_panels
enable_if< Rhs::ColsAtCompileTime!=1 &&Dest::ColsAtCompileTime!=1 >::type solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs &rhs, Dest &dest)
Definition: SparseSolverBase.h:23
Eigen::SparseMatrixBase
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:301
Eigen::SparseMatrixBase::derived
const Derived & derived() const
Definition: SparseMatrixBase.h:143
min
#define min(a, b)
Definition: datatypes.h:19
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
Eigen::SparseSolverBase::solve
const Solve< Derived, Rhs > solve(const SparseMatrixBase< Rhs > &b) const
Definition: SparseSolverBase.h:101
internal
Definition: BandTriangularSolver.h:13
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::internal::size
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::SparseSolverBase::m_isInitialized
bool m_isInitialized
Definition: SparseSolverBase.h:119


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:47