11 #ifndef EIGEN_SPARSEVIEW_H 12 #define EIGEN_SPARSEVIEW_H 15 #include "./InternalHeaderCheck.h" 21 template <
typename MatrixType>
22 struct traits<SparseView<MatrixType> > : traits<MatrixType> {
23 typedef typename MatrixType::StorageIndex StorageIndex;
24 typedef Sparse StorageKind;
25 enum { Flags = int(traits<MatrixType>::Flags) & (
RowMajorBit) };
44 template <
typename MatrixType>
45 class SparseView :
public SparseMatrixBase<SparseView<MatrixType> > {
46 typedef typename MatrixType::Nested MatrixTypeNested;
47 typedef internal::remove_all_t<MatrixTypeNested> MatrixTypeNested_;
48 typedef SparseMatrixBase<SparseView> Base;
51 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseView)
52 typedef internal::remove_all_t<MatrixType> 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 internal::remove_all_t<MatrixTypeNested>&
nestedExpression()
const {
return m_matrix; }
67 Scalar reference()
const {
return m_reference; }
68 RealScalar epsilon()
const {
return m_epsilon; }
71 MatrixTypeNested m_matrix;
82 template <
typename ArgType>
83 struct unary_evaluator<SparseView<ArgType>, IteratorBased> :
public evaluator_base<SparseView<ArgType> > {
84 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
87 typedef SparseView<ArgType> XprType;
89 class InnerIterator :
public EvalIterator {
91 typedef typename XprType::Scalar Scalar;
94 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
95 : EvalIterator(sve.m_argImpl, outer), m_view(sve.m_view) {
99 EIGEN_STRONG_INLINE InnerIterator& operator++() {
100 EvalIterator::operator++();
101 incrementToNonZero();
105 using EvalIterator::value;
108 const XprType& m_view;
111 void incrementToNonZero() {
112 while ((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_view.reference(), m_view.epsilon())) {
113 EvalIterator::operator++();
118 enum { CoeffReadCost = evaluator<ArgType>::CoeffReadCost, Flags = XprType::Flags };
120 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
123 evaluator<ArgType> m_argImpl;
124 const XprType& m_view;
127 template <
typename ArgType>
128 struct unary_evaluator<SparseView<ArgType>, IndexBased> :
public evaluator_base<SparseView<ArgType> > {
130 typedef SparseView<ArgType> XprType;
134 typedef typename XprType::Scalar Scalar;
135 typedef typename XprType::StorageIndex StorageIndex;
138 class InnerIterator {
140 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& sve,
Index outer)
141 : m_sve(sve), m_inner(0), m_outer(outer), m_end(sve.m_view.innerSize()) {
142 incrementToNonZero();
145 EIGEN_STRONG_INLINE InnerIterator& operator++() {
147 incrementToNonZero();
151 EIGEN_STRONG_INLINE Scalar value()
const {
152 return (IsRowMajor) ? m_sve.m_argImpl.coeff(m_outer, m_inner) : m_sve.m_argImpl.coeff(m_inner, m_outer);
155 EIGEN_STRONG_INLINE StorageIndex index()
const {
return m_inner; }
156 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
157 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
159 EIGEN_STRONG_INLINE
operator bool()
const {
return m_inner < m_end && m_inner >= 0; }
162 const unary_evaluator& m_sve;
168 void incrementToNonZero() {
169 while ((
bool(*
this)) && internal::isMuchSmallerThan(value(), m_sve.m_view.reference(), m_sve.m_view.epsilon())) {
175 enum { CoeffReadCost = evaluator<ArgType>::CoeffReadCost, Flags = XprType::Flags };
177 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_view(xpr) {}
180 evaluator<ArgType> m_argImpl;
181 const XprType& m_view;
200 template <
typename Derived>
218 template <
typename Derived>
const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition: SparseView.h:65
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:62
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
const unsigned int RowMajorBit
Definition: Constants.h:70
const SparseView< Derived > pruned(const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition: SparseView.h:219
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: ForwardDeclarations.h:177
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:201
NumTraits< Scalar >::Real RealScalar
Definition: SparseMatrixBase.h:127