11#ifndef EIGEN_SPARSEVIEW_H
12#define EIGEN_SPARSEVIEW_H
15#include "./InternalHeaderCheck.h"
21template <
typename MatrixType>
22struct traits<SparseView<MatrixType> > : traits<MatrixType> {
23 typedef typename MatrixType::StorageIndex StorageIndex;
24 typedef Sparse StorageKind;
25 enum { Flags = int(traits<MatrixType>::Flags) & (
RowMajorBit) };
44template <
typename MatrixType>
46 typedef typename MatrixType::Nested MatrixTypeNested;
47 typedef internal::remove_all_t<MatrixTypeNested> MatrixTypeNested_;
52 typedef internal::remove_all_t<MatrixType> 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 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;
82template <
typename ArgType>
83struct 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;
127template <
typename ArgType>
128struct 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;
200template <
typename Derived>
202 const typename NumTraits<Scalar>::Real& epsilon)
const {
218template <
typename Derived>
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:30
Expression of a dense or sparse matrix with zero or too small values removed.
Definition SparseView.h:45
const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition SparseView.h:65
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition Meta.h:523