11 #ifndef EIGEN_TRIANGULARMATRIX_H 12 #define EIGEN_TRIANGULARMATRIX_H 18 template<
int S
ide,
typename TriangularType,
typename Rhs>
struct triangular_solve_retval;
45 typedef DenseMatrixType DenseType;
49 inline Index rows()
const {
return derived().rows(); }
50 inline Index cols()
const {
return derived().cols(); }
51 inline Index outerStride()
const {
return derived().outerStride(); }
52 inline Index innerStride()
const {
return derived().innerStride(); }
54 inline Scalar coeff(Index row, Index col)
const {
return derived().coeff(row,col); }
55 inline Scalar& coeffRef(Index row, Index col) {
return derived().coeffRef(row,col); }
59 template<
typename Other>
60 EIGEN_STRONG_INLINE
void copyCoeff(Index row, Index col, Other& other)
62 derived().coeffRef(row, col) = other.coeff(row, col);
65 inline Scalar operator()(Index row, Index col)
const 67 check_coordinates(row, col);
68 return coeff(row,col);
70 inline Scalar& operator()(Index row, Index col)
72 check_coordinates(row, col);
73 return coeffRef(row,col);
76 #ifndef EIGEN_PARSED_BY_DOXYGEN 77 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
78 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
79 #endif // not EIGEN_PARSED_BY_DOXYGEN 81 template<
typename DenseDerived>
83 template<
typename DenseDerived>
86 DenseMatrixType toDenseMatrix()
const 88 DenseMatrixType res(rows(), cols());
95 void check_coordinates(Index row, Index col)
const 97 EIGEN_ONLY_USED_FOR_DEBUG(row);
98 EIGEN_ONLY_USED_FOR_DEBUG(col);
99 eigen_assert(col>=0 && col<cols() && row>=0 && row<rows());
101 EIGEN_ONLY_USED_FOR_DEBUG(mode);
102 eigen_assert((mode==
Upper && col>=row)
103 || (mode==
Lower && col<=row)
108 #ifdef EIGEN_INTERNAL_DEBUGGING 109 void check_coordinates_internal(Index row, Index col)
const 111 check_coordinates(row, col);
114 void check_coordinates_internal(Index , Index )
const {}
137 template<
typename MatrixType,
unsigned int _Mode>
144 typedef typename MatrixType::PlainObject DenseMatrixType;
148 CoeffReadCost = MatrixTypeNestedCleaned::CoeffReadCost
153 template<
int Mode,
bool LhsIsTriangular,
154 typename Lhs,
bool LhsIsVector,
155 typename Rhs,
bool RhsIsVector>
166 typedef _MatrixType MatrixType;
168 typedef DenseMatrixType PlainObject;
178 using Base::evalToLazy;
192 inline TriangularView(
const MatrixType& matrix) : m_matrix(matrix)
195 inline Index rows()
const {
return m_matrix.rows(); }
196 inline Index cols()
const {
return m_matrix.cols(); }
197 inline Index outerStride()
const {
return m_matrix.outerStride(); }
198 inline Index innerStride()
const {
return m_matrix.innerStride(); }
210 void fill(
const Scalar& value) { setConstant(value); }
213 {
return *
this = MatrixType::Constant(rows(), cols(), value); }
222 inline Scalar
coeff(Index row, Index col)
const 224 Base::check_coordinates_internal(row, col);
225 return m_matrix.coeff(row, col);
233 Base::check_coordinates_internal(row, col);
234 return m_matrix.const_cast_derived().coeffRef(row, col);
237 const MatrixTypeNestedCleaned& nestedExpression()
const {
return m_matrix; }
238 MatrixTypeNestedCleaned& nestedExpression() {
return *
const_cast<MatrixTypeNestedCleaned*
>(&m_matrix); }
241 template<
typename OtherDerived>
244 template<
typename OtherDerived>
248 {
return *
this = other.nestedExpression(); }
250 template<
typename OtherDerived>
253 template<
typename OtherDerived>
258 {
return m_matrix.conjugate(); }
261 {
return m_matrix.conjugate(); }
265 {
return m_matrix.adjoint(); }
270 EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
271 return m_matrix.const_cast_derived().transpose();
276 return m_matrix.transpose();
280 template<
typename OtherDerived>
285 <Mode,
true, MatrixType,
false, OtherDerived, OtherDerived::ColsAtCompileTime==1>
286 (m_matrix, rhs.derived());
290 template<
typename OtherDerived>
friend 295 <Mode,
false, OtherDerived, OtherDerived::RowsAtCompileTime==1, MatrixType,
false>
296 (lhs.derived(),rhs.m_matrix);
299 #ifdef EIGEN2_SUPPORT 300 template<
typename OtherDerived>
301 struct eigen2_product_return_type
303 typedef typename TriangularView<MatrixType,Mode>::DenseMatrixType DenseMatrixType;
304 typedef typename OtherDerived::PlainObject::DenseType OtherPlainObject;
306 typedef typename ProdRetType::PlainObject type;
308 template<
typename OtherDerived>
309 const typename eigen2_product_return_type<OtherDerived>::type
312 typename OtherDerived::PlainObject::DenseType rhsPlainObject;
313 rhs.evalTo(rhsPlainObject);
314 return this->toDenseMatrix() * rhsPlainObject;
316 template<
typename OtherMatrixType>
319 return this->toDenseMatrix().isApprox(other.toDenseMatrix(), precision);
321 template<
typename OtherDerived>
324 return this->toDenseMatrix().isApprox(other, precision);
326 #endif // EIGEN2_SUPPORT 328 template<
int S
ide,
typename Other>
332 template<
int S
ide,
typename OtherDerived>
335 template<
typename Other>
338 {
return solve<OnTheLeft>(other); }
340 template<
typename OtherDerived>
342 {
return solveInPlace<OnTheLeft>(other); }
346 EIGEN_STATIC_ASSERT((Mode&
UnitDiag)==0,PROGRAMMING_ERROR);
351 EIGEN_STATIC_ASSERT((Mode&
UnitDiag)==0,PROGRAMMING_ERROR);
355 template<
typename OtherDerived>
361 template<
typename OtherDerived>
368 Scalar determinant()
const 375 return m_matrix.diagonal().prod();
379 template<
typename ProductDerived,
typename Lhs,
typename Rhs>
383 return assignProduct(other.derived(),1);
386 template<
typename ProductDerived,
typename Lhs,
typename Rhs>
389 return assignProduct(other.derived(),1);
392 template<
typename ProductDerived,
typename Lhs,
typename Rhs>
395 return assignProduct(other.derived(),-1);
399 template<
typename ProductDerived>
403 return assignProduct(other.derived(),other.alpha());
406 template<
typename ProductDerived>
409 return assignProduct(other.derived(),other.alpha());
412 template<
typename ProductDerived>
415 return assignProduct(other.derived(),-other.alpha());
420 template<
typename ProductDerived,
typename Lhs,
typename Rhs>
423 template<
int Mode,
bool LhsIsTriangular,
424 typename Lhs,
bool LhsIsVector,
425 typename Rhs,
bool RhsIsVector>
428 lazyAssign(alpha*prod.eval());
432 MatrixTypeNested m_matrix;
441 template<
typename Derived1,
typename Derived2,
unsigned int Mode,
int UnrollCount,
bool ClearOpposite>
445 col = (UnrollCount-1) / Derived1::RowsAtCompileTime,
446 row = (UnrollCount-1) % Derived1::RowsAtCompileTime
451 static inline void run(Derived1 &dst,
const Derived2 &src)
458 if((Mode ==
Upper && row <= col)
459 || (Mode ==
Lower && row >= col)
464 dst.copyCoeff(row, col, src);
465 else if(ClearOpposite)
468 dst.coeffRef(row, col) =
Scalar(1);
470 dst.coeffRef(row, col) =
Scalar(0);
476 template<
typename Derived1,
typename Derived2,
unsigned int Mode,
bool ClearOpposite>
479 static inline void run(Derived1 &,
const Derived2 &) {}
482 template<
typename Derived1,
typename Derived2,
bool ClearOpposite>
485 typedef typename Derived1::Index Index;
487 static inline void run(Derived1 &dst,
const Derived2 &src)
489 for(Index j = 0; j < dst.cols(); ++j)
491 Index maxi = (std::min)(j, dst.rows()-1);
492 for(Index i = 0; i <= maxi; ++i)
493 dst.copyCoeff(i, j, src);
495 for(Index i = maxi+1; i < dst.rows(); ++i)
496 dst.coeffRef(i, j) =
Scalar(0);
501 template<
typename Derived1,
typename Derived2,
bool ClearOpposite>
504 typedef typename Derived1::Index Index;
505 static inline void run(Derived1 &dst,
const Derived2 &src)
507 for(Index j = 0; j < dst.cols(); ++j)
509 for(Index i = j; i < dst.rows(); ++i)
510 dst.copyCoeff(i, j, src);
511 Index maxi = (std::min)(j, dst.rows());
513 for(Index i = 0; i < maxi; ++i)
519 template<
typename Derived1,
typename Derived2,
bool ClearOpposite>
522 typedef typename Derived1::Index Index;
524 static inline void run(Derived1 &dst,
const Derived2 &src)
526 for(Index j = 0; j < dst.cols(); ++j)
528 Index maxi = (std::min)(j, dst.rows());
529 for(Index i = 0; i < maxi; ++i)
530 dst.copyCoeff(i, j, src);
532 for(Index i = maxi; i < dst.rows(); ++i)
533 dst.coeffRef(i, j) =
Scalar(0);
538 template<
typename Derived1,
typename Derived2,
bool ClearOpposite>
541 typedef typename Derived1::Index Index;
542 static inline void run(Derived1 &dst,
const Derived2 &src)
544 for(Index j = 0; j < dst.cols(); ++j)
546 for(Index i = j+1; i < dst.rows(); ++i)
547 dst.copyCoeff(i, j, src);
548 Index maxi = (std::min)(j, dst.rows()-1);
550 for(Index i = 0; i <= maxi; ++i)
556 template<
typename Derived1,
typename Derived2,
bool ClearOpposite>
559 typedef typename Derived1::Index Index;
560 static inline void run(Derived1 &dst,
const Derived2 &src)
562 for(Index j = 0; j < dst.cols(); ++j)
564 Index maxi = (std::min)(j, dst.rows());
565 for(Index i = 0; i < maxi; ++i)
566 dst.copyCoeff(i, j, src);
569 for(Index i = maxi+1; i < dst.rows(); ++i)
570 dst.coeffRef(i, j) = 0;
573 dst.diagonal().setOnes();
576 template<
typename Derived1,
typename Derived2,
bool ClearOpposite>
579 typedef typename Derived1::Index Index;
580 static inline void run(Derived1 &dst,
const Derived2 &src)
582 for(Index j = 0; j < dst.cols(); ++j)
584 Index maxi = (std::min)(j, dst.rows());
585 for(Index i = maxi+1; i < dst.rows(); ++i)
586 dst.copyCoeff(i, j, src);
589 for(Index i = 0; i < maxi; ++i)
590 dst.coeffRef(i, j) = 0;
593 dst.diagonal().setOnes();
600 template<
typename MatrixType,
unsigned int Mode>
601 template<
typename OtherDerived>
608 other_evaluated.template triangularView<Mode>().lazyAssign(other.derived());
609 lazyAssign(other_evaluated);
612 lazyAssign(other.derived());
617 template<
typename MatrixType,
unsigned int Mode>
618 template<
typename OtherDerived>
622 unroll = MatrixType::SizeAtCompileTime !=
Dynamic 626 eigen_assert(m_matrix.rows() == other.rows() && m_matrix.cols() == other.cols());
630 unroll ? int(MatrixType::SizeAtCompileTime) :
Dynamic,
632 >::run(m_matrix.const_cast_derived(), other.derived());
637 template<
typename MatrixType,
unsigned int Mode>
638 template<
typename OtherDerived>
642 eigen_assert(Mode ==
int(OtherDerived::Mode));
645 typename OtherDerived::DenseMatrixType other_evaluated(other.rows(), other.cols());
646 other_evaluated.template triangularView<Mode>().lazyAssign(other.derived().nestedExpression());
647 lazyAssign(other_evaluated);
650 lazyAssign(other.derived().nestedExpression());
654 template<
typename MatrixType,
unsigned int Mode>
655 template<
typename OtherDerived>
659 unroll = MatrixType::SizeAtCompileTime !=
Dynamic 662 <= EIGEN_UNROLLING_LIMIT
664 eigen_assert(m_matrix.rows() == other.rows() && m_matrix.cols() == other.cols());
668 unroll ? int(MatrixType::SizeAtCompileTime) :
Dynamic,
670 >::run(m_matrix.const_cast_derived(), other.derived().nestedExpression());
679 template<
typename Derived>
680 template<
typename DenseDerived>
686 evalToLazy(other_evaluated);
687 other.derived().
swap(other_evaluated);
690 evalToLazy(other.derived());
695 template<
typename Derived>
696 template<
typename DenseDerived>
700 unroll = DenseDerived::SizeAtCompileTime !=
Dynamic 703 <= EIGEN_UNROLLING_LIMIT
705 other.derived().
resize(this->rows(), this->cols());
709 unroll ? int(DenseDerived::SizeAtCompileTime) :
Dynamic,
711 >::run(other.derived(), derived().nestedExpression());
722 #ifdef EIGEN2_SUPPORT 727 template<
typename MatrixType,
unsigned int Mode>
728 struct eigen2_part_return_type
733 template<
typename MatrixType>
734 struct eigen2_part_return_type<MatrixType, SelfAdjoint>
741 template<
typename Derived>
742 template<
unsigned int Mode>
749 template<
typename Derived>
750 template<
unsigned int Mode>
768 template<
typename Derived>
769 template<
unsigned int Mode>
777 template<
typename Derived>
778 template<
unsigned int Mode>
790 template<
typename Derived>
794 RealScalar maxAbsOnUpperPart =
static_cast<RealScalar
>(-1);
795 for(
Index j = 0; j < cols(); ++j)
797 Index maxi = (std::min)(j, rows()-1);
798 for(
Index i = 0; i <= maxi; ++i)
800 RealScalar absValue = abs(coeff(i,j));
801 if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
804 RealScalar threshold = maxAbsOnUpperPart * prec;
805 for(
Index j = 0; j < cols(); ++j)
806 for(
Index i = j+1; i < rows(); ++i)
807 if(abs(coeff(i, j)) > threshold)
return false;
816 template<
typename Derived>
820 RealScalar maxAbsOnLowerPart =
static_cast<RealScalar
>(-1);
821 for(
Index j = 0; j < cols(); ++j)
822 for(
Index i = j; i < rows(); ++i)
824 RealScalar absValue = abs(coeff(i,j));
825 if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
827 RealScalar threshold = maxAbsOnLowerPart * prec;
828 for(
Index j = 1; j < cols(); ++j)
830 Index maxi = (std::min)(j, rows()-1);
831 for(
Index i = 0; i < maxi; ++i)
832 if(abs(coeff(i, j)) > threshold)
return false;
839 #endif // EIGEN_TRIANGULARMATRIX_H Expression of the product of two general matrices or vectors.
Definition: GeneralProduct.h:36
View matrix as an upper triangular matrix with ones on the diagonal.
Definition: Constants.h:177
TriangularView< Transpose< MatrixType >, TransposeMode > transpose()
Definition: TriangularMatrix.h:268
View matrix as a lower triangular matrix with zeros on the diagonal.
Definition: Constants.h:179
Definition: SolveTriangular.h:230
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
Definition: ProductBase.h:63
Definition: TriangularMatrix.h:29
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array...
Definition: Constants.h:142
EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other &other)
Definition: TriangularMatrix.h:60
Definition: XprHelper.h:170
View matrix as a lower triangular matrix with ones on the diagonal.
Definition: Constants.h:175
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Matrix has ones on the diagonal; to be used in combination with Lower or Upper.
Definition: Constants.h:171
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:539
Matrix has zeros on the diagonal; to be used in combination with Lower or Upper.
Definition: Constants.h:173
const TriangularView< const typename MatrixType::AdjointReturnType, TransposeMode > adjoint() const
Definition: TriangularMatrix.h:264
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition: Constants.h:81
void resize(Index newSize)
Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods...
Definition: DenseBase.h:213
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:26
TriangularView & operator-=(const DenseBase< Other > &other)
Definition: TriangularMatrix.h:203
bool isUpperTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: TriangularMatrix.h:791
View matrix as an upper triangular matrix.
Definition: Constants.h:169
Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint.
Definition: Constants.h:183
const TriangularView< Transpose< MatrixType >, TransposeMode > transpose() const
Definition: TriangularMatrix.h:274
TriangularView & operator*=(const typename internal::traits< MatrixType >::Scalar &other)
Definition: TriangularMatrix.h:205
friend TriangularProduct< Mode, false, OtherDerived, OtherDerived::RowsAtCompileTime==1, MatrixType, false > operator*(const MatrixBase< OtherDerived > &lhs, const TriangularView &rhs)
Efficient vector/matrix times triangular matrix product.
Definition: TriangularMatrix.h:292
View matrix as an upper triangular matrix with zeros on the diagonal.
Definition: Constants.h:181
void evalTo(MatrixBase< DenseDerived > &other) const
Assigns a triangular or selfadjoint matrix to a dense matrix.
Definition: TriangularMatrix.h:681
Definition: TriangularMatrix.h:442
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Definition: SelfAdjointView.h:53
TriangularView< MatrixConjugateReturnType, Mode > conjugate()
Definition: TriangularMatrix.h:257
const unsigned int EvalBeforeAssigningBit
means the expression should be evaluated before any assignment
Definition: Constants.h:63
TriangularView & operator=(const TriangularBase< OtherDerived > &other)
Assigns a triangular matrix to a triangular part of a dense matrix.
TriangularView & setZero()
Definition: TriangularMatrix.h:215
Definition: TriangularMatrix.h:156
Definition: ProductBase.h:200
TriangularView & setConstant(const Scalar &value)
Definition: TriangularMatrix.h:212
Definition: BandTriangularSolver.h:13
bool isLowerTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: TriangularMatrix.h:817
Scalar & coeffRef(Index row, Index col)
Definition: TriangularMatrix.h:231
Base class for triangular part in a matrix.
Definition: TriangularMatrix.h:158
TriangularView & operator+=(const DenseBase< Other > &other)
Definition: TriangularMatrix.h:201
TriangularView & operator/=(const typename internal::traits< MatrixType >::Scalar &other)
Definition: TriangularMatrix.h:207
TriangularView & setOnes()
Definition: TriangularMatrix.h:217
View matrix as a lower triangular matrix.
Definition: Constants.h:167
void swap(const DenseBase< OtherDerived > &other, int=OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
swaps *this with the expression other.
Definition: DenseBase.h:372
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
Scalar coeff(Index row, Index col) const
Definition: TriangularMatrix.h:222
const TriangularView< MatrixConjugateReturnType, Mode > conjugate() const
Definition: TriangularMatrix.h:260
void fill(const Scalar &value)
Definition: TriangularMatrix.h:210
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:117
Definition: ForwardDeclarations.h:17
TriangularProduct< Mode, true, MatrixType, false, OtherDerived, OtherDerived::ColsAtCompileTime==1 > operator*(const MatrixBase< OtherDerived > &rhs) const
Efficient triangular matrix times vector/matrix product.
Definition: TriangularMatrix.h:282
void evalToLazy(MatrixBase< DenseDerived > &other) const
Assigns a triangular or selfadjoint matrix to a dense matrix.
Definition: TriangularMatrix.h:697
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48