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 Size>           class SparseInnerVectorSet;
00077 template<typename MatrixType, int Mode>           class SparseTriangularView;
00078 template<typename MatrixType, unsigned int UpLo>  class SparseSelfAdjointView;
00079 template<typename Lhs, typename Rhs>              class SparseDiagonalProduct;
00080 template<typename MatrixType> class SparseView;
00081 
00082 template<typename Lhs, typename Rhs>        class SparseSparseProduct;
00083 template<typename Lhs, typename Rhs>        class SparseTimeDenseProduct;
00084 template<typename Lhs, typename Rhs>        class DenseTimeSparseProduct;
00085 template<typename Lhs, typename Rhs, bool Transpose> class SparseDenseOuterProduct;
00086 
00087 template<typename Lhs, typename Rhs> struct SparseSparseProductReturnType;
00088 template<typename Lhs, typename Rhs, int InnerSize = internal::traits<Lhs>::ColsAtCompileTime> struct DenseSparseProductReturnType;
00089 template<typename Lhs, typename Rhs, int InnerSize = internal::traits<Lhs>::ColsAtCompileTime> struct SparseDenseProductReturnType;
00090 template<typename MatrixType,int UpLo> class SparseSymmetricPermutationProduct;
00091 
00092 namespace internal {
00093 
00094 template<typename T,int Rows,int Cols> struct sparse_eval;
00095 
00096 template<typename T> struct eval<T,Sparse>
00097   : public sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime>
00098 {};
00099 
00100 template<typename T,int Cols> struct sparse_eval<T,1,Cols> {
00101     typedef typename traits<T>::Scalar _Scalar;
00102     enum { _Flags = traits<T>::Flags| RowMajorBit };
00103   public:
00104     typedef SparseVector<_Scalar, _Flags> type;
00105 };
00106 
00107 template<typename T,int Rows> struct sparse_eval<T,Rows,1> {
00108     typedef typename traits<T>::Scalar _Scalar;
00109     enum { _Flags = traits<T>::Flags & (~RowMajorBit) };
00110   public:
00111     typedef SparseVector<_Scalar, _Flags> type;
00112 };
00113 
00114 template<typename T,int Rows,int Cols> struct sparse_eval {
00115     typedef typename traits<T>::Scalar _Scalar;
00116     typedef typename traits<T>::Index _Index;
00117     enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
00118   public:
00119     typedef SparseMatrix<_Scalar, _Options, _Index> type;
00120 };
00121 
00122 template<typename T> struct sparse_eval<T,1,1> {
00123     typedef typename traits<T>::Scalar _Scalar;
00124   public:
00125     typedef Matrix<_Scalar, 1, 1> type;
00126 };
00127 
00128 template<typename T> struct plain_matrix_type<T,Sparse>
00129 {
00130   typedef typename traits<T>::Scalar _Scalar;
00131     enum {
00132           _Flags = traits<T>::Flags
00133     };
00134 
00135   public:
00136     typedef SparseMatrix<_Scalar, _Flags> type;
00137 };
00138 
00139 } // end namespace internal
00140 
00149 template<typename Scalar, typename Index=unsigned int>
00150 class Triplet
00151 {
00152 public:
00153   Triplet() : m_row(0), m_col(0), m_value(0) {}
00154 
00155   Triplet(const Index& i, const Index& j, const Scalar& v = Scalar(0))
00156     : m_row(i), m_col(j), m_value(v)
00157   {}
00158 
00160   const Index& row() const { return m_row; }
00161 
00163   const Index& col() const { return m_col; }
00164 
00166   const Scalar& value() const { return m_value; }
00167 protected:
00168   Index m_row, m_col;
00169   Scalar m_value;
00170 };
00171 
00172 } // end namespace Eigen
00173 
00174 #endif // EIGEN_SPARSEUTIL_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:12:13