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 Eigen {
00030
00031 namespace internal {
00032
00033 template<typename MatrixType>
00034 struct traits<SparseView<MatrixType> > : traits<MatrixType>
00035 {
00036 typedef int Index;
00037 typedef Sparse StorageKind;
00038 enum {
00039 Flags = int(traits<MatrixType>::Flags) & (RowMajorBit)
00040 };
00041 };
00042
00043 }
00044
00045 template<typename MatrixType>
00046 class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
00047 {
00048 typedef typename MatrixType::Nested MatrixTypeNested;
00049 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00050 public:
00051 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
00052
00053 SparseView(const MatrixType& mat, const Scalar& m_reference = Scalar(0),
00054 typename NumTraits<Scalar>::Real m_epsilon = NumTraits<Scalar>::dummy_precision()) :
00055 m_matrix(mat), m_reference(m_reference), m_epsilon(m_epsilon) {}
00056
00057 class InnerIterator;
00058
00059 inline Index rows() const { return m_matrix.rows(); }
00060 inline Index cols() const { return m_matrix.cols(); }
00061
00062 inline Index innerSize() const { return m_matrix.innerSize(); }
00063 inline Index outerSize() const { return m_matrix.outerSize(); }
00064
00065 protected:
00066 MatrixTypeNested m_matrix;
00067 Scalar m_reference;
00068 typename NumTraits<Scalar>::Real m_epsilon;
00069 };
00070
00071 template<typename MatrixType>
00072 class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator
00073 {
00074 public:
00075 typedef typename _MatrixTypeNested::InnerIterator IterBase;
00076 InnerIterator(const SparseView& view, Index outer) :
00077 IterBase(view.m_matrix, outer), m_view(view)
00078 {
00079 incrementToNonZero();
00080 }
00081
00082 EIGEN_STRONG_INLINE InnerIterator& operator++()
00083 {
00084 IterBase::operator++();
00085 incrementToNonZero();
00086 return *this;
00087 }
00088
00089 using IterBase::value;
00090
00091 protected:
00092 const SparseView& m_view;
00093
00094 private:
00095 void incrementToNonZero()
00096 {
00097 while((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon))
00098 {
00099 IterBase::operator++();
00100 }
00101 }
00102 };
00103
00104 template<typename Derived>
00105 const SparseView<Derived> MatrixBase<Derived>::sparseView(const Scalar& m_reference,
00106 typename NumTraits<Scalar>::Real m_epsilon) const
00107 {
00108 return SparseView<Derived>(derived(), m_reference, m_epsilon);
00109 }
00110
00111 }
00112
00113 #endif