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>
47 typedef typename MatrixType::Nested MatrixTypeNested;
48 typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
52 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
54 explicit SparseView(
const MatrixType& mat,
const Scalar& reference = Scalar(0),
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;
89 typedef SparseView<ArgType> XprType;
91 class InnerIterator :
public EvalIterator
94 typedef typename XprType::Scalar Scalar;
97 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
98 : EvalIterator(sve.m_argImpl,outer), m_view(sve.m_view)
100 incrementToNonZero();
103 EIGEN_STRONG_INLINE InnerIterator& operator++()
105 EvalIterator::operator++();
106 incrementToNonZero();
110 using EvalIterator::value;
113 const XprType &m_view;
116 void incrementToNonZero()
118 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_view.reference(), m_view.epsilon()))
120 EvalIterator::operator++();
126 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
127 Flags = XprType::Flags
130 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
133 evaluator<ArgType> m_argImpl;
134 const XprType &m_view;
137 template<
typename ArgType>
138 struct unary_evaluator<SparseView<ArgType>, IndexBased>
139 :
public evaluator_base<SparseView<ArgType> >
142 typedef SparseView<ArgType> XprType;
145 typedef typename XprType::Scalar Scalar;
146 typedef typename XprType::StorageIndex StorageIndex;
153 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
154 : m_sve(sve), m_inner(0), m_outer(outer), m_end(sve.m_view.innerSize())
156 incrementToNonZero();
159 EIGEN_STRONG_INLINE InnerIterator& operator++()
162 incrementToNonZero();
166 EIGEN_STRONG_INLINE Scalar value()
const
168 return (IsRowMajor) ? m_sve.m_argImpl.coeff(m_outer, m_inner)
169 : m_sve.m_argImpl.coeff(m_inner, m_outer);
172 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_inner; }
173 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
174 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
176 EIGEN_STRONG_INLINE
operator bool()
const {
return m_inner < m_end && m_inner>=0; }
179 const unary_evaluator &m_sve;
185 void incrementToNonZero()
187 while((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_sve.m_view.reference(), m_sve.m_view.epsilon()))
195 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
196 Flags = XprType::Flags
199 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
202 evaluator<ArgType> m_argImpl;
203 const XprType &m_view;
225 template<
typename Derived>
244 template<
typename Derived>
247 const RealScalar& epsilon)
const