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;
59 inline Index rows()
const {
return derived().rows(); }
61 inline Index cols()
const {
return derived().cols(); }
63 inline Index outerStride()
const {
return derived().outerStride(); }
65 inline Index innerStride()
const {
return derived().innerStride(); }
70 EIGEN_UNUSED_VARIABLE(rows);
71 EIGEN_UNUSED_VARIABLE(cols);
72 eigen_assert(rows==this->rows() && cols==this->cols());
76 inline Scalar coeff(
Index row,
Index col)
const {
return derived().coeff(row,col); }
78 inline Scalar& coeffRef(
Index row,
Index col) {
return derived().coeffRef(row,col); }
82 template<
typename Other>
86 derived().coeffRef(row, col) = other.coeff(row, col);
90 inline Scalar operator()(Index row, Index col)
const
92 check_coordinates(row, col);
93 return coeff(row,col);
96 inline Scalar& operator()(
Index row,
Index col)
98 check_coordinates(row, col);
99 return coeffRef(row,col);
102 #ifndef EIGEN_PARSED_BY_DOXYGEN
104 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
106 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
109 template<
typename DenseDerived>
111 void evalTo(MatrixBase<DenseDerived> &other)
const;
112 template<
typename DenseDerived>
114 void evalToLazy(MatrixBase<DenseDerived> &other)
const;
117 DenseMatrixType toDenseMatrix()
const
119 DenseMatrixType res(rows(), cols());
126 void check_coordinates(
Index row,
Index col)
const
128 EIGEN_ONLY_USED_FOR_DEBUG(row);
129 EIGEN_ONLY_USED_FOR_DEBUG(col);
130 eigen_assert(col>=0 && col<cols() && row>=0 && row<rows());
131 const int mode = int(Mode) & ~SelfAdjoint;
132 EIGEN_ONLY_USED_FOR_DEBUG(mode);
133 eigen_assert((mode==
Upper && col>=row)
134 || (mode==
Lower && col<=row)
139 #ifdef EIGEN_INTERNAL_DEBUGGING
140 void check_coordinates_internal(
Index row,
Index col)
const
142 check_coordinates(row, col);
145 void check_coordinates_internal(
Index ,
Index )
const {}
168template<
typename MatrixType,
unsigned int _Mode>
172 typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
174 typedef typename MatrixType::PlainObject FullMatrixType;
175 typedef MatrixType ExpressionType;
187 :
public TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind >
193 typedef _MatrixType MatrixType;
213 IsVectorAtCompileTime =
false
218 explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix)
221 using Base::operator=;
223 {
return Base::operator=(other); }
227 inline Index
rows()
const {
return m_matrix.rows(); }
230 inline Index
cols()
const {
return m_matrix.cols(); }
257 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
258 typename MatrixType::TransposeReturnType tmp(m_matrix.const_cast_derived());
270 template<
typename Other>
278 template<
int S
ide,
typename Other>
280 inline const internal::triangular_solve_retval<Side,TriangularView, Other>
281 solve(
const MatrixBase<Other>& other)
const
317 return m_matrix.diagonal().prod();
322 MatrixTypeNested m_matrix;
343 typedef _MatrixType MatrixType;
344 typedef typename MatrixType::PlainObject DenseMatrixType;
345 typedef DenseMatrixType PlainObject;
348 using Base::evalToLazy;
368 template<
typename Other>
375 template<
typename Other>
391 void fill(
const Scalar& value) { setConstant(value); }
395 {
return *
this = MatrixType::Constant(derived().rows(), derived().cols(), value); }
409 Base::check_coordinates_internal(row, col);
410 return derived().nestedExpression().coeff(row, col);
420 Base::check_coordinates_internal(row, col);
421 return derived().nestedExpression().const_cast_derived().coeffRef(row, col);
425 template<
typename OtherDerived>
430 template<
typename OtherDerived>
434#ifndef EIGEN_PARSED_BY_DOXYGEN
437 {
return *
this = other.derived().nestedExpression(); }
440 template<
typename OtherDerived>
445 template<
typename OtherDerived>
451 template<
typename OtherDerived>
460 template<
typename OtherDerived>
friend
489 template<
int S
ide,
typename Other>
501 template<
int S
ide,
typename OtherDerived>
505 template<
typename OtherDerived>
511 template<
typename OtherDerived>
513#ifdef EIGEN_PARSED_BY_DOXYGEN
525 template<
typename OtherDerived>
533 template<
typename RhsType,
typename DstType>
538 this->solveInPlace(
dst);
541 template<
typename ProductType>
543 EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(
const ProductType& prod,
const Scalar& alpha);
551template<
typename MatrixType,
unsigned int Mode>
552template<
typename OtherDerived>
553inline TriangularView<MatrixType, Mode>&
554TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const MatrixBase<OtherDerived>& other)
556 internal::call_assignment_no_alias(derived(), other.derived(), internal::assign_op<Scalar>());
561template<
typename MatrixType,
unsigned int Mode>
562template<
typename OtherDerived>
563void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const MatrixBase<OtherDerived>& other)
565 internal::call_assignment_no_alias(derived(), other.template triangularView<Mode>());
570template<
typename MatrixType,
unsigned int Mode>
571template<
typename OtherDerived>
572inline TriangularView<MatrixType, Mode>&
573TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const TriangularBase<OtherDerived>& other)
575 eigen_assert(Mode ==
int(OtherDerived::Mode));
576 internal::call_assignment(derived(), other.derived());
580template<
typename MatrixType,
unsigned int Mode>
581template<
typename OtherDerived>
582void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const TriangularBase<OtherDerived>& other)
584 eigen_assert(Mode ==
int(OtherDerived::Mode));
585 internal::call_assignment_no_alias(derived(), other.derived());
594template<
typename Derived>
595template<
typename DenseDerived>
605 evalToLazy(other.derived());
627template<
typename Derived>
628template<
unsigned int Mode>
636template<
typename Derived>
637template<
unsigned int Mode>
649template<
typename Derived>
654 for(Index
j = 0;
j < cols(); ++
j)
656 Index maxi = (std::min)(
j, rows()-1);
657 for(Index i = 0; i <= maxi; ++i)
664 for(Index
j = 0;
j < cols(); ++
j)
665 for(Index i =
j+1; i < rows(); ++i)
666 if(abs(coeff(i,
j)) > threshold)
return false;
675template<
typename Derived>
680 for(Index
j = 0;
j < cols(); ++
j)
681 for(Index i =
j; i < rows(); ++i)
687 for(Index
j = 1;
j < cols(); ++
j)
689 Index maxi = (std::min)(
j, rows()-1);
690 for(Index i = 0; i < maxi; ++i)
691 if(abs(coeff(i,
j)) > threshold)
return false;
709template<
typename MatrixType,
unsigned int Mode>
717 static const int AssumeAliasing = 0;
720template<
typename MatrixType,
unsigned int Mode>
722 :
evaluator<typename internal::remove_all<MatrixType>::type>
743template<
int UpLo,
int Mode,
int SetOpposite,
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
748 typedef typename Base::DstXprType DstXprType;
749 typedef typename Base::SrcXprType SrcXprType;
752 using Base::m_functor;
755 typedef typename Base::DstEvaluatorType DstEvaluatorType;
756 typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
757 typedef typename Base::Scalar Scalar;
765#ifdef EIGEN_INTERNAL_DEBUGGING
768 eigen_internal_assert(row!=col);
778 else if(Mode==
ZeroDiag &&
SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(0));
784 eigen_internal_assert(row!=col);
786 m_functor.assignCoeff(m_dst.coeffRef(row,col), Scalar(0));
790template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType,
typename Functor>
791EIGEN_DEVICE_FUNC void call_triangular_assignment_loop(
const DstXprType&
dst,
const SrcXprType&
src,
const Functor &func)
793 eigen_assert(
dst.rows() ==
src.rows() &&
dst.cols() ==
src.cols());
798 DstEvaluatorType dstEvaluator(
dst);
799 SrcEvaluatorType srcEvaluator(
src);
802 DstEvaluatorType,SrcEvaluatorType,Functor>
Kernel;
803 Kernel kernel(dstEvaluator, srcEvaluator, func,
dst.const_cast_derived());
806 unroll = DstXprType::SizeAtCompileTime != Dynamic
807 && SrcEvaluatorType::CoeffReadCost < HugeCost
808 && DstXprType::SizeAtCompileTime * SrcEvaluatorType::CoeffReadCost / 2 <= EIGEN_UNROLLING_LIMIT
811 triangular_assignment_loop<
Kernel, Mode,
unroll ? int(DstXprType::SizeAtCompileTime) : Dynamic,
SetOpposite>::run(kernel);
814template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType>
815EIGEN_DEVICE_FUNC
void call_triangular_assignment_loop(
const DstXprType& dst,
const SrcXprType& src)
817 call_triangular_assignment_loop<Mode,SetOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar>());
825template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Scalar>
830 eigen_assert(
int(DstXprType::Mode) ==
int(SrcXprType::Mode));
836template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Scalar>
845template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Scalar>
855template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool SetOpposite>
859 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
860 typedef typename DstEvaluatorType::XprType DstXprType;
863 col = (
UnrollCount-1) / DstXprType::RowsAtCompileTime,
864 row = (
UnrollCount-1) % DstXprType::RowsAtCompileTime
867 typedef typename Kernel::Scalar Scalar;
870 static inline void run(
Kernel &kernel)
875 kernel.assignDiagonalCoeff(row);
876 else if( ((Mode&
Lower) && row>col) || ((Mode&
Upper) && row<col) )
877 kernel.assignCoeff(row,col);
879 kernel.assignOppositeCoeff(row,col);
884template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
888 static inline void run(
Kernel &) {}
897template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
900 typedef typename Kernel::Scalar Scalar;
902 static inline void run(
Kernel &kernel)
904 for(Index
j = 0;
j < kernel.cols(); ++
j)
906 Index maxi = (std::min)(
j, kernel.rows());
911 if(Mode&
Upper) kernel.assignCoeff(i,
j);
912 else kernel.assignOppositeCoeff(i,
j);
918 kernel.assignDiagonalCoeff(i++);
922 for(; i < kernel.rows(); ++i)
923 if(Mode&
Lower) kernel.assignCoeff(i,
j);
924 else kernel.assignOppositeCoeff(i,
j);
934template<
typename Derived>
935template<
typename DenseDerived>
938 other.derived().resize(this->rows(), this->cols());
939 internal::call_triangular_assignment_loop<Derived::Mode,(Derived::Mode&
SelfAdjoint)==0 >(other.derived(), derived().nestedExpression());
945template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
952 dst._assignProduct(
src, 1);
957template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
963 dst._assignProduct(
src, 1);
968template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
974 dst._assignProduct(
src, -1);
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:111
Pseudo expression representing a solving operation.
Definition Solve.h:63
Base class for triangular part in a matrix.
Definition TriangularMatrix.h:28
@ SizeAtCompileTime
This is equal to the number of coefficients, i.e.
Definition TriangularMatrix.h:38
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other &other)
Definition TriangularMatrix.h:84
EIGEN_DEVICE_FUNC TriangularViewType & setOnes()
Definition TriangularMatrix.h:401
EIGEN_DEVICE_FUNC void swap(TriangularBase< OtherDerived > const &other)
Swaps the coefficients of the common triangular parts of two matrices.
Definition TriangularMatrix.h:516
EIGEN_DEVICE_FUNC TriangularViewType & operator+=(const DenseBase< Other > &other)
Definition TriangularMatrix.h:370
EIGEN_DEVICE_FUNC const Product< TriangularViewType, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Efficient triangular matrix times vector/matrix product.
Definition TriangularMatrix.h:454
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
Definition TriangularMatrix.h:417
EIGEN_DEVICE_FUNC void swap(MatrixBase< OtherDerived > const &other)
Definition TriangularMatrix.h:527
EIGEN_DEVICE_FUNC const internal::triangular_solve_retval< Side, TriangularViewType, Other > solve(const MatrixBase< Other > &other) const
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:463
EIGEN_DEVICE_FUNC TriangularViewType & operator/=(const typename internal::traits< MatrixType >::Scalar &other)
Definition TriangularMatrix.h:387
EIGEN_DEVICE_FUNC void lazyAssign(const TriangularBase< OtherDerived > &other)
EIGEN_DEVICE_FUNC void solveInPlace(const MatrixBase< OtherDerived > &other) const
"in-place" version of TriangularView::solve() where the result is written in other
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
Definition TriangularMatrix.h:407
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:384
EIGEN_DEVICE_FUNC TriangularViewType & setConstant(const Scalar &value)
Definition TriangularMatrix.h:394
EIGEN_DEVICE_FUNC TriangularViewType & setZero()
Definition TriangularMatrix.h:398
EIGEN_DEVICE_FUNC void fill(const Scalar &value)
Definition TriangularMatrix.h:391
EIGEN_DEVICE_FUNC Index outerStride() const
Definition TriangularMatrix.h:361
EIGEN_DEVICE_FUNC void lazyAssign(const MatrixBase< OtherDerived > &other)
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:377
EIGEN_DEVICE_FUNC Index innerStride() const
Definition TriangularMatrix.h:365
Definition TriangularMatrix.h:184
Expression of a triangular part in a matrix.
Definition TriangularMatrix.h:188
EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const
Definition TriangularMatrix.h:265
EIGEN_DEVICE_FUNC const NestedExpression & nestedExpression() const
Definition TriangularMatrix.h:234
EIGEN_DEVICE_FUNC Index rows() const
Definition TriangularMatrix.h:227
EIGEN_DEVICE_FUNC Scalar determinant() const
Definition TriangularMatrix.h:310
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition TriangularMatrix.h:255
EIGEN_DEVICE_FUNC SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView()
Definition TriangularMatrix.h:292
EIGEN_DEVICE_FUNC const SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView() const
This is the const version of selfadjointView()
Definition TriangularMatrix.h:300
EIGEN_DEVICE_FUNC NestedExpression & nestedExpression()
Definition TriangularMatrix.h:238
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const
Definition TriangularMatrix.h:249
EIGEN_DEVICE_FUNC Index cols() const
Definition TriangularMatrix.h:230
EIGEN_DEVICE_FUNC const ConjugateReturnType conjugate() const
Definition TriangularMatrix.h:243
Definition AssignEvaluator.h:539
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:571
Definition TriangularMatrix.h:745
@ StrictlyLower
View matrix as a lower triangular matrix with zeros on the diagonal.
Definition Constants.h:216
@ UnitDiag
Matrix has ones on the diagonal; to be used in combination with #Lower or #Upper.
Definition Constants.h:208
@ StrictlyUpper
View matrix as an upper triangular matrix with zeros on the diagonal.
Definition Constants.h:218
@ UnitLower
View matrix as a lower triangular matrix with ones on the diagonal.
Definition Constants.h:212
@ ZeroDiag
Matrix has zeros on the diagonal; to be used in combination with #Lower or #Upper.
Definition Constants.h:210
@ SelfAdjoint
Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint.
Definition Constants.h:220
@ UnitUpper
View matrix as an upper triangular matrix with ones on the diagonal.
Definition Constants.h:214
@ Lower
View matrix as a lower triangular matrix.
Definition Constants.h:204
@ Upper
View matrix as an upper triangular matrix.
Definition Constants.h:206
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:88
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition Constants.h:124
const unsigned int EvalBeforeAssigningBit
Definition Constants.h:70
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition Constants.h:149
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition Constants.h:138
Definition Constants.h:511
The type used to identify a dense storage.
Definition Constants.h:490
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition EigenBase.h:29
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:37
Definition Constants.h:516
Definition AssignEvaluator.h:677
Definition AssignEvaluator.h:684
Definition TriangularMatrix.h:732
Definition Constants.h:525
Definition TriangularMatrix.h:731
Definition TriangularMatrix.h:730
Definition AssignmentFunctors.h:42
Definition AssignmentFunctors.h:21
Definition CoreEvaluators.h:75
Definition CoreEvaluators.h:82
Definition XprHelper.h:628
Definition XprHelper.h:235
Definition XprHelper.h:222
Definition AssignmentFunctors.h:63
Definition AssignmentFunctors.h:140
Definition ForwardDeclarations.h:17
Definition TriangularMatrix.h:857
Definition SolveTriangular.h:203
Definition CoreEvaluators.h:56