SparseUtil.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_SPARSEUTIL_H
00011 #define EIGEN_SPARSEUTIL_H
00012 
00013 namespace Eigen { 
00014 
00015 #ifdef NDEBUG
00016 #define EIGEN_DBG_SPARSE(X)
00017 #else
00018 #define EIGEN_DBG_SPARSE(X) X
00019 #endif
00020 
00021 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
00022 template<typename OtherDerived> \
00023 EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) \
00024 { \
00025   return Base::operator Op(other.derived()); \
00026 } \
00027 EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \
00028 { \
00029   return Base::operator Op(other); \
00030 }
00031 
00032 #define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
00033 template<typename Other> \
00034 EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \
00035 { \
00036   return Base::operator Op(scalar); \
00037 }
00038 
00039 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
00040 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \
00041 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \
00042 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
00043 EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
00044 EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
00045 
00046 #define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \
00047   typedef BaseClass Base; \
00048   typedef typename Eigen::internal::traits<Derived >::Scalar Scalar; \
00049   typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
00050   typedef typename Eigen::internal::nested<Derived >::type Nested; \
00051   typedef typename Eigen::internal::traits<Derived >::StorageKind StorageKind; \
00052   typedef typename Eigen::internal::traits<Derived >::Index Index; \
00053   enum { RowsAtCompileTime = Eigen::internal::traits<Derived >::RowsAtCompileTime, \
00054         ColsAtCompileTime = Eigen::internal::traits<Derived >::ColsAtCompileTime, \
00055         Flags = Eigen::internal::traits<Derived >::Flags, \
00056         CoeffReadCost = Eigen::internal::traits<Derived >::CoeffReadCost, \
00057         SizeAtCompileTime = Base::SizeAtCompileTime, \
00058         IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
00059   using Base::derived; \
00060   using Base::const_cast_derived;
00061 
00062 #define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \
00063   _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived >)
00064 
00065 const int CoherentAccessPattern     = 0x1;
00066 const int InnerRandomAccessPattern  = 0x2 | CoherentAccessPattern;
00067 const int OuterRandomAccessPattern  = 0x4 | CoherentAccessPattern;
00068 const int RandomAccessPattern       = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
00069 
00070 template<typename Derived> class SparseMatrixBase;
00071 template<typename _Scalar, int _Flags = 0, typename _Index = int>  class SparseMatrix;
00072 template<typename _Scalar, int _Flags = 0, typename _Index = int>  class DynamicSparseMatrix;
00073 template<typename _Scalar, int _Flags = 0, typename _Index = int>  class SparseVector;
00074 template<typename _Scalar, int _Flags = 0, typename _Index = int>  class MappedSparseMatrix;
00075 
00076 template<typename MatrixType, int Mode>           class SparseTriangularView;
00077 template<typename MatrixType, unsigned int UpLo>  class SparseSelfAdjointView;
00078 template<typename Lhs, typename Rhs>              class SparseDiagonalProduct;
00079 template<typename MatrixType> class SparseView;
00080 
00081 template<typename Lhs, typename Rhs>        class SparseSparseProduct;
00082 template<typename Lhs, typename Rhs>        class SparseTimeDenseProduct;
00083 template<typename Lhs, typename Rhs>        class DenseTimeSparseProduct;
00084 template<typename Lhs, typename Rhs, bool Transpose> class SparseDenseOuterProduct;
00085 
00086 template<typename Lhs, typename Rhs> struct SparseSparseProductReturnType;
00087 template<typename Lhs, typename Rhs, int InnerSize = internal::traits<Lhs>::ColsAtCompileTime> struct DenseSparseProductReturnType;
00088 template<typename Lhs, typename Rhs, int InnerSize = internal::traits<Lhs>::ColsAtCompileTime> struct SparseDenseProductReturnType;
00089 template<typename MatrixType,int UpLo> class SparseSymmetricPermutationProduct;
00090 
00091 namespace internal {
00092 
00093 template<typename T,int Rows,int Cols> struct sparse_eval;
00094 
00095 template<typename T> struct eval<T,Sparse>
00096   : public sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime>
00097 {};
00098 
00099 template<typename T,int Cols> struct sparse_eval<T,1,Cols> {
00100     typedef typename traits<T>::Scalar _Scalar;
00101     typedef typename traits<T>::Index _Index;
00102   public:
00103     typedef SparseVector<_Scalar, RowMajor, _Index> type;
00104 };
00105 
00106 template<typename T,int Rows> struct sparse_eval<T,Rows,1> {
00107     typedef typename traits<T>::Scalar _Scalar;
00108     typedef typename traits<T>::Index _Index;
00109   public:
00110     typedef SparseVector<_Scalar, ColMajor, _Index> type;
00111 };
00112 
00113 template<typename T,int Rows,int Cols> struct sparse_eval {
00114     typedef typename traits<T>::Scalar _Scalar;
00115     typedef typename traits<T>::Index _Index;
00116     enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
00117   public:
00118     typedef SparseMatrix<_Scalar, _Options, _Index> type;
00119 };
00120 
00121 template<typename T> struct sparse_eval<T,1,1> {
00122     typedef typename traits<T>::Scalar _Scalar;
00123   public:
00124     typedef Matrix<_Scalar, 1, 1> type;
00125 };
00126 
00127 template<typename T> struct plain_matrix_type<T,Sparse>
00128 {
00129   typedef typename traits<T>::Scalar _Scalar;
00130   typedef typename traits<T>::Index _Index;
00131   enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
00132   public:
00133     typedef SparseMatrix<_Scalar, _Options, _Index> type;
00134 };
00135 
00136 } // end namespace internal
00137 
00146 template<typename Scalar, typename Index=unsigned int>
00147 class Triplet
00148 {
00149 public:
00150   Triplet() : m_row(0), m_col(0), m_value(0) {}
00151 
00152   Triplet(const Index& i, const Index& j, const Scalar& v = Scalar(0))
00153     : m_row(i), m_col(j), m_value(v)
00154   {}
00155 
00157   const Index& row() const { return m_row; }
00158 
00160   const Index& col() const { return m_col; }
00161 
00163   const Scalar& value() const { return m_value; }
00164 protected:
00165   Index m_row, m_col;
00166   Scalar m_value;
00167 };
00168 
00169 } // end namespace Eigen
00170 
00171 #endif // EIGEN_SPARSEUTIL_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:39:42