11#ifndef EIGEN_TRIANGULARMATRIX_H
12#define EIGEN_TRIANGULARMATRIX_H
18template<
int S
ide,
typename TriangularType,
typename Rhs>
struct triangular_solve_retval;
52 typedef DenseMatrixType DenseType;
53 typedef Derived
const&
Nested;
58 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
59 inline Index rows()
const EIGEN_NOEXCEPT {
return derived().rows(); }
60 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
61 inline Index cols()
const EIGEN_NOEXCEPT {
return derived().cols(); }
62 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
63 inline Index outerStride()
const EIGEN_NOEXCEPT {
return derived().outerStride(); }
64 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
65 inline Index innerStride()
const EIGEN_NOEXCEPT {
return derived().innerStride(); }
71 EIGEN_UNUSED_VARIABLE(rows);
72 EIGEN_UNUSED_VARIABLE(cols);
73 eigen_assert(rows==this->rows() && cols==this->cols());
77 inline Scalar coeff(
Index row,
Index col)
const {
return derived().coeff(row,col); }
79 inline Scalar& coeffRef(
Index row,
Index col) {
return derived().coeffRef(row,col); }
83 template<
typename Other>
87 derived().coeffRef(row, col) = other.coeff(row, col);
91 inline Scalar operator()(
Index row,
Index col)
const
93 check_coordinates(row, col);
94 return coeff(row,col);
97 inline Scalar& operator()(
Index row,
Index col)
99 check_coordinates(row, col);
100 return coeffRef(row,col);
104 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
106 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
108 template<
typename DenseDerived>
111 template<
typename DenseDerived>
116 DenseMatrixType toDenseMatrix()
const
118 DenseMatrixType res(rows(), cols());
125 void check_coordinates(
Index row,
Index col)
const
127 EIGEN_ONLY_USED_FOR_DEBUG(row);
128 EIGEN_ONLY_USED_FOR_DEBUG(col);
129 eigen_assert(col>=0 && col<cols() && row>=0 && row<rows());
130 const int mode = int(Mode) & ~SelfAdjoint;
131 EIGEN_ONLY_USED_FOR_DEBUG(mode);
132 eigen_assert((mode==
Upper && col>=row)
133 || (mode==
Lower && col<=row)
138 #ifdef EIGEN_INTERNAL_DEBUGGING
139 void check_coordinates_internal(
Index row,
Index col)
const
141 check_coordinates(row, col);
144 void check_coordinates_internal(
Index ,
Index )
const {}
167template<
typename MatrixType,
unsigned int _Mode>
171 typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
172 typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
173 typedef typename MatrixType::PlainObject FullMatrixType;
174 typedef MatrixType ExpressionType;
186 :
public TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind >
192 typedef _MatrixType MatrixType;
198 typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
213 IsVectorAtCompileTime =
false
217 explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix)
223 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
226 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
266 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
267 typename MatrixType::TransposeReturnType tmp(m_matrix);
279 template<
typename Other>
287 template<
int S
ide,
typename Other>
289 inline const internal::triangular_solve_retval<Side,TriangularView, Other>
290 solve(
const MatrixBase<Other>& other)
const
291 {
return Base::template solve<Side>(other); }
326 return m_matrix.diagonal().prod();
331 MatrixTypeNested m_matrix;
352 typedef _MatrixType MatrixType;
353 typedef typename MatrixType::PlainObject DenseMatrixType;
354 typedef DenseMatrixType PlainObject;
357 using Base::evalToLazy;
377 template<
typename Other>
384 template<
typename Other>
400 void fill(
const Scalar& value) { setConstant(value); }
404 {
return *
this = MatrixType::Constant(derived().rows(), derived().cols(), value); }
418 Base::check_coordinates_internal(row, col);
419 return derived().nestedExpression().coeff(row, col);
429 Base::check_coordinates_internal(row, col);
430 return derived().nestedExpression().coeffRef(row, col);
434 template<
typename OtherDerived>
439 template<
typename OtherDerived>
445 {
return *
this = other.derived().nestedExpression(); }
447 template<
typename OtherDerived>
449 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
452 template<
typename OtherDerived>
454 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
458 template<
typename OtherDerived>
467 template<
typename OtherDerived>
friend
498 template<
int S
ide,
typename Other>
511 template<
int S
ide,
typename OtherDerived>
515 template<
typename OtherDerived>
521 template<
typename OtherDerived>
530 template<
typename OtherDerived>
532 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
539 template<
typename RhsType,
typename DstType>
542 if(!internal::is_same_dense(
dst,rhs))
544 this->solveInPlace(
dst);
547 template <
typename ProductType>
548 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(
const ProductType& prod,
const Scalar& alpha,
552 EIGEN_DEFAULT_COPY_CONSTRUCTOR(TriangularViewImpl)
553 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TriangularViewImpl)
561#ifndef EIGEN_PARSED_BY_DOXYGEN
563template<
typename MatrixType,
unsigned int Mode>
564template<
typename OtherDerived>
565EIGEN_DEVICE_FUNC
inline TriangularView<MatrixType, Mode>&
566TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const MatrixBase<OtherDerived>& other)
568 internal::call_assignment_no_alias(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
573template<
typename MatrixType,
unsigned int Mode>
574template<
typename OtherDerived>
575EIGEN_DEVICE_FUNC
void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const MatrixBase<OtherDerived>& other)
577 internal::call_assignment_no_alias(derived(), other.template triangularView<Mode>());
582template<
typename MatrixType,
unsigned int Mode>
583template<
typename OtherDerived>
584EIGEN_DEVICE_FUNC
inline TriangularView<MatrixType, Mode>&
585TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const TriangularBase<OtherDerived>& other)
587 eigen_assert(Mode ==
int(OtherDerived::Mode));
588 internal::call_assignment(derived(), other.derived());
592template<
typename MatrixType,
unsigned int Mode>
593template<
typename OtherDerived>
594EIGEN_DEVICE_FUNC
void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const TriangularBase<OtherDerived>& other)
596 eigen_assert(Mode ==
int(OtherDerived::Mode));
597 internal::call_assignment_no_alias(derived(), other.derived());
607template<
typename Derived>
608template<
typename DenseDerived>
611 evalToLazy(other.derived());
633template<
typename Derived>
634template<
unsigned int Mode>
643template<
typename Derived>
644template<
unsigned int Mode>
657template<
typename Derived>
661 for(
Index j = 0; j < cols(); ++j)
663 Index maxi = numext::mini(j, rows()-1);
664 for(
Index i = 0; i <= maxi; ++i)
666 RealScalar
absValue = numext::abs(coeff(i,j));
671 for(
Index j = 0; j < cols(); ++j)
672 for(
Index i = j+1; i < rows(); ++i)
673 if(numext::abs(coeff(i, j)) > threshold)
return false;
682template<
typename Derived>
686 for(
Index j = 0; j < cols(); ++j)
687 for(
Index i = j; i < rows(); ++i)
689 RealScalar
absValue = numext::abs(coeff(i,j));
693 for(
Index j = 1; j < cols(); ++j)
695 Index maxi = numext::mini(j, rows()-1);
696 for(
Index i = 0; i < maxi; ++i)
697 if(numext::abs(coeff(i, j)) > threshold)
return false;
715template<
typename MatrixType,
unsigned int Mode>
722template<
typename MatrixType,
unsigned int Mode>
724 :
evaluator<typename internal::remove_all<MatrixType>::type>
746template<
int UpLo,
int Mode,
int SetOpposite,
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
751 typedef typename Base::DstXprType DstXprType;
752 typedef typename Base::SrcXprType SrcXprType;
755 using Base::m_functor;
758 typedef typename Base::DstEvaluatorType DstEvaluatorType;
759 typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
760 typedef typename Base::Scalar Scalar;
768#ifdef EIGEN_INTERNAL_DEBUGGING
771 eigen_internal_assert(row!=col);
778 EIGEN_DEVICE_FUNC
void assignDiagonalCoeff(
Index id)
781 else if(Mode==
ZeroDiag &&
SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(0));
785 EIGEN_DEVICE_FUNC
void assignOppositeCoeff(
Index row,
Index col)
787 eigen_internal_assert(row!=col);
789 m_functor.assignCoeff(m_dst.coeffRef(row,col), Scalar(0));
793template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType,
typename Functor>
794EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
795void call_triangular_assignment_loop(DstXprType&
dst,
const SrcXprType&
src,
const Functor &func)
800 SrcEvaluatorType srcEvaluator(
src);
806 DstEvaluatorType dstEvaluator(
dst);
809 DstEvaluatorType,SrcEvaluatorType,Functor>
Kernel;
810 Kernel kernel(dstEvaluator, srcEvaluator, func,
dst.const_cast_derived());
814 && SrcEvaluatorType::CoeffReadCost <
HugeCost
815 && DstXprType::SizeAtCompileTime * (int(DstEvaluatorType::CoeffReadCost) + int(SrcEvaluatorType::CoeffReadCost)) / 2 <= EIGEN_UNROLLING_LIMIT
821template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType>
822EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
823void call_triangular_assignment_loop(DstXprType& dst,
const SrcXprType& src)
825 call_triangular_assignment_loop<Mode,SetOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>());
833template<
typename DstXprType,
typename SrcXprType,
typename Functor>
836 EIGEN_DEVICE_FUNC
static void run(DstXprType &
dst,
const SrcXprType &
src,
const Functor &func)
838 eigen_assert(
int(DstXprType::Mode) ==
int(SrcXprType::Mode));
844template<
typename DstXprType,
typename SrcXprType,
typename Functor>
847 EIGEN_DEVICE_FUNC
static void run(DstXprType &
dst,
const SrcXprType &
src,
const Functor &func)
853template<
typename DstXprType,
typename SrcXprType,
typename Functor>
856 EIGEN_DEVICE_FUNC
static void run(DstXprType &
dst,
const SrcXprType &
src,
const Functor &func)
863template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool SetOpposite>
867 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
868 typedef typename DstEvaluatorType::XprType DstXprType;
871 col = (
UnrollCount-1) / DstXprType::RowsAtCompileTime,
872 row = (
UnrollCount-1) % DstXprType::RowsAtCompileTime
875 typedef typename Kernel::Scalar Scalar;
878 static inline void run(
Kernel &kernel)
883 kernel.assignDiagonalCoeff(row);
884 else if( ((Mode&
Lower) && row>col) || ((Mode&
Upper) && row<col) )
885 kernel.assignCoeff(row,col);
887 kernel.assignOppositeCoeff(row,col);
892template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
896 static inline void run(
Kernel &) {}
905template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
908 typedef typename Kernel::Scalar Scalar;
910 static inline void run(
Kernel &kernel)
912 for(
Index j = 0; j < kernel.cols(); ++j)
914 Index maxi = numext::mini(j, kernel.rows());
919 if(Mode&
Upper) kernel.assignCoeff(i, j);
920 else kernel.assignOppositeCoeff(i, j);
926 kernel.assignDiagonalCoeff(i++);
930 for(; i < kernel.rows(); ++i)
931 if(Mode&
Lower) kernel.assignCoeff(i, j);
932 else kernel.assignOppositeCoeff(i, j);
942template<
typename Derived>
943template<
typename DenseDerived>
946 other.derived().
resize(this->rows(), this->cols());
947 internal::call_triangular_assignment_loop<Derived::Mode, (int(Derived::Mode) & int(
SelfAdjoint)) == 0 >(other.derived(), derived().nestedExpression());
953template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
964 dst._assignProduct(
src, Scalar(1),
false);
969template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
975 dst._assignProduct(
src, Scalar(1),
true);
980template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
986 dst._assignProduct(
src, Scalar(-1),
true);
EIGEN_DEVICE_FUNC void resize(Index newSize)
Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods...
Definition DenseBase.h:246
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:75
Base class for triangular part in a matrix.
Definition TriangularMatrix.h:28
EIGEN_DEVICE_FUNC void evalTo(MatrixBase< DenseDerived > &other) const
Assigns a triangular or selfadjoint matrix to a dense matrix.
Definition TriangularMatrix.h:609
@ SizeAtCompileTime
This is equal to the number of coefficients, i.e.
Definition TriangularMatrix.h:38
EIGEN_DEVICE_FUNC void evalToLazy(MatrixBase< DenseDerived > &other) const
Assigns a triangular or selfadjoint matrix to a dense matrix.
Definition TriangularMatrix.h:944
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other &other)
Definition TriangularMatrix.h:85
EIGEN_DEVICE_FUNC TriangularViewType & setOnes()
Definition TriangularMatrix.h:410
EIGEN_DEVICE_FUNC void swap(TriangularBase< OtherDerived > const &other)
Swaps the coefficients of the common triangular parts of two matrices.
Definition TriangularMatrix.h:523
EIGEN_DEVICE_FUNC TriangularViewType & operator+=(const DenseBase< Other > &other)
Definition TriangularMatrix.h:379
EIGEN_DEVICE_FUNC const Product< TriangularViewType, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Efficient triangular matrix times vector/matrix product.
Definition TriangularMatrix.h:461
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC void swap(MatrixBase< OtherDerived > const &other)
Shortcut for.
Definition TriangularMatrix.h:533
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
Definition TriangularMatrix.h:426
friend EIGEN_DEVICE_FUNC const Product< OtherDerived, TriangularViewType > operator*(const MatrixBase< OtherDerived > &lhs, const TriangularViewImpl &rhs)
Efficient vector/matrix times triangular matrix product.
Definition TriangularMatrix.h:470
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC void lazyAssign(const MatrixBase< OtherDerived > &other)
EIGEN_DEVICE_FUNC TriangularViewType & operator/=(const typename internal::traits< MatrixType >::Scalar &other)
Definition TriangularMatrix.h:396
const internal::triangular_solve_retval< Side, TriangularViewType, Other > solve(const MatrixBase< Other > &other) const
EIGEN_DEVICE_FUNC void solveInPlace(const MatrixBase< OtherDerived > &other) const
"in-place" version of TriangularView::solve() where the result is written in other
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC void lazyAssign(const TriangularBase< OtherDerived > &other)
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
Definition TriangularMatrix.h:416
EIGEN_DEVICE_FUNC TriangularViewType & operator=(const MatrixBase< OtherDerived > &other)
Shortcut for.
EIGEN_DEVICE_FUNC TriangularViewType & operator*=(const typename internal::traits< MatrixType >::Scalar &other)
Definition TriangularMatrix.h:393
EIGEN_DEVICE_FUNC TriangularViewType & setConstant(const Scalar &value)
Definition TriangularMatrix.h:403
EIGEN_DEVICE_FUNC TriangularViewType & setZero()
Definition TriangularMatrix.h:407
EIGEN_DEVICE_FUNC void fill(const Scalar &value)
Definition TriangularMatrix.h:400
EIGEN_DEVICE_FUNC Index outerStride() const
Definition TriangularMatrix.h:370
EIGEN_DEVICE_FUNC TriangularViewType & operator=(const TriangularBase< OtherDerived > &other)
Assigns a triangular matrix to a triangular part of a dense matrix.
EIGEN_DEVICE_FUNC TriangularViewType & operator-=(const DenseBase< Other > &other)
Definition TriangularMatrix.h:386
EIGEN_DEVICE_FUNC Index innerStride() const
Definition TriangularMatrix.h:374
Definition TriangularMatrix.h:183
Expression of a triangular part in a matrix.
Definition TriangularMatrix.h:187
EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const
Definition TriangularMatrix.h:274
EIGEN_DEVICE_FUNC const NestedExpression & nestedExpression() const
Definition TriangularMatrix.h:231
EIGEN_DEVICE_FUNC Scalar determinant() const
Definition TriangularMatrix.h:319
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition TriangularMatrix.h:264
EIGEN_DEVICE_FUNC SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView()
Definition TriangularMatrix.h:301
EIGEN_DEVICE_FUNC const SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView() const
This is the const version of selfadjointView()
Definition TriangularMatrix.h:309
EIGEN_DEVICE_FUNC NestedExpression & nestedExpression()
Definition TriangularMatrix.h:235
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const
Definition TriangularMatrix.h:258
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition TriangularMatrix.h:224
EIGEN_DEVICE_FUNC internal::conditional< Cond, ConjugateReturnType, ConstTriangularView >::type conjugateIf() const
Definition TriangularMatrix.h:249
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition TriangularMatrix.h:227
EIGEN_DEVICE_FUNC const ConjugateReturnType conjugate() const
Definition TriangularMatrix.h:240
Definition AssignEvaluator.h:619
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col)
Assign src(row,col) to dst(row,col) through the assignment functor.
Definition AssignEvaluator.h:652
Definition TriangularMatrix.h:748
@ StrictlyLower
View matrix as a lower triangular matrix with zeros on the diagonal.
Definition Constants.h:221
@ UnitDiag
Matrix has ones on the diagonal; to be used in combination with #Lower or #Upper.
Definition Constants.h:213
@ StrictlyUpper
View matrix as an upper triangular matrix with zeros on the diagonal.
Definition Constants.h:223
@ UnitLower
View matrix as a lower triangular matrix with ones on the diagonal.
Definition Constants.h:217
@ ZeroDiag
Matrix has zeros on the diagonal; to be used in combination with #Lower or #Upper.
Definition Constants.h:215
@ SelfAdjoint
Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint.
Definition Constants.h:225
@ UnitUpper
View matrix as an upper triangular matrix with ones on the diagonal.
Definition Constants.h:219
@ Lower
View matrix as a lower triangular matrix.
Definition Constants.h:209
@ Upper
View matrix as an upper triangular matrix.
Definition Constants.h:211
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:94
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition Constants.h:130
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition Constants.h:155
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition Constants.h:144
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
const int HugeCost
This value means that the cost to evaluate an expression coefficient is either very expensive or cann...
Definition Constants.h:44
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition Constants.h:22
Definition Constants.h:528
The type used to identify a dense storage.
Definition Constants.h:507
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition EigenBase.h:30
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:39
Definition Constants.h:533
Definition AssignEvaluator.h:817
Definition AssignEvaluator.h:824
Definition TriangularMatrix.h:735
Definition Constants.h:542
Definition TriangularMatrix.h:734
Definition TriangularMatrix.h:733
Definition AssignmentFunctors.h:46
Definition AssignmentFunctors.h:21
Definition CoreEvaluators.h:80
Definition CoreEvaluators.h:91
Definition XprHelper.h:660
Definition XprHelper.h:282
Definition AssignmentFunctors.h:67
Definition AssignmentFunctors.h:142
Definition ForwardDeclarations.h:17
Definition TriangularMatrix.h:865
Definition SolveTriangular.h:208
Definition CoreEvaluators.h:65