11 #ifndef EIGEN_SPARSE_TRIANGULARVIEW_H
12 #define EIGEN_SPARSE_TRIANGULARVIEW_H
25 template<
typename MatrixType,
unsigned int Mode>
class TriangularViewImpl<MatrixType,Mode,
Sparse>
30 SkipLast = !SkipFirst,
32 HasUnitDiag = (Mode&
UnitDiag) ? 1 : 0
43 EIGEN_SPARSE_PUBLIC_INTERFACE(TriangularViewType)
46 class ReverseInnerIterator;
48 typedef typename MatrixType::Nested MatrixTypeNested;
49 typedef typename internal::remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
50 typedef typename internal::remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
52 template<
typename RhsType,
typename DstType>
54 EIGEN_STRONG_INLINE
void _solve_impl(
const RhsType &rhs, DstType &dst)
const {
55 if(!(internal::is_same<RhsType,DstType>::value && internal::extract_data(dst) == internal::extract_data(rhs)))
57 this->solveInPlace(dst);
65 template<
typename MatrixType,
unsigned int Mode>
66 class TriangularViewImpl<MatrixType,Mode,
Sparse>::InnerIterator :
public MatrixTypeNestedCleaned::InnerIterator
68 typedef typename MatrixTypeNestedCleaned::InnerIterator Base;
71 EIGEN_STRONG_INLINE InnerIterator(
const TriangularViewImpl& view, Index outer)
72 : Base(view.derived().nestedExpression(), outer), m_returnOne(false)
76 while((*
this) && ((HasUnitDiag||SkipDiag) ? this->index()<=outer : this->index()<outer))
81 else if(HasUnitDiag && ((!Base::operator
bool()) || Base::index()>=Base::outer()))
83 if((!SkipFirst) && Base::operator
bool())
89 EIGEN_STRONG_INLINE InnerIterator& operator++()
91 if(HasUnitDiag && m_returnOne)
96 if(HasUnitDiag && (!SkipFirst) && ((!Base::operator
bool()) || Base::index()>=Base::outer()))
98 if((!SkipFirst) && Base::operator
bool())
106 inline Index row()
const {
return (MatrixType::Flags&
RowMajorBit ? Base::outer() : this->index()); }
107 inline Index col()
const {
return (MatrixType::Flags&
RowMajorBit ? this->index() : Base::outer()); }
108 inline StorageIndex index()
const
110 if(HasUnitDiag && m_returnOne)
return Base::outer();
111 else return Base::index();
113 inline Scalar value()
const
115 if(HasUnitDiag && m_returnOne)
return Scalar(1);
116 else return Base::value();
119 EIGEN_STRONG_INLINE
operator bool()
const
121 if(HasUnitDiag && m_returnOne)
123 if(SkipFirst)
return Base::operator bool();
126 if (SkipDiag)
return (Base::operator
bool() && this->index() < this->outer());
127 else return (Base::operator
bool() && this->index() <= this->outer());
134 template<
typename MatrixType,
unsigned int Mode>
135 class TriangularViewImpl<MatrixType,Mode,Sparse>::ReverseInnerIterator :
public MatrixTypeNestedCleaned::ReverseInnerIterator
137 typedef typename MatrixTypeNestedCleaned::ReverseInnerIterator Base;
140 EIGEN_STRONG_INLINE ReverseInnerIterator(
const TriangularViewType& view, Index outer)
141 : Base(view.derived().nestedExpression(), outer)
143 eigen_assert((!HasUnitDiag) &&
"ReverseInnerIterator does not support yet triangular views with a unit diagonal");
145 while((*
this) && (SkipDiag ? this->index()>=outer : this->index()>outer))
150 EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
151 { Base::operator--();
return *
this; }
153 inline Index row()
const {
return Base::row(); }
154 inline Index col()
const {
return Base::col(); }
156 EIGEN_STRONG_INLINE
operator bool()
const
158 if (SkipLast)
return Base::operator bool() ;
161 if(SkipDiag)
return (Base::operator
bool() && this->index() > this->outer());
162 else return (Base::operator
bool() && this->index() >= this->outer());
169 template<
typename ArgType,
unsigned int Mode>
170 struct unary_evaluator<TriangularView<ArgType,Mode>, IteratorBased>
171 : evaluator_base<TriangularView<ArgType,Mode> >
173 typedef TriangularView<ArgType,Mode> XprType;
177 typedef typename XprType::Scalar Scalar;
178 typedef typename XprType::StorageIndex StorageIndex;
179 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
183 SkipLast = !SkipFirst,
185 HasUnitDiag = (Mode&
UnitDiag) ? 1 : 0
191 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
192 Flags = XprType::Flags
195 explicit unary_evaluator(
const XprType &xpr) : m_argImpl(xpr.nestedExpression()) {}
197 inline Index nonZerosEstimate()
const {
198 return m_argImpl.nonZerosEstimate();
201 class InnerIterator :
public EvalIterator
203 typedef EvalIterator Base;
206 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& xprEval, Index outer)
207 : Base(xprEval.m_argImpl,outer), m_returnOne(false)
211 while((*
this) && ((HasUnitDiag||SkipDiag) ? this->index()<=outer : this->index()<outer))
216 else if(HasUnitDiag && ((!Base::operator
bool()) || Base::index()>=Base::outer()))
218 if((!SkipFirst) && Base::operator
bool())
224 EIGEN_STRONG_INLINE InnerIterator& operator++()
226 if(HasUnitDiag && m_returnOne)
231 if(HasUnitDiag && (!SkipFirst) && ((!Base::operator
bool()) || Base::index()>=Base::outer()))
233 if((!SkipFirst) && Base::operator
bool())
241 EIGEN_STRONG_INLINE
operator bool()
const
243 if(HasUnitDiag && m_returnOne)
245 if(SkipFirst)
return Base::operator bool();
248 if (SkipDiag)
return (Base::operator
bool() && this->index() < this->outer());
249 else return (Base::operator
bool() && this->index() <= this->outer());
255 inline StorageIndex index()
const
257 if(HasUnitDiag && m_returnOne)
return internal::convert_index<StorageIndex>(Base::outer());
258 else return Base::index();
260 inline Scalar value()
const
262 if(HasUnitDiag && m_returnOne)
return Scalar(1);
263 else return Base::value();
273 evaluator<ArgType> m_argImpl;
278 template<
typename Derived>
280 inline const TriangularView<const Derived, Mode>
281 SparseMatrixBase<Derived>::triangularView()
const
283 return TriangularView<const Derived, Mode>(derived());
288 #endif // EIGEN_SPARSE_TRIANGULARVIEW_H
Definition: Constants.h:196
Definition: Constants.h:202
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Constants.h:198
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:26
Definition: Constants.h:485
Definition: Constants.h:200
Definition: Eigen_Colamd.h:54
Expression of a triangular part in a matrix.
Definition: TriangularMatrix.h:186
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48