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>
68 template <
typename OtherDerived>
74template <
typename ArgType,
unsigned int Mode>
75struct unary_evaluator<
TriangularView<ArgType, Mode>, IteratorBased> : evaluator_base<TriangularView<ArgType, Mode> > {
79 using Scalar =
typename XprType::Scalar;
80 using StorageIndex =
typename XprType::StorageIndex;
81 using EvalIterator =
typename evaluator<ArgType>::InnerIterator;
86 SkipLast = !SkipFirst,
87 SkipDiag = (Mode &
ZeroDiag) ? 1 : 0,
88 HasUnitDiag = (Mode &
UnitDiag) ? 1 : 0
92 enum { CoeffReadCost = evaluator<ArgType>::CoeffReadCost, Flags = XprType::Flags };
94 explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_arg(xpr.nestedExpression()) {}
96 inline Index nonZerosEstimate()
const {
return m_argImpl.nonZerosEstimate(); }
98 class InnerIterator :
public EvalIterator {
99 using Base = EvalIterator;
102 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& xprEval, Index outer)
103 : Base(xprEval.m_argImpl, outer),
105 m_containsDiag(Base::outer() < xprEval.m_arg.innerSize()) {
106 EIGEN_IF_CONSTEXPR (SkipFirst) {
107 while ((*
this) && ((HasUnitDiag || SkipDiag) ? this->index() <= outer : this->index() < outer))
109 EIGEN_IF_CONSTEXPR (HasUnitDiag) m_returnOne = m_containsDiag;
110 }
else EIGEN_IF_CONSTEXPR (HasUnitDiag) {
111 if ((!Base::operator
bool()) || Base::index() >= Base::outer()) {
112 if (Base::operator
bool()) Base::operator++();
113 m_returnOne = m_containsDiag;
118 EIGEN_STRONG_INLINE InnerIterator& operator++() {
119 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
127 EIGEN_IF_CONSTEXPR (HasUnitDiag && !SkipFirst) {
128 if (!(*
this))
return *
this;
131 EIGEN_IF_CONSTEXPR (HasUnitDiag && !SkipFirst) {
132 if ((!Base::operator
bool()) || Base::index() >= Base::outer()) {
133 if (Base::operator
bool()) Base::operator++();
134 m_returnOne = m_containsDiag;
140 EIGEN_STRONG_INLINE
operator bool()
const {
141 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
142 if (m_returnOne)
return true;
144 EIGEN_IF_CONSTEXPR (SkipFirst) {
145 return Base::operator bool();
147 EIGEN_IF_CONSTEXPR (SkipDiag) {
148 return (Base::operator
bool() && this->index() < this->outer());
150 return (Base::operator
bool() && this->index() <= this->outer());
155 inline Index row()
const {
return (ArgType::Flags & RowMajorBit ? Base::outer() : Index(this->index())); }
156 inline Index col()
const {
return (ArgType::Flags & RowMajorBit ? Index(this->index()) : Base::outer()); }
157 inline StorageIndex index()
const {
158 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
159 if (m_returnOne)
return internal::convert_index<StorageIndex>(Base::outer());
161 return Base::index();
163 inline Scalar value()
const {
164 EIGEN_IF_CONSTEXPR (HasUnitDiag) {
165 if (m_returnOne)
return Scalar(1);
167 return Base::value();
179 evaluator<ArgType> m_argImpl;
180 const ArgType& m_arg;
185template <
typename Derived>
187inline const TriangularView<const Derived, Mode> SparseMatrixBase<Derived>::triangularView()
const {
188 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