Eigen  3.2.10
 
Loading...
Searching...
No Matches
SparseView.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_SPARSEVIEW_H
12#define EIGEN_SPARSEVIEW_H
13
14namespace Eigen {
15
16namespace internal {
17
18template<typename MatrixType>
19struct traits<SparseView<MatrixType> > : traits<MatrixType>
20{
21 typedef typename MatrixType::Index Index;
22 typedef Sparse StorageKind;
23 enum {
24 Flags = int(traits<MatrixType>::Flags) & (RowMajorBit)
25 };
26};
27
28} // end namespace internal
29
44template<typename MatrixType>
45class SparseView : public SparseMatrixBase<SparseView<MatrixType> >
46{
47 typedef typename MatrixType::Nested MatrixTypeNested;
48 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
49public:
50 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
51
52 explicit SparseView(const MatrixType& mat, const Scalar& reference = Scalar(0),
53 const RealScalar &epsilon = NumTraits<Scalar>::dummy_precision())
54 : m_matrix(mat), m_reference(reference), m_epsilon(epsilon) {}
55
56 class InnerIterator;
57
58 inline Index rows() const { return m_matrix.rows(); }
59 inline Index cols() const { return m_matrix.cols(); }
60
61 inline Index innerSize() const { return m_matrix.innerSize(); }
62 inline Index outerSize() const { return m_matrix.outerSize(); }
63
64protected:
65 MatrixTypeNested m_matrix;
66 Scalar m_reference;
67 typename NumTraits<Scalar>::Real m_epsilon;
68};
69
70template<typename MatrixType>
71class SparseView<MatrixType>::InnerIterator : public _MatrixTypeNested::InnerIterator
72{
73 typedef typename SparseView::Index Index;
74public:
75 typedef typename _MatrixTypeNested::InnerIterator IterBase;
76 InnerIterator(const SparseView& view, Index outer) :
77 IterBase(view.m_matrix, outer), m_view(view)
78 {
79 incrementToNonZero();
80 }
81
82 EIGEN_STRONG_INLINE InnerIterator& operator++()
83 {
84 IterBase::operator++();
85 incrementToNonZero();
86 return *this;
87 }
88
89 using IterBase::value;
90
91protected:
92 const SparseView& m_view;
93
94private:
95 void incrementToNonZero()
96 {
97 while((bool(*this)) && internal::isMuchSmallerThan(value(), m_view.m_reference, m_view.m_epsilon))
98 {
99 IterBase::operator++();
100 }
101 }
102};
103
104
105
123template<typename Derived>
125 const typename NumTraits<Scalar>::Real& m_epsilon) const
126{
127 return SparseView<Derived>(derived(), m_reference, m_epsilon);
128}
129
130} // end namespace Eigen
131
132#endif
Expression of a dense or sparse matrix with zero or too small values removed.
Definition SparseView.h:46
const SparseView< Derived > sparseView(const Scalar &m_reference=Scalar(0), const typename NumTraits< Scalar >::Real &m_epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition SparseView.h:124
const unsigned int RowMajorBit
Definition Constants.h:53
Definition LDLT.h:18