Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:34:45

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_SPARSEUTIL_H
0011 #define EIGEN_SPARSEUTIL_H
0012 
0013 namespace Eigen { 
0014 
0015 #ifdef NDEBUG
0016 #define EIGEN_DBG_SPARSE(X)
0017 #else
0018 #define EIGEN_DBG_SPARSE(X) X
0019 #endif
0020 
0021 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
0022 template<typename OtherDerived> \
0023 EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) \
0024 { \
0025   return Base::operator Op(other.derived()); \
0026 } \
0027 EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \
0028 { \
0029   return Base::operator Op(other); \
0030 }
0031 
0032 #define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
0033 template<typename Other> \
0034 EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \
0035 { \
0036   return Base::operator Op(scalar); \
0037 }
0038 
0039 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
0040 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =)
0041 
0042 
0043 #define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \
0044   EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
0045 
0046   
0047 const int CoherentAccessPattern     = 0x1;
0048 const int InnerRandomAccessPattern  = 0x2 | CoherentAccessPattern;
0049 const int OuterRandomAccessPattern  = 0x4 | CoherentAccessPattern;
0050 const int RandomAccessPattern       = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
0051 
0052 template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int>  class SparseMatrix;
0053 template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int>  class DynamicSparseMatrix;
0054 template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int>  class SparseVector;
0055 template<typename _Scalar, int _Flags = 0, typename _StorageIndex = int>  class MappedSparseMatrix;
0056 
0057 template<typename MatrixType, unsigned int UpLo>  class SparseSelfAdjointView;
0058 template<typename Lhs, typename Rhs>              class SparseDiagonalProduct;
0059 template<typename MatrixType> class SparseView;
0060 
0061 template<typename Lhs, typename Rhs>        class SparseSparseProduct;
0062 template<typename Lhs, typename Rhs>        class SparseTimeDenseProduct;
0063 template<typename Lhs, typename Rhs>        class DenseTimeSparseProduct;
0064 template<typename Lhs, typename Rhs, bool Transpose> class SparseDenseOuterProduct;
0065 
0066 template<typename Lhs, typename Rhs> struct SparseSparseProductReturnType;
0067 template<typename Lhs, typename Rhs,
0068          int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct DenseSparseProductReturnType;
0069          
0070 template<typename Lhs, typename Rhs,
0071          int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct SparseDenseProductReturnType;
0072 template<typename MatrixType,int UpLo> class SparseSymmetricPermutationProduct;
0073 
0074 namespace internal {
0075 
0076 template<typename T,int Rows,int Cols,int Flags> struct sparse_eval;
0077 
0078 template<typename T> struct eval<T,Sparse>
0079   : sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime,traits<T>::Flags>
0080 {};
0081 
0082 template<typename T,int Cols,int Flags> struct sparse_eval<T,1,Cols,Flags> {
0083     typedef typename traits<T>::Scalar _Scalar;
0084     typedef typename traits<T>::StorageIndex _StorageIndex;
0085   public:
0086     typedef SparseVector<_Scalar, RowMajor, _StorageIndex> type;
0087 };
0088 
0089 template<typename T,int Rows,int Flags> struct sparse_eval<T,Rows,1,Flags> {
0090     typedef typename traits<T>::Scalar _Scalar;
0091     typedef typename traits<T>::StorageIndex _StorageIndex;
0092   public:
0093     typedef SparseVector<_Scalar, ColMajor, _StorageIndex> type;
0094 };
0095 
0096 // TODO this seems almost identical to plain_matrix_type<T, Sparse>
0097 template<typename T,int Rows,int Cols,int Flags> struct sparse_eval {
0098     typedef typename traits<T>::Scalar _Scalar;
0099     typedef typename traits<T>::StorageIndex _StorageIndex;
0100     enum { _Options = ((Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
0101   public:
0102     typedef SparseMatrix<_Scalar, _Options, _StorageIndex> type;
0103 };
0104 
0105 template<typename T,int Flags> struct sparse_eval<T,1,1,Flags> {
0106     typedef typename traits<T>::Scalar _Scalar;
0107   public:
0108     typedef Matrix<_Scalar, 1, 1> type;
0109 };
0110 
0111 template<typename T> struct plain_matrix_type<T,Sparse>
0112 {
0113   typedef typename traits<T>::Scalar _Scalar;
0114   typedef typename traits<T>::StorageIndex _StorageIndex;
0115   enum { _Options = ((evaluator<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
0116   public:
0117     typedef SparseMatrix<_Scalar, _Options, _StorageIndex> type;
0118 };
0119 
0120 template<typename T>
0121 struct plain_object_eval<T,Sparse>
0122   : sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime, evaluator<T>::Flags>
0123 {};
0124 
0125 template<typename Decomposition, typename RhsType>
0126 struct solve_traits<Decomposition,RhsType,Sparse>
0127 {
0128   typedef typename sparse_eval<RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime,traits<RhsType>::Flags>::type PlainObject;
0129 };
0130 
0131 template<typename Derived>
0132 struct generic_xpr_base<Derived, MatrixXpr, Sparse>
0133 {
0134   typedef SparseMatrixBase<Derived> type;
0135 };
0136 
0137 struct SparseTriangularShape  { static std::string debugName() { return "SparseTriangularShape"; } };
0138 struct SparseSelfAdjointShape { static std::string debugName() { return "SparseSelfAdjointShape"; } };
0139 
0140 template<> struct glue_shapes<SparseShape,SelfAdjointShape> { typedef SparseSelfAdjointShape type;  };
0141 template<> struct glue_shapes<SparseShape,TriangularShape > { typedef SparseTriangularShape  type;  };
0142 
0143 // return type of SparseCompressedBase::lower_bound;
0144 struct LowerBoundIndex {
0145   LowerBoundIndex() : value(-1), found(false) {}
0146   LowerBoundIndex(Index val, bool ok) : value(val), found(ok) {}
0147   Index value;
0148   bool found;
0149 };
0150 
0151 } // end namespace internal
0152 
0153 /** \ingroup SparseCore_Module
0154   *
0155   * \class Triplet
0156   *
0157   * \brief A small structure to hold a non zero as a triplet (i,j,value).
0158   *
0159   * \sa SparseMatrix::setFromTriplets()
0160   */
0161 template<typename Scalar, typename StorageIndex=typename SparseMatrix<Scalar>::StorageIndex >
0162 class Triplet
0163 {
0164 public:
0165   Triplet() : m_row(0), m_col(0), m_value(0) {}
0166 
0167   Triplet(const StorageIndex& i, const StorageIndex& j, const Scalar& v = Scalar(0))
0168     : m_row(i), m_col(j), m_value(v)
0169   {}
0170 
0171   /** \returns the row index of the element */
0172   const StorageIndex& row() const { return m_row; }
0173 
0174   /** \returns the column index of the element */
0175   const StorageIndex& col() const { return m_col; }
0176 
0177   /** \returns the value of the element */
0178   const Scalar& value() const { return m_value; }
0179 protected:
0180   StorageIndex m_row, m_col;
0181   Scalar m_value;
0182 };
0183 
0184 } // end namespace Eigen
0185 
0186 #endif // EIGEN_SPARSEUTIL_H