11 #ifndef EIGEN_TRIANGULARMATRIX_H
12 #define EIGEN_TRIANGULARMATRIX_H
20 template<
int S
ide,
typename TriangularType,
typename Rhs>
struct triangular_solve_retval;
34 Mode = internal::traits<Derived>::Mode,
46 internal::traits<Derived>::MaxColsAtCompileTime)
49 typedef typename internal::traits<Derived>::Scalar
Scalar;
50 typedef typename internal::traits<Derived>::StorageKind
StorageKind;
51 typedef typename internal::traits<Derived>::StorageIndex
StorageIndex;
84 template<
typename Other>
104 #ifndef EIGEN_PARSED_BY_DOXYGEN
106 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
108 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
111 template<
typename DenseDerived>
114 template<
typename DenseDerived>
141 #ifdef EIGEN_INTERNAL_DEBUGGING
170 template<
typename MatrixType,
unsigned int Mode_>
171 struct traits<TriangularView<
MatrixType, Mode_> > : traits<MatrixType>
173 typedef typename ref_selector<MatrixType>::non_const_type MatrixTypeNested;
174 typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNestedNonRef;
175 typedef remove_all_t<MatrixTypeNested> MatrixTypeNestedCleaned;
180 FlagsLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
189 :
public TriangularViewImpl<MatrixType_, Mode_, typename internal::traits<MatrixType_>::StorageKind >
194 typedef typename internal::traits<TriangularView>::Scalar
Scalar;
206 typedef typename internal::traits<TriangularView>::StorageKind
StorageKind;
207 typedef typename internal::traits<TriangularView>::MatrixTypeNestedCleaned
NestedExpression;
211 Flags = internal::traits<TriangularView>::Flags,
251 inline std::conditional_t<Cond,ConjugateReturnType,ConstTriangularView>
254 typedef std::conditional_t<Cond,ConjugateReturnType,ConstTriangularView> ReturnType;
255 return ReturnType(
m_matrix.template conjugateIf<Cond>());
266 template<
class Dummy=
int>
282 template<
typename Other>
290 template<
int S
ide,
typename Other>
292 inline const internal::triangular_solve_retval<Side,TriangularView, Other>
294 {
return Base::template solve<Side>(other); }
354 typedef typename internal::traits<TriangularViewType>::Scalar
Scalar;
361 using Base::evalToLazy;
364 typedef typename internal::traits<TriangularViewType>::StorageKind
StorageKind;
368 Flags = internal::traits<TriangularViewType>::Flags
381 template<
typename Other>
388 template<
typename Other>
408 {
return *
this = MatrixType::Constant(derived().
rows(), derived().
cols(), value); }
422 Base::check_coordinates_internal(
row,
col);
423 return derived().nestedExpression().coeff(
row,
col);
433 Base::check_coordinates_internal(
row,
col);
434 return derived().nestedExpression().coeffRef(
row,
col);
438 template<
typename OtherDerived>
443 template<
typename OtherDerived>
447 #ifndef EIGEN_PARSED_BY_DOXYGEN
450 {
return *
this = other.derived().nestedExpression(); }
452 template<
typename OtherDerived>
457 template<
typename OtherDerived>
464 template<
typename OtherDerived>
473 template<
typename OtherDerived>
friend
504 template<
int S
ide,
typename Other>
505 inline const internal::triangular_solve_retval<Side,TriangularViewType, Other>
517 template<
int S
ide,
typename OtherDerived>
521 template<
typename OtherDerived>
524 {
return solveInPlace<OnTheLeft>(other); }
527 template<
typename OtherDerived>
529 #ifdef EIGEN_PARSED_BY_DOXYGEN
540 template<
typename OtherDerived>
549 template<
typename RhsType,
typename DstType>
551 EIGEN_STRONG_INLINE
void _solve_impl(
const RhsType &rhs, DstType &dst)
const {
554 this->solveInPlace(dst);
557 template<
typename ProductType>
570 #ifndef EIGEN_PARSED_BY_DOXYGEN
572 template<
typename MatrixType,
unsigned int Mode>
573 template<
typename OtherDerived>
582 template<
typename MatrixType,
unsigned int Mode>
583 template<
typename OtherDerived>
584 EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const MatrixBase<OtherDerived>& other)
591 template<
typename MatrixType,
unsigned int Mode>
592 template<
typename OtherDerived>
594 TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const TriangularBase<OtherDerived>& other)
601 template<
typename MatrixType,
unsigned int Mode>
602 template<
typename OtherDerived>
603 EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const TriangularBase<OtherDerived>& other)
616 template<
typename Derived>
617 template<
typename DenseDerived>
642 template<
typename Derived>
643 template<
unsigned int Mode>
652 template<
typename Derived>
653 template<
unsigned int Mode>
666 template<
typename Derived>
676 if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
679 RealScalar threshold = maxAbsOnUpperPart * prec;
691 template<
typename Derived>
699 if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
701 RealScalar threshold = maxAbsOnLowerPart * prec;
724 template<
typename MatrixType,
unsigned int Mode>
727 typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind;
728 typedef typename glue_shapes<typename evaluator_traits<MatrixType>::Shape,
TriangularShape>::type Shape;
731 template<
typename MatrixType,
unsigned int Mode>
732 struct unary_evaluator<TriangularView<
MatrixType,Mode>, IndexBased>
733 : evaluator<internal::remove_all_t<MatrixType>>
735 typedef TriangularView<MatrixType,Mode> XprType;
736 typedef evaluator<internal::remove_all_t<MatrixType>> Base;
738 unary_evaluator(
const XprType &xpr) : Base(xpr.nestedExpression()) {}
742 struct Triangular2Triangular {};
743 struct Triangular2Dense {};
744 struct Dense2Triangular {};
747 template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool ClearOpposite>
struct triangular_assignment_loop;
755 template<
int UpLo,
int Mode,
int SetOpposite,
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
756 class triangular_dense_assignment_kernel :
public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
759 typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> Base;
760 typedef typename Base::DstXprType DstXprType;
761 typedef typename Base::SrcXprType SrcXprType;
764 using Base::m_functor;
767 typedef typename Base::DstEvaluatorType DstEvaluatorType;
768 typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
769 typedef typename Base::Scalar Scalar;
770 typedef typename Base::AssignmentTraits AssignmentTraits;
773 EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst,
const SrcEvaluatorType &src,
const Functor &func, DstXprType& dstExpr)
774 : Base(dst, src, func, dstExpr)
777 #ifdef EIGEN_INTERNAL_DEBUGGING
781 Base::assignCoeff(
row,
col);
784 using Base::assignCoeff;
789 if(Mode==
UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(1));
790 else if(Mode==
ZeroDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(0));
791 else if(Mode==0) Base::assignCoeff(
id,
id);
798 m_functor.assignCoeff(m_dst.coeffRef(
row,
col), Scalar(0));
802 template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType,
typename Functor>
806 typedef evaluator<DstXprType> DstEvaluatorType;
807 typedef evaluator<SrcXprType> SrcEvaluatorType;
809 SrcEvaluatorType srcEvaluator(src);
811 Index dstRows = src.rows();
812 Index dstCols = src.cols();
813 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
814 dst.resize(dstRows, dstCols);
815 DstEvaluatorType dstEvaluator(dst);
818 DstEvaluatorType,SrcEvaluatorType,Functor> Kernel;
819 Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
822 unroll = DstXprType::SizeAtCompileTime !=
Dynamic
823 && SrcEvaluatorType::CoeffReadCost <
HugeCost
824 && DstXprType::SizeAtCompileTime * (int(DstEvaluatorType::CoeffReadCost) + int(SrcEvaluatorType::CoeffReadCost)) / 2 <=
EIGEN_UNROLLING_LIMIT
827 triangular_assignment_loop<Kernel, Mode, unroll ? int(DstXprType::SizeAtCompileTime) :
Dynamic, SetOpposite>::run(kernel);
830 template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType>
834 call_triangular_assignment_loop<Mode,SetOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>());
838 template<>
struct AssignmentKind<DenseShape,TriangularShape> {
typedef Triangular2Dense Kind; };
839 template<>
struct AssignmentKind<TriangularShape,DenseShape> {
typedef Dense2Triangular Kind; };
842 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
843 struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Triangular>
845 EIGEN_DEVICE_FUNC static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
847 eigen_assert(
int(DstXprType::Mode) ==
int(SrcXprType::Mode));
849 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
853 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
854 struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Dense>
856 EIGEN_DEVICE_FUNC static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
858 call_triangular_assignment_loop<SrcXprType::Mode, (int(SrcXprType::Mode) & int(SelfAdjoint)) == 0>(dst, src, func);
862 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
863 struct Assignment<DstXprType, SrcXprType, Functor, Dense2Triangular>
865 EIGEN_DEVICE_FUNC static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
867 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
872 template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool SetOpposite>
873 struct triangular_assignment_loop
876 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
877 typedef typename DstEvaluatorType::XprType DstXprType;
880 col = (UnrollCount-1) / DstXprType::RowsAtCompileTime,
881 row = (UnrollCount-1) % DstXprType::RowsAtCompileTime
884 typedef typename Kernel::Scalar Scalar;
887 static inline void run(Kernel &kernel)
889 triangular_assignment_loop<Kernel, Mode, UnrollCount-1, SetOpposite>::run(kernel);
892 kernel.assignDiagonalCoeff(
row);
894 kernel.assignCoeff(
row,
col);
896 kernel.assignOppositeCoeff(
row,
col);
901 template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
902 struct triangular_assignment_loop<Kernel, Mode, 0, SetOpposite>
905 static inline void run(Kernel &) {}
914 template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
915 struct triangular_assignment_loop<Kernel, Mode,
Dynamic, SetOpposite>
917 typedef typename Kernel::Scalar Scalar;
919 static inline void run(Kernel &kernel)
921 for(
Index j = 0;
j < kernel.cols(); ++
j)
925 if (((Mode&
Lower) && SetOpposite) || (Mode&
Upper))
928 if(Mode&
Upper) kernel.assignCoeff(
i,
j);
929 else kernel.assignOppositeCoeff(
i,
j);
935 kernel.assignDiagonalCoeff(
i++);
937 if (((Mode&
Upper) && SetOpposite) || (Mode&
Lower))
939 for(;
i < kernel.rows(); ++
i)
940 if(Mode&
Lower) kernel.assignCoeff(
i,
j);
941 else kernel.assignOppositeCoeff(
i,
j);
951 template<
typename Derived>
952 template<
typename DenseDerived>
962 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
963 struct Assignment<DstXprType,
Product<Lhs,Rhs,
DefaultProduct>,
internal::assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
966 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<Scalar,typename SrcXprType::Scalar> &)
969 Index dstCols = src.cols();
970 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
971 dst.resize(dstRows, dstCols);
973 dst._assignProduct(src, Scalar(1),
false);
978 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
979 struct Assignment<DstXprType, Product<Lhs,Rhs,
DefaultProduct>,
internal::add_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
981 typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
982 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::add_assign_op<Scalar,typename SrcXprType::Scalar> &)
984 dst._assignProduct(src, Scalar(1),
true);
989 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
990 struct Assignment<DstXprType, Product<Lhs,Rhs,
DefaultProduct>,
internal::sub_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
992 typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
993 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::sub_assign_op<Scalar,typename SrcXprType::Scalar> &)
995 dst._assignProduct(src, Scalar(-1),
true);
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
#define eigen_internal_assert(x)
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
#define EIGEN_UNUSED_VARIABLE(var)
#define EIGEN_DEVICE_FUNC
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_UNROLLING_LIMIT
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
#define EIGEN_STATIC_ASSERT(X, MSG)
Matrix< float, 1, Dynamic > MatrixType
Base class for all dense matrices, vectors, and arrays.
NumTraits< Scalar >::Real RealScalar
Base class for all dense matrices, vectors, and expressions.
bool isLowerTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
TriangularViewReturnType< Mode >::Type triangularView()
bool isUpperTriangular(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Base::PlainObject PlainObject
Expression of the product of two arbitrary matrices or vectors.
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
Pseudo expression representing a solving operation.
Expression of the transpose of a matrix.
Base class for triangular part in a matrix.
void copyCoeff(Index row, Index col, Other &other)
internal::traits< Derived >::StorageKind StorageKind
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Scalar & coeffRef(Index row, Index col)
EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
void resize(Index rows, Index cols)
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
void evalTo(MatrixBase< DenseDerived > &other) const
internal::traits< Derived >::Scalar Scalar
internal::traits< Derived >::FullMatrixType DenseMatrixType
internal::traits< Derived >::StorageIndex StorageIndex
Scalar operator()(Index row, Index col) const
void evalToLazy(MatrixBase< DenseDerived > &other) const
void check_coordinates_internal(Index, Index) const
void check_coordinates(Index row, Index col) const
DenseMatrixType DenseType
Scalar & operator()(Index row, Index col)
DenseMatrixType toDenseMatrix() const
Scalar coeff(Index row, Index col) const
TriangularBase< TriangularViewType > Base
TriangularViewType & setZero()
Scalar coeff(Index row, Index col) const
MatrixType::PlainObject DenseMatrixType
TriangularViewType & operator/=(const typename internal::traits< MatrixType >::Scalar &other)
internal::traits< TriangularViewType >::Scalar Scalar
DenseMatrixType PlainObject
void fill(const Scalar &value)
TriangularViewType & operator-=(const DenseBase< Other > &other)
TriangularViewType & _assignProduct(const ProductType &prod, const Scalar &alpha, bool beta)
Index outerStride() const
void _solve_impl(const RhsType &rhs, DstType &dst) const
const Product< TriangularViewType, OtherDerived > operator*(const MatrixBase< OtherDerived > &rhs) const
EIGEN_DEPRECATED void swap(MatrixBase< OtherDerived > const &other)
TriangularView< MatrixType_, Mode_ > TriangularViewType
TriangularViewType & operator=(const MatrixBase< OtherDerived > &other)
Index innerStride() const
TriangularViewType & setOnes()
TriangularViewType & operator*=(const typename internal::traits< MatrixType >::Scalar &other)
TriangularViewType & operator=(const TriangularBase< OtherDerived > &other)
TriangularViewType & setConstant(const Scalar &value)
const internal::triangular_solve_retval< Side, TriangularViewType, Other > solve(const MatrixBase< Other > &other) const
friend const Product< OtherDerived, TriangularViewType > operator*(const MatrixBase< OtherDerived > &lhs, const TriangularViewImpl &rhs)
void solveInPlace(const MatrixBase< OtherDerived > &other) const
internal::traits< TriangularViewType >::StorageKind StorageKind
void solveInPlace(const MatrixBase< OtherDerived > &other) const
TriangularViewType & operator+=(const DenseBase< Other > &other)
Scalar & coeffRef(Index row, Index col)
void swap(TriangularBase< OtherDerived > &other)
Expression of a triangular part in a matrix.
const ConjugateReturnType conjugate() const
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
TriangularView< std::add_const_t< MatrixType >, Mode_ > ConstTriangularView
internal::traits< TriangularView >::MatrixTypeNested MatrixTypeNested
Scalar determinant() const
TransposeReturnType transpose(std::enable_if_t< Eigen::internal::is_lvalue< MatrixType >::value, Dummy * >=nullptr)
NestedExpression & nestedExpression()
const SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView() const
internal::traits< TriangularView >::StorageKind StorageKind
MatrixTypeNested m_matrix
internal::traits< TriangularView >::MatrixTypeNestedNonRef MatrixTypeNestedNonRef
const ConstTransposeReturnType transpose() const
TriangularView< const typename MatrixType::AdjointReturnType, TransposeMode > AdjointReturnType
const Solve< TriangularView, Other > solve(const MatrixBase< Other > &other) const
TriangularView(MatrixType &matrix)
std::conditional_t< Cond, ConjugateReturnType, ConstTriangularView > conjugateIf() const
const AdjointReturnType adjoint() const
internal::traits< TriangularView >::MatrixTypeNestedCleaned NestedExpression
TriangularView< const typename MatrixType::ConstTransposeReturnType, TransposeMode > ConstTransposeReturnType
TriangularView< const MatrixConjugateReturnType, Mode > ConjugateReturnType
const NestedExpression & nestedExpression() const
SelfAdjointView< MatrixTypeNestedNonRef, Mode > selfadjointView()
TriangularView< typename MatrixType::TransposeReturnType, TransposeMode > TransposeReturnType
internal::traits< TriangularView >::Scalar Scalar
internal::remove_all_t< typename MatrixType::ConjugateReturnType > MatrixConjugateReturnType
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
TriangularViewImpl< MatrixType_, Mode_, typename internal::traits< MatrixType_ >::StorageKind > Base
const unsigned int PacketAccessBit
const unsigned int LinearAccessBit
const unsigned int DirectAccessBit
const unsigned int LvalueBit
void call_triangular_assignment_loop(DstXprType &dst, const SrcXprType &src, const Functor &func)
constexpr int size_at_compile_time(int rows, int cols)
void call_assignment(Dst &dst, const Src &src)
EIGEN_CONSTEXPR void call_assignment_no_alias(Dst &dst, const Src &src, const Func &func)
typename remove_all< T >::type remove_all_t
bool is_same_dense(const T1 &mat1, const T2 &mat2, std::enable_if_t< possibly_same_dense< T1, T2 >::value > *=0)
void swap(scoped_array< T > &a, scoped_array< T > &b)
EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
const unsigned int HereditaryBits
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Eigen::Index Index
The interface type of indices.
Derived & const_cast_derived() const