Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_SPARSEVIEW_H
00027 #define EIGEN_SPARSEVIEW_H
00028
00029 namespace internal {
00030
00031 template<typename MatrixType>
00032 struct traits<SparseView<MatrixType> > : traits<MatrixType>
00033 {
00034 typedef int Index;
00035 typedef Sparse StorageKind;
00036 enum {
00037 Flags = int(traits<MatrixType>::Flags) & (RowMajorBit)
00038 };
00039 };
00040
00041 }
00042
00043 template<typename MatrixType>
00044 class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
00045 {
00046 typedef typename MatrixType::Nested MatrixTypeNested;
00047 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00048 public:
00049 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
00050
00051 SparseView(const MatrixType& mat, const Scalar& m_reference = Scalar(0),
00052 typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) :
00053 m_matrix(mat), m_reference(m_reference), m_epsilon(m_epsilon) {}
00054
00055 class InnerIterator;
00056
00057 inline Index rows() const { return m_matrix.rows(); }
00058 inline Index cols() const { return m_matrix.cols(); }
00059
00060 inline Index innerSize() const { return m_matrix.innerSize(); }
00061 inline Index outerSize() const { return m_matrix.outerSize(); }
00062
00063 protected:
00064 const MatrixTypeNested m_matrix;
00065 Scalar m_reference;
00066 typename NumTraits<Scalar>::Real m_epsilon;
00067 };
00068
00069 template<typename MatrixType>
00070 class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator
00071 {
00072 public:
00073 typedef typename _MatrixTypeNested::InnerIterator IterBase;
00074 InnerIterator(const SparseView& view, Index outer) :
00075 IterBase(view.m_matrix, outer), m_view(view)
00076 {
00077 incrementToNonZero();
00078 }
00079
00080 EIGEN_STRONG_INLINE InnerIterator& operator++()
00081 {
00082 IterBase::operator++();
00083 incrementToNonZero();
00084 return *this;
00085 }
00086
00087 using IterBase::value;
00088
00089 protected:
00090 const SparseView& m_view;
00091
00092 private:
00093 void incrementToNonZero()
00094 {
00095 while(internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon) && (bool(*this)))
00096 {
00097 IterBase::operator++();
00098 }
00099 }
00100 };
00101
00102 template<typename Derived>
00103 const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference,
00104 typename NumTraits<Scalar>::Real m_epsilon) const
00105 {
00106 return SparseView<Derived>(derived(), m_reference, m_epsilon);
00107 }
00108
00109 #endif