11 #ifndef EIGEN_SPARSE_TRIANGULARVIEW_H
12 #define EIGEN_SPARSE_TRIANGULARVIEW_H
18 template<
typename MatrixType,
int Mode>
19 struct traits<SparseTriangularView<MatrixType,Mode> >
20 :
public traits<MatrixType>
25 template<
typename MatrixType,
int Mode>
class SparseTriangularView
26 :
public SparseMatrixBase<SparseTriangularView<MatrixType,Mode> >
30 SkipLast = !SkipFirst,
32 HasUnitDiag = (Mode&
UnitDiag) ? 1 : 0
37 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseTriangularView)
40 class ReverseInnerIterator;
42 inline Index rows()
const {
return m_matrix.rows(); }
43 inline Index cols()
const {
return m_matrix.cols(); }
45 typedef typename MatrixType::Nested MatrixTypeNested;
46 typedef typename internal::remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
47 typedef typename internal::remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
49 inline SparseTriangularView(
const MatrixType& matrix) : m_matrix(matrix) {}
52 inline const MatrixTypeNestedCleaned& nestedExpression()
const {
return m_matrix; }
54 template<
typename OtherDerived>
55 typename internal::plain_matrix_type_column_major<OtherDerived>::type
56 solve(
const MatrixBase<OtherDerived>& other)
const;
58 template<
typename OtherDerived>
void solveInPlace(MatrixBase<OtherDerived>& other)
const;
59 template<
typename OtherDerived>
void solveInPlace(SparseMatrixBase<OtherDerived>& other)
const;
62 MatrixTypeNested m_matrix;
65 template<
typename MatrixType,
int Mode>
66 class SparseTriangularView<MatrixType,Mode>::InnerIterator :
public MatrixTypeNestedCleaned::InnerIterator
68 typedef typename MatrixTypeNestedCleaned::InnerIterator Base;
69 typedef typename SparseTriangularView::Index Index;
72 EIGEN_STRONG_INLINE InnerIterator(
const SparseTriangularView& view, Index outer)
73 : Base(view.nestedExpression(), outer), m_returnOne(false)
77 while((*
this) && ((HasUnitDiag||SkipDiag) ? this->index()<=outer : this->index()<outer))
82 else if(HasUnitDiag && ((!Base::operator
bool()) || Base::index()>=Base::outer()))
84 if((!SkipFirst) && Base::operator
bool())
90 EIGEN_STRONG_INLINE InnerIterator& operator++()
92 if(HasUnitDiag && m_returnOne)
97 if(HasUnitDiag && (!SkipFirst) && ((!Base::operator
bool()) || Base::index()>=Base::outer()))
99 if((!SkipFirst) && Base::operator
bool())
107 inline Index
row()
const {
return (MatrixType::Flags&RowMajorBit ? Base::outer() : this->index()); }
108 inline Index
col()
const {
return (MatrixType::Flags&RowMajorBit ? this->index() : Base::outer()); }
109 inline Index index()
const
111 if(HasUnitDiag && m_returnOne)
return Base::outer();
112 else return Base::index();
114 inline Scalar value()
const
116 if(HasUnitDiag && m_returnOne)
return Scalar(1);
117 else return Base::value();
120 EIGEN_STRONG_INLINE
operator bool()
const
122 if(HasUnitDiag && m_returnOne)
124 if(SkipFirst)
return Base::operator bool();
127 if (SkipDiag)
return (Base::operator
bool() && this->index() < this->outer());
128 else return (Base::operator
bool() && this->index() <= this->outer());
135 template<
typename MatrixType,
int Mode>
136 class SparseTriangularView<MatrixType,Mode>::ReverseInnerIterator :
public MatrixTypeNestedCleaned::ReverseInnerIterator
138 typedef typename MatrixTypeNestedCleaned::ReverseInnerIterator Base;
139 typedef typename SparseTriangularView::Index Index;
142 EIGEN_STRONG_INLINE ReverseInnerIterator(
const SparseTriangularView& view, Index outer)
143 : Base(view.nestedExpression(), outer)
145 eigen_assert((!HasUnitDiag) &&
"ReverseInnerIterator does not support yet triangular views with a unit diagonal");
147 while((*
this) && (SkipDiag ? this->index()>=outer : this->index()>outer))
152 EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
153 { Base::operator--();
return *
this; }
155 inline Index
row()
const {
return Base::row(); }
156 inline Index
col()
const {
return Base::col(); }
158 EIGEN_STRONG_INLINE
operator bool()
const
160 if (SkipLast)
return Base::operator bool() ;
163 if(SkipDiag)
return (Base::operator
bool() && this->index() > this->outer());
164 else return (Base::operator
bool() && this->index() >= this->outer());
169 template<
typename Derived>
171 inline const SparseTriangularView<Derived, Mode>
172 SparseMatrixBase<Derived>::triangularView()
const
179 #endif // EIGEN_SPARSE_TRIANGULARVIEW_H
Definition: Constants.h:167
RowXpr row(Index i)
Definition: SparseMatrixBase.h:750
Definition: Constants.h:173
Definition: Constants.h:169
Definition: Constants.h:171
const unsigned int RowMajorBit
Definition: Constants.h:53
ColXpr col(Index i)
Definition: SparseMatrixBase.h:733