11 #ifndef EIGEN_TRIANGULARMATRIX_H 12 #define EIGEN_TRIANGULARMATRIX_H 18 template<
int S
ide,
typename TriangularType,
typename Rhs>
struct triangular_solve_retval;
59 inline Index rows()
const {
return derived().rows(); }
61 inline Index cols()
const {
return derived().cols(); }
82 template<
typename Other>
86 derived().coeffRef(row, col) = other.coeff(row, col);
92 check_coordinates(row, col);
93 return coeff(row,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>
134 || (mode==
Lower && col<=row)
139 #ifdef EIGEN_INTERNAL_DEBUGGING 142 check_coordinates(row, col);
168 template<
typename MatrixType,
unsigned int _Mode>
187 :
public TriangularViewImpl<_MatrixType, _Mode, typename internal::traits<_MatrixType>::StorageKind >
213 IsVectorAtCompileTime =
false 220 using Base::operator=;
222 {
return Base::operator=(other); }
248 inline const AdjointReturnType
adjoint()
const 249 {
return AdjointReturnType(m_matrix.adjoint()); }
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();
347 using Base::evalToLazy;
367 template<
typename Other>
374 template<
typename Other>
394 {
return *
this = MatrixType::Constant(derived().
rows(), derived().
cols(), value); }
408 Base::check_coordinates_internal(row, col);
409 return derived().nestedExpression().coeff(row, col);
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 490 template<
int S
ide,
typename Other>
504 template<
int S
ide,
typename OtherDerived>
508 template<
typename OtherDerived>
511 {
return solveInPlace<OnTheLeft>(other); }
514 template<
typename OtherDerived>
516 #ifdef EIGEN_PARSED_BY_DOXYGEN 528 template<
typename OtherDerived>
536 template<
typename RhsType,
typename DstType>
541 this->solveInPlace(dst);
544 template<
typename ProductType>
553 #ifndef EIGEN_PARSED_BY_DOXYGEN 555 template<
typename MatrixType,
unsigned int Mode>
556 template<
typename OtherDerived>
565 template<
typename MatrixType,
unsigned int Mode>
566 template<
typename OtherDerived>
574 template<
typename MatrixType,
unsigned int Mode>
575 template<
typename OtherDerived>
584 template<
typename MatrixType,
unsigned int Mode>
585 template<
typename OtherDerived>
599 template<
typename Derived>
600 template<
typename DenseDerived>
603 evalToLazy(other.derived());
625 template<
typename Derived>
626 template<
unsigned int Mode>
634 template<
typename Derived>
635 template<
unsigned int Mode>
647 template<
typename Derived>
657 if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
660 RealScalar threshold = maxAbsOnUpperPart * prec;
672 template<
typename Derived>
680 if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
682 RealScalar threshold = maxAbsOnLowerPart * prec;
705 template<
typename MatrixType,
unsigned int Mode>
712 template<
typename MatrixType,
unsigned int Mode>
714 :
evaluator<typename internal::remove_all<MatrixType>::type>
735 template<
int UpLo,
int Mode,
int SetOpposite,
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
744 using Base::m_functor;
754 : Base(dst, src, func, dstExpr)
757 #ifdef EIGEN_INTERNAL_DEBUGGING 761 Base::assignCoeff(row,col);
764 using Base::assignCoeff;
769 if(Mode==
UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id),
Scalar(1));
770 else if(Mode==
ZeroDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id),
Scalar(0));
771 else if(Mode==0) Base::assignCoeff(
id,
id);
778 m_functor.assignCoeff(m_dst.coeffRef(row,col),
Scalar(0));
782 template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType,
typename Functor>
789 SrcEvaluatorType srcEvaluator(src);
791 Index dstRows = src.rows();
792 Index dstCols = src.cols();
793 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
794 dst.resize(dstRows, dstCols);
795 DstEvaluatorType dstEvaluator(dst);
798 DstEvaluatorType,SrcEvaluatorType,
Functor> Kernel;
799 Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
802 unroll = DstXprType::SizeAtCompileTime !=
Dynamic 803 && SrcEvaluatorType::CoeffReadCost <
HugeCost 804 && DstXprType::SizeAtCompileTime * (DstEvaluatorType::CoeffReadCost+SrcEvaluatorType::CoeffReadCost) / 2 <=
EIGEN_UNROLLING_LIMIT 810 template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType>
822 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
825 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &
func)
827 eigen_assert(
int(DstXprType::Mode) ==
int(SrcXprType::Mode));
829 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src,
func);
833 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
836 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &
func)
838 call_triangular_assignment_loop<SrcXprType::Mode, (SrcXprType::Mode&SelfAdjoint)==0>(dst, src,
func);
842 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
845 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &
func)
847 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src,
func);
852 template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool SetOpposite>
860 col = (UnrollCount-1) / DstXprType::RowsAtCompileTime,
861 row = (UnrollCount-1) % DstXprType::RowsAtCompileTime
867 static inline void run(Kernel &kernel)
872 kernel.assignDiagonalCoeff(
row);
874 kernel.assignCoeff(
row,
col);
876 kernel.assignOppositeCoeff(
row,
col);
881 template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
885 static inline void run(Kernel &) {}
894 template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
899 static inline void run(Kernel &kernel)
901 for(
Index j = 0;
j < kernel.cols(); ++
j)
905 if (((Mode&
Lower) && SetOpposite) || (Mode&
Upper))
908 if(Mode&
Upper) kernel.assignCoeff(i,
j);
909 else kernel.assignOppositeCoeff(i,
j);
915 kernel.assignDiagonalCoeff(i++);
917 if (((Mode&
Upper) && SetOpposite) || (Mode&Lower))
919 for(; i < kernel.rows(); ++
i)
920 if(Mode&Lower) kernel.assignCoeff(i,
j);
921 else kernel.assignOppositeCoeff(i,
j);
931 template<
typename Derived>
932 template<
typename DenseDerived>
942 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
950 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
951 dst.resize(dstRows, dstCols);
953 dst._assignProduct(src, 1, 0);
958 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
964 dst._assignProduct(src, 1, 1);
969 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
975 dst._assignProduct(src, -1, 1);
983 #endif // EIGEN_TRIANGULARMATRIX_H EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const
Base::DstEvaluatorType DstEvaluatorType
EIGEN_DEVICE_FUNC void assignOppositeCoeff(Index row, Index col)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment_no_alias(Dst &dst, const Src &src, const Func &func)
#define EIGEN_STRONG_INLINE
Product< Lhs, Rhs, DefaultProduct > SrcXprType
remove_reference< MatrixTypeNested >::type MatrixTypeNestedNonRef
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
internal::remove_all< typename MatrixType::ConjugateReturnType >::type MatrixConjugateReturnType
EIGEN_DEVICE_FUNC void solveInPlace(const MatrixBase< OtherDerived > &other) const
SrcEvaluatorTypeT::XprType SrcXprType
Product< Lhs, Rhs, DefaultProduct > SrcXprType
Expression of the product of two arbitrary matrices or vectors.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
EIGEN_DEVICE_FUNC Scalar & coeffRef(Index row, Index col)
EIGEN_DEVICE_FUNC void swap(TriangularBase< OtherDerived > const &other)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
void check_coordinates_internal(Index, Index) const
TriangularView< MatrixType, Mode > XprType
bool is_same_dense(const T1 &mat1, const T2 &mat2, typename enable_if< has_direct_access< T1 >::ret &&has_direct_access< T2 >::ret, T1 >::type *=0)
TriangularView< typename MatrixType::TransposeReturnType, TransposeMode > TransposeReturnType
EIGEN_DEVICE_FUNC void evalToLazy(MatrixBase< DenseDerived > &other) const
TriangularView< _MatrixType, _Mode > TriangularViewType
Base class for triangular part in a matrix.
const unsigned int DirectAccessBit
static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op< Scalar, typename SrcXprType::Scalar > &)
generic_dense_assignment_kernel< DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version > Base
const unsigned int LvalueBit
EIGEN_DEVICE_FUNC Index rows() const
Base::AssignmentTraits AssignmentTraits
EIGEN_DEVICE_FUNC TriangularViewType & operator+=(const DenseBase< Other > &other)
bool isLowerTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
DstEvaluatorType::Scalar Scalar
internal::traits< Derived >::FullMatrixType DenseMatrixType
Namespace containing all symbols from the Eigen library.
EIGEN_DEVICE_FUNC TriangularViewType & setOnes()
TriangularView< const typename MatrixType::AdjointReturnType, TransposeMode > AdjointReturnType
DenseMatrixType PlainObject
glue_shapes< typename evaluator_traits< MatrixType >::Shape, TriangularShape >::type Shape
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
EIGEN_DEVICE_FUNC void resize(Index newSize)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
EIGEN_DEVICE_FUNC TriangularViewType & operator/=(const typename internal::traits< MatrixType >::Scalar &other)
ref_selector< MatrixType >::non_const_type MatrixTypeNested
EIGEN_DEVICE_FUNC Index innerStride() const
MatrixTypeNested m_matrix
EIGEN_DEVICE_FUNC void assignDiagonalCoeff(Index id)
Eigen::Index Index
The interface type of indices.
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Base class for all dense matrices, vectors, and arrays.
static EIGEN_DEVICE_FUNC void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
EIGEN_DEVICE_FUNC Index outerStride() const
const unsigned int PacketAccessBit
static EIGEN_DEVICE_FUNC void run(Kernel &kernel)
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
static EIGEN_DEVICE_FUNC void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
DenseMatrixType DenseType
friend EIGEN_DEVICE_FUNC const Product< OtherDerived, TriangularViewType > operator*(const MatrixBase< OtherDerived > &lhs, const TriangularViewImpl &rhs)
MatrixType ExpressionType
EIGEN_DEVICE_FUNC const NestedExpression & nestedExpression() const
void resize(Index rows, Index cols)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
EIGEN_DEVICE_FUNC void evalTo(MatrixBase< DenseDerived > &other) const
internal::traits< TriangularView >::Scalar Scalar
SrcEvaluatorTypeT SrcEvaluatorType
EIGEN_DEVICE_FUNC Derived & const_cast_derived() const
Product< Lhs, Rhs, DefaultProduct > SrcXprType
TriangularView< const typename MatrixType::ConstTransposeReturnType, TransposeMode > ConstTransposeReturnType
const unsigned int HereditaryBits
EIGEN_DEVICE_FUNC TriangularViewType & setConstant(const Scalar &value)
EIGEN_DEVICE_FUNC const Product< TriangularViewType, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
EIGEN_DEVICE_FUNC TriangularViewType & operator*=(const typename internal::traits< MatrixType >::Scalar &other)
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, Other &other)
EIGEN_DEVICE_FUNC Index outerStride() const
EIGEN_DEVICE_FUNC TriangularBase()
EIGEN_DEVICE_FUNC const Solve< TriangularView, Other > solve(const MatrixBase< Other > &other) const
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< Scalar, typename SrcXprType::Scalar > &)
EIGEN_DEVICE_FUNC const SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView() const
TriangularView< const MatrixConjugateReturnType, Mode > ConjugateReturnType
EIGEN_DEVICE_FUNC void swap(MatrixBase< OtherDerived > const &other)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
storage_kind_to_evaluator_kind< typename MatrixType::StorageKind >::Kind Kind
DstEvaluatorTypeT DstEvaluatorType
EIGEN_DEVICE_FUNC Scalar operator()(Index row, Index col) const
remove_all< MatrixTypeNested >::type MatrixTypeNestedCleaned
TriangularViewImpl< _MatrixType, _Mode, typename internal::traits< _MatrixType >::StorageKind > Base
EIGEN_DEVICE_FUNC Index innerStride() const
EIGEN_DEVICE_FUNC const ConjugateReturnType conjugate() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_triangular_assignment_loop(DstXprType &dst, const SrcXprType &src, const Functor &func)
static EIGEN_DEVICE_FUNC void run(Kernel &)
EIGEN_DEVICE_FUNC TriangularViewReturnType< Mode >::Type triangularView()
internal::traits< TriangularView >::MatrixTypeNested MatrixTypeNested
EIGEN_DEVICE_FUNC DenseMatrixType toDenseMatrix() const
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
EIGEN_DEVICE_FUNC const Derived & derived() const
EIGEN_DEVICE_FUNC Index cols() const
Base::SrcEvaluatorType SrcEvaluatorType
EIGEN_DEVICE_FUNC Derived & derived()
evaluator< typename internal::remove_all< MatrixType >::type > Base
Base::SrcXprType SrcXprType
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
internal::traits< TriangularView >::MatrixTypeNestedCleaned NestedExpression
EIGEN_DEVICE_FUNC NestedExpression & nestedExpression()
DstEvaluatorType::XprType DstXprType
EIGEN_DEVICE_FUNC TriangularViewType & operator-=(const DenseBase< Other > &other)
EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType &dstExpr)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _solve_impl(const RhsType &rhs, DstType &dst) const
DstEvaluatorTypeT::XprType DstXprType
Base::DstXprType DstXprType
EIGEN_DEVICE_FUNC Scalar & operator()(Index row, Index col)
EIGEN_DEVICE_FUNC Index cols() const
MatrixType::PlainObject FullMatrixType
static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op< Scalar, typename SrcXprType::Scalar > &)
MatrixType::PlainObject DenseMatrixType
EIGEN_DEVICE_FUNC Index rows() const
NumTraits< Scalar >::Real RealScalar
static EIGEN_DEVICE_FUNC void run(Kernel &kernel)
EIGEN_DEVICE_FUNC Scalar determinant() const
bool isUpperTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Expression of a triangular part in a matrix.
Triangular2Triangular Kind
internal::traits< Derived >::StorageKind StorageKind
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
internal::traits< TriangularViewType >::StorageKind StorageKind
internal::conditional< NumTraits< Scalar >::IsComplex, const CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, const Derived >, const Derived & >::type ConjugateReturnType
Pseudo expression representing a solving operation.
static EIGEN_DEVICE_FUNC void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
#define eigen_internal_assert(x)
internal::traits< Derived >::Scalar Scalar
Kernel::DstEvaluatorType DstEvaluatorType
EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col) const
EIGEN_DEVICE_FUNC TriangularViewType & operator=(const TriangularViewImpl &other)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
EIGEN_DEVICE_FUNC void fill(const Scalar &value)
TriangularBase< TriangularViewType > Base
unary_evaluator(const XprType &xpr)
TriangularView & operator=(const TriangularView &other)
Base class for all dense matrices, vectors, and expressions.
EIGEN_DEVICE_FUNC TriangularView(MatrixType &matrix)
const unsigned int LinearAccessBit
EIGEN_DEVICE_FUNC SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView()
internal::traits< TriangularView >::StorageKind StorageKind
void check_coordinates(Index row, Index col) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(Dst &dst, const Src &src)
#define EIGEN_UNROLLING_LIMIT
#define EIGEN_UNUSED_VARIABLE(var)
EIGEN_DEVICE_FUNC TriangularViewType & setZero()
void swap(scoped_array< T > &a, scoped_array< T > &b)
internal::traits< Derived >::StorageIndex StorageIndex
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
internal::traits< TriangularView >::MatrixTypeNestedNonRef MatrixTypeNestedNonRef
const Product< Lhs, Rhs > prod(const Lhs &lhs, const Rhs &rhs)
internal::traits< TriangularViewType >::Scalar Scalar