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,
00088          int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct DenseSparseProductReturnType;         
00089 template<typename Lhs, typename Rhs,
00090          int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct SparseDenseProductReturnType;
00091 template<typename MatrixType,int UpLo> class SparseSymmetricPermutationProduct;
00092 
00093 namespace internal {
00094 
00095 template<typename T,int Rows,int Cols> struct sparse_eval;
00096 
00097 template<typename T> struct eval<T,Sparse>
00098   : public sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime>
00099 {};
00100 
00101 template<typename T,int Cols> struct sparse_eval<T,1,Cols> {
00102     typedef typename traits<T>::Scalar _Scalar;
00103     typedef typename traits<T>::Index _Index;
00104   public:
00105     typedef SparseVector<_Scalar, RowMajor, _Index> type;
00106 };
00107 
00108 template<typename T,int Rows> struct sparse_eval<T,Rows,1> {
00109     typedef typename traits<T>::Scalar _Scalar;
00110     typedef typename traits<T>::Index _Index;
00111   public:
00112     typedef SparseVector<_Scalar, ColMajor, _Index> type;
00113 };
00114 
00115 template<typename T,int Rows,int Cols> struct sparse_eval {
00116     typedef typename traits<T>::Scalar _Scalar;
00117     typedef typename traits<T>::Index _Index;
00118     enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
00119   public:
00120     typedef SparseMatrix<_Scalar, _Options, _Index> type;
00121 };
00122 
00123 template<typename T> struct sparse_eval<T,1,1> {
00124     typedef typename traits<T>::Scalar _Scalar;
00125   public:
00126     typedef Matrix<_Scalar, 1, 1> type;
00127 };
00128 
00129 template<typename T> struct plain_matrix_type<T,Sparse>
00130 {
00131   typedef typename traits<T>::Scalar _Scalar;
00132   typedef typename traits<T>::Index _Index;
00133   enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
00134   public:
00135     typedef SparseMatrix<_Scalar, _Options, _Index> type;
00136 };
00137 
00138 } // end namespace internal
00139 
00148 template<typename Scalar, typename Index=typename SparseMatrix<Scalar>::Index >
00149 class Triplet
00150 {
00151 public:
00152   Triplet() : m_row(0), m_col(0), m_value(0) {}
00153 
00154   Triplet(const Index& i, const Index& j, const Scalar& v = Scalar(0))
00155     : m_row(i), m_col(j), m_value(v)
00156   {}
00157 
00159   const Index& row() const { return m_row; }
00160 
00162   const Index& col() const { return m_col; }
00163 
00165   const Scalar& value() const { return m_value; }
00166 protected:
00167   Index m_row, m_col;
00168   Scalar m_value;
00169 };
00170 
00171 } // end namespace Eigen
00172 
00173 #endif // EIGEN_SPARSEUTIL_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 21:00:10