11 #ifndef EIGEN_SPARSEVIEW_H 12 #define EIGEN_SPARSEVIEW_H 18 template<
typename MatrixType>
19 struct traits<SparseView<MatrixType> > : traits<MatrixType>
21 typedef typename MatrixType::StorageIndex StorageIndex;
22 typedef Sparse StorageKind;
24 Flags = int(traits<MatrixType>::Flags) & (
RowMajorBit)
44 template<
typename MatrixType>
45 class SparseView :
public SparseMatrixBase<SparseView<MatrixType> >
47 typedef typename MatrixType::Nested MatrixTypeNested;
48 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
49 typedef SparseMatrixBase<SparseView > Base;
51 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
52 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
54 explicit SparseView(
const MatrixType& mat,
const Scalar& reference = Scalar(0),
55 const RealScalar &epsilon = NumTraits<Scalar>::dummy_precision())
56 : m_matrix(mat), m_reference(reference), m_epsilon(epsilon) {}
58 inline Index rows()
const {
return m_matrix.rows(); }
59 inline Index cols()
const {
return m_matrix.cols(); }
61 inline Index innerSize()
const {
return m_matrix.innerSize(); }
62 inline Index outerSize()
const {
return m_matrix.outerSize(); }
65 const typename internal::remove_all<MatrixTypeNested>::type&
68 Scalar reference()
const {
return m_reference; }
69 RealScalar epsilon()
const {
return m_epsilon; }
72 MatrixTypeNested m_matrix;
83 template<
typename ArgType>
84 struct unary_evaluator<SparseView<ArgType>, IteratorBased>
85 :
public evaluator_base<SparseView<ArgType> >
87 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
91 class InnerIterator :
public EvalIterator
93 typedef typename XprType::Scalar Scalar;
96 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
97 : EvalIterator(sve.m_argImpl,outer), m_view(sve.m_view)
102 EIGEN_STRONG_INLINE InnerIterator& operator++()
104 EvalIterator::operator++();
105 incrementToNonZero();
109 using EvalIterator::value;
112 const XprType &m_view;
115 void incrementToNonZero()
117 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_view.reference(), m_view.epsilon()))
119 EvalIterator::operator++();
125 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
126 Flags = XprType::Flags
129 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
132 evaluator<ArgType> m_argImpl;
133 const XprType &m_view;
136 template<
typename ArgType>
137 struct unary_evaluator<SparseView<ArgType>, IndexBased>
138 :
public evaluator_base<SparseView<ArgType> >
144 typedef typename XprType::Scalar Scalar;
152 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
153 : m_sve(sve), m_inner(0), m_outer(outer), m_end(sve.m_view.innerSize())
155 incrementToNonZero();
158 EIGEN_STRONG_INLINE InnerIterator& operator++()
161 incrementToNonZero();
165 EIGEN_STRONG_INLINE Scalar value()
const 167 return (IsRowMajor) ? m_sve.m_argImpl.coeff(m_outer, m_inner)
168 : m_sve.m_argImpl.coeff(m_inner, m_outer);
171 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_inner; }
172 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
173 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
175 EIGEN_STRONG_INLINE
operator bool()
const {
return m_inner < m_end && m_inner>=0; }
178 const unary_evaluator &m_sve;
184 void incrementToNonZero()
186 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_sve.m_view.reference(), m_sve.m_view.epsilon()))
194 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
195 Flags = XprType::Flags
198 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
201 evaluator<ArgType> m_argImpl;
202 const XprType &m_view;
224 template<
typename Derived>
243 template<
typename Derived>
246 const RealScalar& epsilon)
const internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
Namespace containing all symbols from the Eigen library.
Definition: Core:287
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
const unsigned int RowMajorBit
Definition: Constants.h:61
const SparseView< Derived > pruned(const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition: SparseView.h:245
internal::traits< SparseView< MatrixType > >::StorageIndex StorageIndex
Definition: SparseMatrixBase.h:43
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: ForwardDeclarations.h:126
Definition: Eigen_Colamd.h:50
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:225
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: SparseView.h:66