12#ifndef EIGEN_SPARSE_TRIANGULARVIEW_H
13#define EIGEN_SPARSE_TRIANGULARVIEW_H
16#include "./InternalHeaderCheck.h"
30template <
typename MatrixType,
unsigned int Mode>
31class TriangularViewImpl<MatrixType, Mode,
Sparse> :
public SparseMatrixBase<TriangularView<MatrixType, Mode> > {
38 using Base = SparseMatrixBase<TriangularViewType>;
41 EIGEN_SPARSE_PUBLIC_INTERFACE(TriangularViewType)
43 using MatrixTypeNested =
typename MatrixType::Nested;
44 using MatrixTypeNestedNonRef = std::remove_reference_t<MatrixTypeNested>;
45 using MatrixTypeNestedCleaned = internal::remove_all_t<MatrixTypeNested>;
47 template <
typename RhsType,
typename DstType>
48 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _solve_impl(
const RhsType& rhs, DstType& dst)
const {
49 EIGEN_IF_CONSTEXPR ((std::is_same<RhsType, DstType>::value)) {
50 if (internal::extract_data(dst) != internal::extract_data(rhs)) dst = rhs;
57 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
return derived().nestedExpression().rows(); }
58 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return derived().nestedExpression().cols(); }
61 template <
typename OtherDerived>
65 template <
typename OtherDerived>
71template <
typename ArgType,
unsigned int Mode>
72struct unary_evaluator<
TriangularView<ArgType, Mode>, IteratorBased> : evaluator_base<TriangularView<ArgType, Mode> > {
76 using Scalar =
typename XprType::Scalar;
77 using StorageIndex =
typename XprType::StorageIndex;
78 using EvalIterator =
typename evaluator<ArgType>::InnerIterator;
83 SkipLast = !SkipFirst,
84 SkipDiag = (Mode &
ZeroDiag) ? 1 : 0,
85 HasUnitDiag = (Mode &
UnitDiag) ? 1 : 0
89 enum { CoeffReadCost = evaluator<ArgType>::CoeffReadCost, Flags = XprType::Flags };
91 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_arg(xpr.nestedExpression()) {}
93 inline Index nonZerosEstimate()
const {
return m_argImpl.nonZerosEstimate(); }
95 class InnerIterator :
public EvalIterator {
96 using Base = EvalIterator;
99 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& xprEval, Index outer)
100 : Base(xprEval.m_argImpl, outer),
102 m_containsDiag(Base::outer() < xprEval.m_arg.innerSize()) {
103 EIGEN_IF_CONSTEXPR (SkipFirst) {
104 while ((*
this) && ((HasUnitDiag || SkipDiag) ? this->index() <= outer : this->index() < outer))
106 EIGEN_IF_CONSTEXPR (HasUnitDiag) m_returnOne = m_containsDiag;
107 }
else EIGEN_IF_CONSTEXPR (HasUnitDiag) {
108 if ((!Base::operator
bool()) || Base::index() >= Base::outer()) {
109 if (Base::operator
bool()) Base::operator++();
110 m_returnOne = m_containsDiag;
115 EIGEN_STRONG_INLINE InnerIterator& operator++() {
116 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
123 EIGEN_IF_CONSTEXPR (HasUnitDiag && !SkipFirst) {
124 if ((!Base::operator
bool()) || Base::index() >= Base::outer()) {
125 if (Base::operator
bool()) Base::operator++();
126 m_returnOne = m_containsDiag;
132 EIGEN_STRONG_INLINE
operator bool()
const {
133 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
134 if (m_returnOne)
return true;
136 EIGEN_IF_CONSTEXPR (SkipFirst) {
137 return Base::operator bool();
139 EIGEN_IF_CONSTEXPR (SkipDiag) {
140 return (Base::operator
bool() && this->index() < this->outer());
142 return (Base::operator
bool() && this->index() <= this->outer());
147 inline Index row()
const {
return (ArgType::Flags & RowMajorBit ? Base::outer() : this->index()); }
148 inline Index col()
const {
return (ArgType::Flags & RowMajorBit ? this->index() : Base::outer()); }
149 inline StorageIndex index()
const {
150 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
151 if (m_returnOne)
return internal::convert_index<StorageIndex>(Base::outer());
153 return Base::index();
155 inline Scalar value()
const {
156 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
157 if (m_returnOne)
return Scalar(1);
159 return Base::value();
171 evaluator<ArgType> m_argImpl;
172 const ArgType& m_arg;
177template <
typename Derived>
179inline const TriangularView<const Derived, Mode> SparseMatrixBase<Derived>::triangularView()
const {
180 return TriangularView<const Derived, Mode>(derived());
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
void solveInPlace(MatrixBase< OtherDerived > &other) const
void solveInPlace(SparseMatrixBase< OtherDerived > &other) const
Expression of a triangular part in a matrix.
Definition TriangularMatrix.h:426
@ UnitDiag
Definition Constants.h:216
@ ZeroDiag
Definition Constants.h:218
@ Lower
Definition Constants.h:212
@ Upper
Definition Constants.h:214
constexpr unsigned int RowMajorBit
Definition Constants.h:71
constexpr TriangularView< MatrixType, Mode > & derived()
Definition EigenBase.h:50
Definition Constants.h:545