11 #ifndef EIGEN_TRIANGULARMATRIX_H 12 #define EIGEN_TRIANGULARMATRIX_H 18 template<
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); }
107 #endif // not EIGEN_PARSED_BY_DOXYGEN 109 template<
typename DenseDerived>
112 template<
typename DenseDerived>
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());
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 {}
168 template<
typename MatrixType,
unsigned int _Mode>
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 217 explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix)
220 using Base::operator=;
221 TriangularView& operator=(
const TriangularView &other)
222 {
return Base::operator=(other); }
243 {
return ConjugateReturnType(m_matrix.conjugate()); }
248 inline const AdjointReturnType
adjoint()
const 249 {
return AdjointReturnType(m_matrix.adjoint()); }
256 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
257 typename MatrixType::TransposeReturnType tmp(m_matrix);
258 return TransposeReturnType(tmp);
266 return ConstTransposeReturnType(m_matrix.transpose());
269 template<
typename Other>
277 template<
int S
ide,
typename Other>
281 {
return Base::template solve<Side>(other); }
316 return m_matrix.diagonal().prod();
321 MatrixTypeNested m_matrix;
342 typedef _MatrixType MatrixType;
343 typedef typename MatrixType::PlainObject DenseMatrixType;
344 typedef DenseMatrixType PlainObject;
347 using Base::evalToLazy;
367 template<
typename Other>
374 template<
typename Other>
390 void fill(
const Scalar& value) { setConstant(value); }
394 {
return *
this = MatrixType::Constant(derived().rows(), derived().cols(), value); }
397 TriangularViewType&
setZero() {
return setConstant(Scalar(0)); }
400 TriangularViewType&
setOnes() {
return setConstant(Scalar(1)); }
408 Base::check_coordinates_internal(row, col);
409 return derived().nestedExpression().coeff(row, col);
418 EIGEN_STATIC_ASSERT_LVALUE(TriangularViewType);
419 Base::check_coordinates_internal(row, col);
420 return derived().nestedExpression().coeffRef(row, col);
424 template<
typename OtherDerived>
429 template<
typename OtherDerived>
433 #ifndef EIGEN_PARSED_BY_DOXYGEN 436 {
return *
this = other.derived().nestedExpression(); }
439 template<
typename OtherDerived>
444 template<
typename OtherDerived>
450 template<
typename OtherDerived>
459 template<
typename OtherDerived>
friend 488 template<
int S
ide,
typename Other>
500 template<
int S
ide,
typename OtherDerived>
504 template<
typename OtherDerived>
507 {
return solveInPlace<OnTheLeft>(other); }
510 template<
typename OtherDerived>
512 #ifdef EIGEN_PARSED_BY_DOXYGEN 518 EIGEN_STATIC_ASSERT_LVALUE(OtherDerived);
524 template<
typename OtherDerived>
528 EIGEN_STATIC_ASSERT_LVALUE(OtherDerived);
532 template<
typename RhsType,
typename DstType>
534 EIGEN_STRONG_INLINE
void _solve_impl(
const RhsType &rhs, DstType &dst)
const {
535 if(!internal::is_same_dense(dst,rhs))
537 this->solveInPlace(dst);
540 template<
typename ProductType>
542 EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(
const ProductType& prod,
const Scalar& alpha);
550 template<
typename MatrixType,
unsigned int Mode>
551 template<
typename OtherDerived>
560 template<
typename MatrixType,
unsigned int Mode>
561 template<
typename OtherDerived>
564 internal::call_assignment_no_alias(derived(), other.template triangularView<Mode>());
569 template<
typename MatrixType,
unsigned int Mode>
570 template<
typename OtherDerived>
574 eigen_assert(Mode ==
int(OtherDerived::Mode));
575 internal::call_assignment(derived(), other.derived());
579 template<
typename MatrixType,
unsigned int Mode>
580 template<
typename OtherDerived>
583 eigen_assert(Mode ==
int(OtherDerived::Mode));
584 internal::call_assignment_no_alias(derived(), other.derived());
593 template<
typename Derived>
594 template<
typename DenseDerived>
597 evalToLazy(other.derived());
619 template<
typename Derived>
620 template<
unsigned int Mode>
624 return typename TriangularViewReturnType<Mode>::Type(derived());
628 template<
typename Derived>
629 template<
unsigned int Mode>
633 return typename ConstTriangularViewReturnType<Mode>::Type(derived());
641 template<
typename Derived>
644 RealScalar maxAbsOnUpperPart =
static_cast<RealScalar
>(-1);
645 for(
Index j = 0; j < cols(); ++j)
647 Index maxi = numext::mini(j, rows()-1);
648 for(
Index i = 0; i <= maxi; ++i)
650 RealScalar absValue = numext::abs(coeff(i,j));
651 if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
654 RealScalar threshold = maxAbsOnUpperPart * prec;
655 for(
Index j = 0; j < cols(); ++j)
656 for(
Index i = j+1; i < rows(); ++i)
657 if(numext::abs(coeff(i, j)) > threshold)
return false;
666 template<
typename Derived>
669 RealScalar maxAbsOnLowerPart =
static_cast<RealScalar
>(-1);
670 for(
Index j = 0; j < cols(); ++j)
671 for(
Index i = j; i < rows(); ++i)
673 RealScalar absValue = numext::abs(coeff(i,j));
674 if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
676 RealScalar threshold = maxAbsOnLowerPart * prec;
677 for(
Index j = 1; j < cols(); ++j)
679 Index maxi = numext::mini(j, rows()-1);
680 for(
Index i = 0; i < maxi; ++i)
681 if(numext::abs(coeff(i, j)) > threshold)
return false;
699 template<
typename MatrixType,
unsigned int Mode>
706 template<
typename MatrixType,
unsigned int Mode>
708 :
evaluator<typename internal::remove_all<MatrixType>::type>
729 template<
int UpLo,
int Mode,
int SetOpposite,
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
734 typedef typename Base::DstXprType DstXprType;
735 typedef typename Base::SrcXprType SrcXprType;
738 using Base::m_functor;
741 typedef typename Base::DstEvaluatorType DstEvaluatorType;
742 typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
743 typedef typename Base::Scalar Scalar;
748 : Base(dst, src, func, dstExpr)
751 #ifdef EIGEN_INTERNAL_DEBUGGING 752 EIGEN_DEVICE_FUNC
void assignCoeff(
Index row,
Index col)
754 eigen_internal_assert(row!=col);
755 Base::assignCoeff(row,col);
758 using Base::assignCoeff;
761 EIGEN_DEVICE_FUNC
void assignDiagonalCoeff(
Index id)
763 if(Mode==
UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(1));
764 else if(Mode==
ZeroDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(0));
765 else if(Mode==0) Base::assignCoeff(
id,
id);
768 EIGEN_DEVICE_FUNC
void assignOppositeCoeff(
Index row,
Index col)
770 eigen_internal_assert(row!=col);
772 m_functor.assignCoeff(m_dst.coeffRef(row,col), Scalar(0));
776 template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType,
typename Functor>
777 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
778 void call_triangular_assignment_loop(DstXprType& dst,
const SrcXprType& src,
const Functor &
func)
783 SrcEvaluatorType srcEvaluator(src);
785 Index dstRows = src.rows();
786 Index dstCols = src.cols();
787 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
788 dst.resize(dstRows, dstCols);
789 DstEvaluatorType dstEvaluator(dst);
792 DstEvaluatorType,SrcEvaluatorType,
Functor> Kernel;
793 Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
796 unroll = DstXprType::SizeAtCompileTime !=
Dynamic 797 && SrcEvaluatorType::CoeffReadCost <
HugeCost 798 && DstXprType::SizeAtCompileTime * (DstEvaluatorType::CoeffReadCost+SrcEvaluatorType::CoeffReadCost) / 2 <= EIGEN_UNROLLING_LIMIT
804 template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType>
805 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
806 void call_triangular_assignment_loop(DstXprType& dst,
const SrcXprType& src)
816 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
819 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
821 eigen_assert(
int(DstXprType::Mode) ==
int(SrcXprType::Mode));
823 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
827 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
830 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
832 call_triangular_assignment_loop<SrcXprType::Mode, (SrcXprType::Mode&SelfAdjoint)==0>(dst, src, func);
836 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
839 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
841 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
846 template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool SetOpposite>
850 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
851 typedef typename DstEvaluatorType::XprType DstXprType;
854 col = (UnrollCount-1) / DstXprType::RowsAtCompileTime,
855 row = (UnrollCount-1) % DstXprType::RowsAtCompileTime
858 typedef typename Kernel::Scalar Scalar;
861 static inline void run(Kernel &kernel)
866 kernel.assignDiagonalCoeff(row);
867 else if( ((Mode&
Lower) && row>col) || ((Mode&
Upper) && row<col) )
868 kernel.assignCoeff(row,col);
870 kernel.assignOppositeCoeff(row,col);
875 template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
879 static inline void run(Kernel &) {}
888 template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
891 typedef typename Kernel::Scalar Scalar;
893 static inline void run(Kernel &kernel)
895 for(
Index j = 0; j < kernel.cols(); ++j)
897 Index maxi = numext::mini(j, kernel.rows());
899 if (((Mode&
Lower) && SetOpposite) || (Mode&
Upper))
902 if(Mode&
Upper) kernel.assignCoeff(i, j);
903 else kernel.assignOppositeCoeff(i, j);
909 kernel.assignDiagonalCoeff(i++);
911 if (((Mode&
Upper) && SetOpposite) || (Mode&Lower))
913 for(; i < kernel.rows(); ++i)
914 if(Mode&Lower) kernel.assignCoeff(i, j);
915 else kernel.assignOppositeCoeff(i, j);
925 template<
typename Derived>
926 template<
typename DenseDerived>
929 other.derived().
resize(this->rows(), this->cols());
930 internal::call_triangular_assignment_loop<Derived::Mode,(Derived::Mode&
SelfAdjoint)==0 >(other.derived(), derived().nestedExpression());
936 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
942 Index dstRows = src.rows();
943 Index dstCols = src.cols();
944 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
945 dst.resize(dstRows, dstCols);
948 dst._assignProduct(src, 1);
953 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
959 dst._assignProduct(src, 1);
964 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
970 dst._assignProduct(src, -1);
978 #endif // EIGEN_TRIANGULARMATRIX_H Definition: NonLinearOptimization.cpp:108
Definition: AssignEvaluator.h:28
Definition: Constants.h:526
const int HugeCost
This value means that the cost to evaluate an expression coefficient is either very expensive or cann...
Definition: Constants.h:39
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
Definition: TriangularMatrix.h:416
EIGEN_DEVICE_FUNC void swap(TriangularBase< OtherDerived > const &other)
Swaps the coefficients of the common triangular parts of two matrices.
Definition: TriangularMatrix.h:515
View matrix as a lower triangular matrix with zeros on the diagonal.
Definition: Constants.h:216
Definition: SolveTriangular.h:201
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
Definition: TriangularMatrix.h:406
Definition: AssignmentFunctors.h:67
Definition: AssignmentFunctors.h:142
Base class for triangular part in a matrix.
Definition: TriangularMatrix.h:27
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array...
Definition: Constants.h:150
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition: Constants.h:139
Definition: TriangularMatrix.h:721
Definition: CoreEvaluators.h:90
Definition: CoreEvaluators.h:65
EIGEN_DEVICE_FUNC TriangularViewType & operator+=(const DenseBase< Other > &other)
Definition: TriangularMatrix.h:369
EIGEN_DEVICE_FUNC const SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView() const
This is the const version of selfadjointView()
Definition: TriangularMatrix.h:299
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Definition: TriangularMatrix.h:716
EIGEN_DEVICE_FUNC TriangularViewType & setOnes()
Definition: TriangularMatrix.h:400
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:241
EIGEN_DEVICE_FUNC TriangularViewType & operator/=(const typename internal::traits< MatrixType >::Scalar &other)
Definition: TriangularMatrix.h:386
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition: TriangularMatrix.h:254
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Definition: Constants.h:512
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition: Constants.h:89
EIGEN_DEVICE_FUNC Index rows() const
Definition: TriangularMatrix.h:226
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:462
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const
Definition: TriangularMatrix.h:248
Definition: AssignmentFunctors.h:21
Definition: AssignEvaluator.h:753
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
bool isUpperTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: TriangularMatrix.h:642
EIGEN_DEVICE_FUNC TriangularViewType & setConstant(const Scalar &value)
Definition: TriangularMatrix.h:393
EIGEN_DEVICE_FUNC TriangularViewType & operator*=(const typename internal::traits< MatrixType >::Scalar &other)
Definition: TriangularMatrix.h:383
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other &other)
Definition: TriangularMatrix.h:84
View matrix as a lower triangular matrix.
Definition: Constants.h:204
Definition: TriangularMatrix.h:717
Matrix has ones on the diagonal; to be used in combination with Lower or Upper.
Definition: Constants.h:208
EIGEN_DEVICE_FUNC Index innerStride() const
Definition: TriangularMatrix.h:364
EIGEN_DEVICE_FUNC void swap(MatrixBase< OtherDerived > const &other)
Definition: TriangularMatrix.h:526
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC const Product< TriangularViewType, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
Efficient triangular matrix times vector/matrix product.
Definition: TriangularMatrix.h:453
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition: SelfAdjointView.h:49
View matrix as an upper triangular matrix with zeros on the diagonal.
Definition: Constants.h:218
Definition: XprHelper.h:396
Definition: TriangularMatrix.h:730
View matrix as an upper triangular matrix with ones on the diagonal.
Definition: Constants.h:214
View matrix as an upper triangular matrix.
Definition: Constants.h:206
EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const
Definition: TriangularMatrix.h:264
EIGEN_DEVICE_FUNC Index cols() const
Definition: TriangularMatrix.h:229
EIGEN_DEVICE_FUNC NestedExpression & nestedExpression()
Definition: TriangularMatrix.h:237
EIGEN_DEVICE_FUNC TriangularViewType & operator-=(const DenseBase< Other > &other)
Definition: TriangularMatrix.h:376
Definition: XprHelper.h:648
EIGEN_DEVICE_FUNC Index outerStride() const
Definition: TriangularMatrix.h:360
Definition: benchGeometry.cpp:23
Matrix has zeros on the diagonal; to be used in combination with Lower or Upper.
Definition: Constants.h:210
View matrix as a lower triangular matrix with ones on the diagonal.
Definition: Constants.h:212
Definition: BandTriangularSolver.h:13
Definition: TriangularMatrix.h:184
bool isLowerTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: TriangularMatrix.h:667
Definition: CoreEvaluators.h:79
Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint.
Definition: Constants.h:220
Definition: AssignEvaluator.h:740
EIGEN_DEVICE_FUNC const ConjugateReturnType conjugate() const
Definition: TriangularMatrix.h:242
Expression of a triangular part in a matrix.
Definition: TriangularMatrix.h:186
EIGEN_DEVICE_FUNC const NestedExpression & nestedExpression() const
Definition: TriangularMatrix.h:233
EIGEN_DEVICE_FUNC Scalar determinant() const
Definition: TriangularMatrix.h:309
The type used to identify a dense storage.
Definition: Constants.h:491
Definition: AssignmentFunctors.h:46
Definition: Constants.h:517
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Pseudo expression representing a solving operation.
Definition: Solve.h:62
Definition: AssignEvaluator.h:596
EIGEN_DEVICE_FUNC void fill(const Scalar &value)
Definition: TriangularMatrix.h:390
Definition: TriangularMatrix.h:718
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition: Constants.h:125
EIGEN_DEVICE_FUNC SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView()
Definition: TriangularMatrix.h:291
Definition: ForwardDeclarations.h:17
Definition: XprHelper.h:630
Definition: XprHelper.h:261
EIGEN_DEVICE_FUNC TriangularViewType & setZero()
Definition: TriangularMatrix.h:397