281 template<
typename Other>
289 template<
int S
ide,
typename Other>
291 inline const internal::triangular_solve_retval<Side,TriangularView, Other>
292 solve(
const MatrixBase<Other>& other)
const
293 {
return Base::template solve<Side>(other); }
328 return m_matrix.diagonal().prod();
333 MatrixTypeNested m_matrix;
345template<
typename _MatrixType,
unsigned int _Mode>
class TriangularViewImpl<_MatrixType,_Mode,
Dense>
352 typedef typename internal::traits<TriangularViewType>::Scalar Scalar;
354 typedef _MatrixType MatrixType;
355 typedef typename MatrixType::PlainObject DenseMatrixType;
356 typedef DenseMatrixType PlainObject;
359 using Base::evalToLazy;
362 typedef typename internal::traits<TriangularViewType>::StorageKind StorageKind;
366 Flags = internal::traits<TriangularViewType>::Flags
379 template<
typename Other>
382 internal::call_assignment_no_alias(derived(), other.
derived(), internal::add_assign_op<Scalar,typename Other::Scalar>());
386 template<
typename Other>
389 internal::call_assignment_no_alias(derived(), other.
derived(), internal::sub_assign_op<Scalar,typename Other::Scalar>());
402 void fill(
const Scalar& value) { setConstant(value); }
406 {
return *
this = MatrixType::Constant(derived().rows(), derived().cols(), value); }
420 Base::check_coordinates_internal(row, col);
421 return derived().nestedExpression().coeff(row, col);
431 Base::check_coordinates_internal(row, col);
432 return derived().nestedExpression().coeffRef(row, col);
436 template<
typename OtherDerived>
441 template<
typename OtherDerived>
445#ifndef EIGEN_PARSED_BY_DOXYGEN
448 {
return *
this = other.derived().nestedExpression(); }
450 template<
typename OtherDerived>
452 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
455 template<
typename OtherDerived>
457 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
462 template<
typename OtherDerived>
471 template<
typename OtherDerived>
friend
502 template<
int S
ide,
typename Other>
503 inline const internal::triangular_solve_retval<Side,TriangularViewType, Other>
515 template<
int S
ide,
typename OtherDerived>
519 template<
typename OtherDerived>
522 {
return solveInPlace<OnTheLeft>(other); }
525 template<
typename OtherDerived>
527#ifdef EIGEN_PARSED_BY_DOXYGEN
533 EIGEN_STATIC_ASSERT_LVALUE(OtherDerived);
534 call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
538 template<
typename OtherDerived>
540 EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
543 EIGEN_STATIC_ASSERT_LVALUE(OtherDerived);
544 call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
547 template<
typename RhsType,
typename DstType>
549 EIGEN_STRONG_INLINE
void _solve_impl(
const RhsType &rhs, DstType &dst)
const {
550 if(!internal::is_same_dense(dst,rhs))
552 this->solveInPlace(dst);
555 template<
typename ProductType>
557 EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(
const ProductType& prod,
const Scalar& alpha,
bool beta);
559 EIGEN_DEFAULT_COPY_CONSTRUCTOR(TriangularViewImpl)
560 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TriangularViewImpl)
568#ifndef EIGEN_PARSED_BY_DOXYGEN
570template<
typename MatrixType,
unsigned int Mode>
571template<
typename OtherDerived>
572EIGEN_DEVICE_FUNC
inline TriangularView<MatrixType, Mode>&
573TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const MatrixBase<OtherDerived>& other)
575 internal::call_assignment_no_alias(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
580template<
typename MatrixType,
unsigned int Mode>
581template<
typename OtherDerived>
582EIGEN_DEVICE_FUNC
void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const MatrixBase<OtherDerived>& other)
584 internal::call_assignment_no_alias(derived(), other.template triangularView<Mode>());
589template<
typename MatrixType,
unsigned int Mode>
590template<
typename OtherDerived>
591EIGEN_DEVICE_FUNC
inline TriangularView<MatrixType, Mode>&
592TriangularViewImpl<MatrixType, Mode, Dense>::operator=(
const TriangularBase<OtherDerived>& other)
594 eigen_assert(Mode ==
int(OtherDerived::Mode));
595 internal::call_assignment(derived(), other.derived());
599template<
typename MatrixType,
unsigned int Mode>
600template<
typename OtherDerived>
601EIGEN_DEVICE_FUNC
void TriangularViewImpl<MatrixType, Mode, Dense>::lazyAssign(
const TriangularBase<OtherDerived>& other)
603 eigen_assert(Mode ==
int(OtherDerived::Mode));
604 internal::call_assignment_no_alias(derived(), other.derived());
614template<
typename Derived>
615template<
typename DenseDerived>
640template<
typename Derived>
641template<
unsigned int Mode>
650template<
typename Derived>
651template<
unsigned int Mode>
664template<
typename Derived>
667 RealScalar maxAbsOnUpperPart =
static_cast<RealScalar
>(-1);
668 for(
Index j = 0; j < cols(); ++j)
670 Index maxi = numext::mini(j, rows()-1);
671 for(
Index i = 0; i <= maxi; ++i)
673 RealScalar absValue = numext::abs(coeff(i,j));
674 if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue;
677 RealScalar threshold = maxAbsOnUpperPart * prec;
678 for(
Index j = 0; j < cols(); ++j)
679 for(
Index i = j+1; i < rows(); ++i)
680 if(numext::abs(coeff(i, j)) > threshold)
return false;
689template<
typename Derived>
692 RealScalar maxAbsOnLowerPart =
static_cast<RealScalar
>(-1);
693 for(
Index j = 0; j < cols(); ++j)
694 for(
Index i = j; i < rows(); ++i)
696 RealScalar absValue = numext::abs(coeff(i,j));
697 if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue;
699 RealScalar threshold = maxAbsOnLowerPart * prec;
700 for(
Index j = 1; j < cols(); ++j)
702 Index maxi = numext::mini(j, rows()-1);
703 for(
Index i = 0; i < maxi; ++i)
704 if(numext::abs(coeff(i, j)) > threshold)
return false;
722template<
typename MatrixType,
unsigned int Mode>
725 typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind;
726 typedef typename glue_shapes<typename evaluator_traits<MatrixType>::Shape, TriangularShape>::type Shape;
729template<
typename MatrixType,
unsigned int Mode>
730struct unary_evaluator<TriangularView<MatrixType,Mode>, IndexBased>
731 : evaluator<typename internal::remove_all<MatrixType>::type>
733 typedef TriangularView<MatrixType,Mode> XprType;
734 typedef evaluator<typename internal::remove_all<MatrixType>::type> Base;
736 unary_evaluator(
const XprType &xpr) : Base(xpr.nestedExpression()) {}
740struct Triangular2Triangular {};
741struct Triangular2Dense {};
742struct Dense2Triangular {};
745template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool ClearOpposite>
struct triangular_assignment_loop;
753template<
int UpLo,
int Mode,
int SetOpposite,
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
754class triangular_dense_assignment_kernel :
public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>
757 typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version> Base;
758 typedef typename Base::DstXprType DstXprType;
759 typedef typename Base::SrcXprType SrcXprType;
762 using Base::m_functor;
765 typedef typename Base::DstEvaluatorType DstEvaluatorType;
766 typedef typename Base::SrcEvaluatorType SrcEvaluatorType;
767 typedef typename Base::Scalar Scalar;
768 typedef typename Base::AssignmentTraits AssignmentTraits;
771 EIGEN_DEVICE_FUNC triangular_dense_assignment_kernel(DstEvaluatorType &dst,
const SrcEvaluatorType &src,
const Functor &func, DstXprType& dstExpr)
772 : Base(dst, src, func, dstExpr)
775#ifdef EIGEN_INTERNAL_DEBUGGING
776 EIGEN_DEVICE_FUNC
void assignCoeff(Index row, Index col)
778 eigen_internal_assert(row!=col);
779 Base::assignCoeff(row,col);
782 using Base::assignCoeff;
785 EIGEN_DEVICE_FUNC
void assignDiagonalCoeff(Index
id)
787 if(Mode==
UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(1));
788 else if(Mode==
ZeroDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(
id,
id), Scalar(0));
789 else if(Mode==0) Base::assignCoeff(
id,
id);
792 EIGEN_DEVICE_FUNC
void assignOppositeCoeff(Index row, Index col)
794 eigen_internal_assert(row!=col);
796 m_functor.assignCoeff(m_dst.coeffRef(row,col), Scalar(0));
800template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType,
typename Functor>
801EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
802void call_triangular_assignment_loop(DstXprType& dst,
const SrcXprType& src,
const Functor &func)
804 typedef evaluator<DstXprType> DstEvaluatorType;
805 typedef evaluator<SrcXprType> SrcEvaluatorType;
807 SrcEvaluatorType srcEvaluator(src);
809 Index dstRows = src.rows();
810 Index dstCols = src.cols();
811 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
812 dst.resize(dstRows, dstCols);
813 DstEvaluatorType dstEvaluator(dst);
816 DstEvaluatorType,SrcEvaluatorType,Functor> Kernel;
817 Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
820 unroll = DstXprType::SizeAtCompileTime !=
Dynamic
821 && SrcEvaluatorType::CoeffReadCost <
HugeCost
822 && DstXprType::SizeAtCompileTime * (int(DstEvaluatorType::CoeffReadCost) + int(SrcEvaluatorType::CoeffReadCost)) / 2 <= EIGEN_UNROLLING_LIMIT
825 triangular_assignment_loop<Kernel, Mode, unroll ? int(DstXprType::SizeAtCompileTime) :
Dynamic, SetOpposite>::run(kernel);
828template<
int Mode,
bool SetOpposite,
typename DstXprType,
typename SrcXprType>
829EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
830void call_triangular_assignment_loop(DstXprType& dst,
const SrcXprType& src)
832 call_triangular_assignment_loop<Mode,SetOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>());
835template<>
struct AssignmentKind<TriangularShape,TriangularShape> {
typedef Triangular2Triangular Kind; };
836template<>
struct AssignmentKind<DenseShape,TriangularShape> {
typedef Triangular2Dense Kind; };
837template<>
struct AssignmentKind<TriangularShape,DenseShape> {
typedef Dense2Triangular Kind; };
840template<
typename DstXprType,
typename SrcXprType,
typename Functor>
841struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Triangular>
843 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
845 eigen_assert(
int(DstXprType::Mode) ==
int(SrcXprType::Mode));
847 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
851template<
typename DstXprType,
typename SrcXprType,
typename Functor>
852struct Assignment<DstXprType, SrcXprType, Functor, Triangular2Dense>
854 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
856 call_triangular_assignment_loop<SrcXprType::Mode, (int(SrcXprType::Mode) & int(SelfAdjoint)) == 0>(dst, src, func);
860template<
typename DstXprType,
typename SrcXprType,
typename Functor>
861struct Assignment<DstXprType, SrcXprType, Functor, Dense2Triangular>
863 EIGEN_DEVICE_FUNC
static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &func)
865 call_triangular_assignment_loop<DstXprType::Mode, false>(dst, src, func);
870template<
typename Kernel,
unsigned int Mode,
int UnrollCount,
bool SetOpposite>
871struct triangular_assignment_loop
874 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
875 typedef typename DstEvaluatorType::XprType DstXprType;
878 col = (UnrollCount-1) / DstXprType::RowsAtCompileTime,
879 row = (UnrollCount-1) % DstXprType::RowsAtCompileTime
882 typedef typename Kernel::Scalar Scalar;
885 static inline void run(Kernel &kernel)
887 triangular_assignment_loop<Kernel, Mode, UnrollCount-1, SetOpposite>::run(kernel);
890 kernel.assignDiagonalCoeff(row);
891 else if( ((Mode&
Lower) && row>col) || ((Mode&
Upper) && row<col) )
892 kernel.assignCoeff(row,col);
894 kernel.assignOppositeCoeff(row,col);
899template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
900struct triangular_assignment_loop<Kernel, Mode, 0, SetOpposite>
903 static inline void run(Kernel &) {}
912template<
typename Kernel,
unsigned int Mode,
bool SetOpposite>
913struct triangular_assignment_loop<Kernel, Mode,
Dynamic, SetOpposite>
915 typedef typename Kernel::Scalar Scalar;
917 static inline void run(Kernel &kernel)
919 for(Index j = 0; j < kernel.cols(); ++j)
921 Index maxi = numext::mini(j, kernel.rows());
923 if (((Mode&
Lower) && SetOpposite) || (Mode&
Upper))
926 if(Mode&
Upper) kernel.assignCoeff(i, j);
927 else kernel.assignOppositeCoeff(i, j);
933 kernel.assignDiagonalCoeff(i++);
935 if (((Mode&
Upper) && SetOpposite) || (Mode&
Lower))
937 for(; i < kernel.rows(); ++i)
938 if(Mode&
Lower) kernel.assignCoeff(i, j);
939 else kernel.assignOppositeCoeff(i, j);
949template<
typename Derived>
950template<
typename DenseDerived>
953 other.
derived().resize(this->rows(), this->cols());
954 internal::call_triangular_assignment_loop<Derived::Mode, (int(Derived::Mode) & int(
SelfAdjoint)) == 0 >(other.
derived(), derived().nestedExpression());
960template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
961struct Assignment<DstXprType,
Product<Lhs,Rhs,DefaultProduct>, internal::assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
964 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<Scalar,typename SrcXprType::Scalar> &)
966 Index dstRows = src.rows();
967 Index dstCols = src.cols();
968 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
969 dst.resize(dstRows, dstCols);
971 dst._assignProduct(src, Scalar(1),
false);
976template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
977struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::add_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
979 typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
980 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::add_assign_op<Scalar,typename SrcXprType::Scalar> &)
982 dst._assignProduct(src, Scalar(1),
true);
987template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename Scalar>
988struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::sub_assign_op<Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, Dense2Triangular>
990 typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType;
991 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::sub_assign_op<Scalar,typename SrcXprType::Scalar> &)
993 dst._assignProduct(src, Scalar(-1),
true);