11 #ifndef EIGEN_SPARSEVIEW_H
12 #define EIGEN_SPARSEVIEW_H
14 #include "./InternalHeaderCheck.h"
20 template<
typename MatrixType>
21 struct traits<SparseView<MatrixType> > : traits<MatrixType>
23 typedef typename MatrixType::StorageIndex StorageIndex;
24 typedef Sparse StorageKind;
26 Flags = int(traits<MatrixType>::Flags) & (
RowMajorBit)
46 template<
typename MatrixType>
49 typedef typename MatrixType::Nested MatrixTypeNested;
50 typedef internal::remove_all_t<MatrixTypeNested> MatrixTypeNested_;
54 typedef internal::remove_all_t<MatrixType> NestedExpression;
56 explicit SparseView(
const MatrixType& mat,
const Scalar& reference = Scalar(0),
58 : m_matrix(mat), m_reference(reference), m_epsilon(epsilon) {}
60 inline Index rows()
const {
return m_matrix.rows(); }
61 inline Index cols()
const {
return m_matrix.cols(); }
63 inline Index innerSize()
const {
return m_matrix.innerSize(); }
64 inline Index outerSize()
const {
return m_matrix.outerSize(); }
67 const internal::remove_all_t<MatrixTypeNested>&
70 Scalar reference()
const {
return m_reference; }
71 RealScalar epsilon()
const {
return m_epsilon; }
74 MatrixTypeNested m_matrix;
85 template<
typename ArgType>
86 struct unary_evaluator<SparseView<ArgType>, IteratorBased>
87 :
public evaluator_base<SparseView<ArgType> >
89 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
91 typedef SparseView<ArgType> XprType;
93 class InnerIterator :
public EvalIterator
96 typedef typename XprType::Scalar Scalar;
99 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
100 : EvalIterator(sve.m_argImpl,outer), m_view(sve.m_view)
102 incrementToNonZero();
105 EIGEN_STRONG_INLINE InnerIterator& operator++()
107 EvalIterator::operator++();
108 incrementToNonZero();
112 using EvalIterator::value;
115 const XprType &m_view;
118 void incrementToNonZero()
120 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_view.reference(), m_view.epsilon()))
122 EvalIterator::operator++();
128 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
129 Flags = XprType::Flags
132 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
135 evaluator<ArgType> m_argImpl;
136 const XprType &m_view;
139 template<
typename ArgType>
140 struct unary_evaluator<SparseView<ArgType>, IndexBased>
141 :
public evaluator_base<SparseView<ArgType> >
144 typedef SparseView<ArgType> XprType;
147 typedef typename XprType::Scalar Scalar;
148 typedef typename XprType::StorageIndex StorageIndex;
155 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
156 : m_sve(sve), m_inner(0), m_outer(outer), m_end(sve.m_view.innerSize())
158 incrementToNonZero();
161 EIGEN_STRONG_INLINE InnerIterator& operator++()
164 incrementToNonZero();
168 EIGEN_STRONG_INLINE Scalar value()
const
170 return (IsRowMajor) ? m_sve.m_argImpl.coeff(m_outer, m_inner)
171 : m_sve.m_argImpl.coeff(m_inner, m_outer);
174 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_inner; }
175 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
176 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
178 EIGEN_STRONG_INLINE
operator bool()
const {
return m_inner < m_end && m_inner>=0; }
181 const unary_evaluator &m_sve;
187 void incrementToNonZero()
189 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_sve.m_view.reference(), m_sve.m_view.epsilon()))
197 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
198 Flags = XprType::Flags
201 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
204 evaluator<ArgType> m_argImpl;
205 const XprType &m_view;
227 template<
typename Derived>
246 template<
typename Derived>
249 const RealScalar& epsilon)
const
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
const SparseView< Derived > pruned(const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition: SparseView.h:248
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: SparseView.h:48
const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition: SparseView.h:68
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:228
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231