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)
30 template<
typename MatrixType>
31 class SparseView :
public SparseMatrixBase<SparseView<MatrixType> >
33 typedef typename MatrixType::Nested MatrixTypeNested;
34 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
36 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
37 typedef typename
internal::remove_all<MatrixType>::type NestedExpression;
39 explicit SparseView(const MatrixType& mat, const Scalar& reference = Scalar(0),
40 RealScalar epsilon = NumTraits<Scalar>::dummy_precision())
41 : m_matrix(mat), m_reference(reference), m_epsilon(epsilon) {}
43 inline Index rows()
const {
return m_matrix.rows(); }
44 inline Index cols()
const {
return m_matrix.cols(); }
46 inline Index innerSize()
const {
return m_matrix.innerSize(); }
47 inline Index outerSize()
const {
return m_matrix.outerSize(); }
50 const typename internal::remove_all<MatrixTypeNested>::type&
51 nestedExpression()
const {
return m_matrix; }
53 Scalar reference()
const {
return m_reference; }
54 RealScalar epsilon()
const {
return m_epsilon; }
57 MatrixTypeNested m_matrix;
68 template<
typename ArgType>
69 struct unary_evaluator<SparseView<ArgType>, IteratorBased>
70 :
public evaluator_base<SparseView<ArgType> >
72 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
74 typedef SparseView<ArgType> XprType;
76 class InnerIterator :
public EvalIterator
78 typedef typename XprType::Scalar Scalar;
81 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve, Index outer)
82 : EvalIterator(sve.m_argImpl,outer), m_view(sve.m_view)
87 EIGEN_STRONG_INLINE InnerIterator& operator++()
89 EvalIterator::operator++();
94 using EvalIterator::value;
97 const XprType &m_view;
100 void incrementToNonZero()
102 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_view.reference(), m_view.epsilon()))
104 EvalIterator::operator++();
110 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
111 Flags = XprType::Flags
114 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
117 evaluator<ArgType> m_argImpl;
118 const XprType &m_view;
121 template<
typename ArgType>
122 struct unary_evaluator<SparseView<ArgType>, IndexBased>
123 :
public evaluator_base<SparseView<ArgType> >
126 typedef SparseView<ArgType> XprType;
129 typedef typename XprType::Scalar Scalar;
130 typedef typename XprType::StorageIndex StorageIndex;
137 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve, Index outer)
138 : m_sve(sve), m_inner(0), m_outer(outer), m_end(sve.m_view.innerSize())
140 incrementToNonZero();
143 EIGEN_STRONG_INLINE InnerIterator& operator++()
146 incrementToNonZero();
150 EIGEN_STRONG_INLINE Scalar value()
const
152 return (IsRowMajor) ? m_sve.m_argImpl.coeff(m_outer, m_inner)
153 : m_sve.m_argImpl.coeff(m_inner, m_outer);
156 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_inner; }
157 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
158 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
160 EIGEN_STRONG_INLINE
operator bool()
const {
return m_inner < m_end && m_inner>=0; }
163 const unary_evaluator &m_sve;
169 void incrementToNonZero()
171 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_sve.m_view.reference(), m_sve.m_view.epsilon()))
179 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
180 Flags = XprType::Flags
183 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
186 evaluator<ArgType> m_argImpl;
187 const XprType &m_view;
192 template<
typename Derived>
193 const SparseView<Derived> MatrixBase<Derived>::sparseView(
const Scalar& reference,
194 const typename NumTraits<Scalar>::Real& epsilon)
const
196 return SparseView<Derived>(derived(), reference, epsilon);
211 template<
typename Derived>
212 const SparseView<Derived>
214 const RealScalar& epsilon)
const
216 return SparseView<Derived>(derived(), reference, epsilon);
const SparseView< Derived > pruned(const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition: SparseView.h:213
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Eigen_Colamd.h:54