16 template<
typename _MatrixType>
struct traits<FullPivLU<_MatrixType> >
19 typedef MatrixXpr XprKind;
20 typedef SolverStorage StorageKind;
21 typedef int StorageIndex;
64 typedef _MatrixType MatrixType;
68 EIGEN_GENERIC_PUBLIC_INTERFACE(FullPivLU)
70 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
71 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
73 typedef typename internal::plain_row_type<MatrixType, StorageIndex>::type IntRowVectorType;
74 typedef typename internal::plain_col_type<MatrixType, StorageIndex>::type IntColVectorType;
77 typedef typename MatrixType::PlainObject PlainObject;
100 template<
typename InputType>
109 template<
typename InputType>
119 template<
typename InputType>
134 eigen_assert(m_isInitialized &&
"LU is not initialized.");
147 eigen_assert(m_isInitialized &&
"LU is not initialized.");
148 return m_nonzero_pivots;
162 eigen_assert(m_isInitialized &&
"LU is not initialized.");
172 eigen_assert(m_isInitialized &&
"LU is not initialized.");
190 inline const internal::kernel_retval<FullPivLU>
kernel()
const 192 eigen_assert(m_isInitialized &&
"LU is not initialized.");
193 return internal::kernel_retval<FullPivLU>(*this);
215 inline const internal::image_retval<FullPivLU>
216 image(
const MatrixType& originalMatrix)
const 218 eigen_assert(m_isInitialized &&
"LU is not initialized.");
219 return internal::image_retval<FullPivLU>(*
this, originalMatrix);
222 #ifdef EIGEN_PARSED_BY_DOXYGEN 242 template<
typename Rhs>
252 eigen_assert(m_isInitialized &&
"PartialPivLU is not initialized.");
253 return internal::rcond_estimate_helper(m_l1_norm, *
this);
271 typename internal::traits<MatrixType>::Scalar determinant()
const;
292 m_usePrescribedThreshold =
true;
293 m_prescribedThreshold = threshold;
307 m_usePrescribedThreshold =
false;
317 eigen_assert(m_isInitialized || m_usePrescribedThreshold);
318 return m_usePrescribedThreshold ? m_prescribedThreshold
333 eigen_assert(m_isInitialized &&
"LU is not initialized.");
334 RealScalar premultiplied_threshold =
abs(m_maxpivot) * threshold();
336 for(
Index i = 0; i < m_nonzero_pivots; ++i)
337 result += (
abs(m_lu.coeff(i,i)) > premultiplied_threshold);
349 eigen_assert(m_isInitialized &&
"LU is not initialized.");
350 return cols() - rank();
362 eigen_assert(m_isInitialized &&
"LU is not initialized.");
363 return rank() == cols();
375 eigen_assert(m_isInitialized &&
"LU is not initialized.");
376 return rank() == rows();
387 eigen_assert(m_isInitialized &&
"LU is not initialized.");
388 return isInjective() && (m_lu.rows() == m_lu.cols());
400 eigen_assert(m_isInitialized &&
"LU is not initialized.");
401 eigen_assert(m_lu.rows() == m_lu.cols() &&
"You can't take the inverse of a non-square matrix!");
405 MatrixType reconstructedMatrix()
const;
407 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
408 inline Index rows()
const EIGEN_NOEXCEPT {
return m_lu.rows(); }
409 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
410 inline Index cols()
const EIGEN_NOEXCEPT {
return m_lu.cols(); }
412 #ifndef EIGEN_PARSED_BY_DOXYGEN 413 template<
typename RhsType,
typename DstType>
414 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
416 template<
bool Conjugate,
typename RhsType,
typename DstType>
417 void _solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const;
422 static void check_template_parameters()
424 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
427 void computeInPlace();
430 PermutationPType m_p;
431 PermutationQType m_q;
432 IntColVectorType m_rowsTranspositions;
433 IntRowVectorType m_colsTranspositions;
434 Index m_nonzero_pivots;
435 RealScalar m_l1_norm;
436 RealScalar m_maxpivot, m_prescribedThreshold;
437 signed char m_det_pq;
438 bool m_isInitialized, m_usePrescribedThreshold;
441 template<
typename MatrixType>
443 : m_isInitialized(false), m_usePrescribedThreshold(false)
447 template<
typename MatrixType>
452 m_rowsTranspositions(rows),
453 m_colsTranspositions(cols),
454 m_isInitialized(false),
455 m_usePrescribedThreshold(false)
459 template<
typename MatrixType>
460 template<
typename InputType>
462 : m_lu(matrix.rows(), matrix.cols()),
465 m_rowsTranspositions(matrix.rows()),
466 m_colsTranspositions(matrix.cols()),
467 m_isInitialized(false),
468 m_usePrescribedThreshold(false)
473 template<
typename MatrixType>
474 template<
typename InputType>
479 m_rowsTranspositions(matrix.rows()),
480 m_colsTranspositions(matrix.cols()),
481 m_isInitialized(false),
482 m_usePrescribedThreshold(false)
487 template<
typename MatrixType>
490 check_template_parameters();
495 m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
498 const Index rows = m_lu.rows();
499 const Index cols = m_lu.cols();
503 m_rowsTranspositions.resize(m_lu.rows());
504 m_colsTranspositions.resize(m_lu.cols());
505 Index number_of_transpositions = 0;
507 m_nonzero_pivots =
size;
508 m_maxpivot = RealScalar(0);
515 Index row_of_biggest_in_corner, col_of_biggest_in_corner;
516 typedef internal::scalar_score_coeff_op<Scalar> Scoring;
517 typedef typename Scoring::result_type Score;
518 Score biggest_in_corner;
519 biggest_in_corner = m_lu.bottomRightCorner(rows-k, cols-k)
520 .unaryExpr(Scoring())
521 .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
522 row_of_biggest_in_corner += k;
523 col_of_biggest_in_corner += k;
525 if(biggest_in_corner==Score(0))
529 m_nonzero_pivots = k;
532 m_rowsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
533 m_colsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
538 RealScalar abs_pivot = internal::abs_knowing_score<Scalar>()(m_lu(row_of_biggest_in_corner, col_of_biggest_in_corner), biggest_in_corner);
539 if(abs_pivot > m_maxpivot) m_maxpivot = abs_pivot;
544 m_rowsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner);
545 m_colsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner);
546 if(k != row_of_biggest_in_corner) {
547 m_lu.row(k).swap(m_lu.row(row_of_biggest_in_corner));
548 ++number_of_transpositions;
550 if(k != col_of_biggest_in_corner) {
551 m_lu.col(k).swap(m_lu.col(col_of_biggest_in_corner));
552 ++number_of_transpositions;
559 m_lu.col(k).tail(rows-k-1) /= m_lu.coeff(k,k);
561 m_lu.block(k+1,k+1,rows-k-1,cols-k-1).noalias() -= m_lu.col(k).tail(rows-k-1) * m_lu.row(k).tail(cols-k-1);
568 for(
Index k = size-1; k >= 0; --k)
575 m_det_pq = (number_of_transpositions%2) ? -1 : 1;
577 m_isInitialized =
true;
580 template<
typename MatrixType>
583 eigen_assert(m_isInitialized &&
"LU is not initialized.");
584 eigen_assert(m_lu.rows() == m_lu.cols() &&
"You can't take the determinant of a non-square matrix!");
585 return Scalar(m_det_pq) * Scalar(m_lu.diagonal().prod());
591 template<
typename MatrixType>
594 eigen_assert(m_isInitialized &&
"LU is not initialized.");
595 const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols());
597 MatrixType res(m_lu.rows(),m_lu.cols());
599 res = m_lu.leftCols(smalldim)
600 .template triangularView<UnitLower>().toDenseMatrix()
601 * m_lu.topRows(smalldim)
602 .template triangularView<Upper>().toDenseMatrix();
616 template<
typename _MatrixType>
617 struct kernel_retval<FullPivLU<_MatrixType> >
618 : kernel_retval_base<FullPivLU<_MatrixType> >
622 enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
623 MatrixType::MaxColsAtCompileTime,
624 MatrixType::MaxRowsAtCompileTime)
627 template<
typename Dest>
void evalTo(Dest& dst)
const 630 const Index cols = dec().matrixLU().cols(), dimker = cols -
rank();
657 RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
659 for(
Index i = 0; i < dec().nonzeroPivots(); ++i)
660 if(
abs(dec().
matrixLU().coeff(i,i)) > premultiplied_threshold)
662 eigen_internal_assert(p ==
rank());
669 MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
673 if(i) m.row(i).head(i).setZero();
674 m.row(i).tail(cols-i) = dec().matrixLU().row(pivots.
coeff(i)).tail(cols-i);
677 m.block(0, 0,
rank(),
rank()).template triangularView<StrictlyLower>().setZero();
679 m.col(i).swap(m.col(pivots.
coeff(i)));
685 .template triangularView<Upper>().solveInPlace(
686 m.topRightCorner(rank(), dimker)
691 m.col(i).swap(m.col(pivots.
coeff(i)));
694 for(
Index i = 0; i <
rank(); ++i) dst.row(dec().
permutationQ().indices().coeff(i)) = -m.row(i).tail(dimker);
696 for(
Index k = 0; k < dimker; ++k) dst.coeffRef(dec().
permutationQ().indices().coeff(
rank()+k), k) = Scalar(1);
702 template<
typename _MatrixType>
703 struct image_retval<FullPivLU<_MatrixType> >
704 : image_retval_base<FullPivLU<_MatrixType> >
708 enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
709 MatrixType::MaxColsAtCompileTime,
710 MatrixType::MaxRowsAtCompileTime)
713 template<
typename Dest>
void evalTo(Dest& dst)
const 726 RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
728 for(
Index i = 0; i < dec().nonzeroPivots(); ++i)
729 if(
abs(dec().
matrixLU().coeff(i,i)) > premultiplied_threshold)
731 eigen_internal_assert(p ==
rank());
734 dst.col(i) = originalMatrix().col(dec().
permutationQ().indices().coeff(pivots.
coeff(i)));
742 #ifndef EIGEN_PARSED_BY_DOXYGEN 743 template<
typename _MatrixType>
744 template<
typename RhsType,
typename DstType>
755 const Index rows = this->rows(),
757 nonzero_pivots = this->
rank();
758 const Index smalldim = (std::min)(rows, cols);
760 if(nonzero_pivots == 0)
766 typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
772 m_lu.topLeftCorner(smalldim,smalldim)
773 .template triangularView<UnitLower>()
774 .solveInPlace(c.topRows(smalldim));
776 c.bottomRows(rows-cols) -= m_lu.bottomRows(rows-cols) * c.topRows(cols);
779 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
780 .template triangularView<Upper>()
781 .solveInPlace(c.topRows(nonzero_pivots));
784 for(
Index i = 0; i < nonzero_pivots; ++i)
786 for(
Index i = nonzero_pivots; i < m_lu.cols(); ++i)
790 template<
typename _MatrixType>
791 template<
bool Conjugate,
typename RhsType,
typename DstType>
805 const Index rows = this->rows(), cols = this->cols(),
806 nonzero_pivots = this->
rank();
807 const Index smalldim = (std::min)(rows, cols);
809 if(nonzero_pivots == 0)
815 typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
821 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
822 .template triangularView<Upper>()
824 .template conjugateIf<Conjugate>()
825 .solveInPlace(c.topRows(nonzero_pivots));
828 m_lu.topLeftCorner(smalldim, smalldim)
829 .template triangularView<UnitLower>()
831 .template conjugateIf<Conjugate>()
832 .solveInPlace(c.topRows(smalldim));
836 for(
Index i = 0; i < smalldim; ++i)
837 dst.row(invp.indices().coeff(i)) = c.row(i);
838 for(
Index i = smalldim; i < rows; ++i)
839 dst.row(invp.indices().coeff(i)).setZero();
848 template<
typename DstXprType,
typename MatrixType>
849 struct Assignment<DstXprType, Inverse<FullPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename FullPivLU<MatrixType>::Scalar>, Dense2Dense>
853 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename MatrixType::Scalar> &)
855 dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
868 template<
typename Derived>
const internal::image_retval< FullPivLU > image(const MatrixType &originalMatrix) const
Definition: FullPivLU.h:216
FullPivLU & setThreshold(const RealScalar &threshold)
Definition: FullPivLU.h:290
InverseReturnType inverse() const
Definition: PermutationMatrix.h:185
FullPivLU & compute(const EigenBase< InputType > &matrix)
Definition: FullPivLU.h:120
const PermutationQType & permutationQ() const
Definition: FullPivLU.h:170
Derived & applyTranspositionOnTheRight(Index i, Index j)
Definition: PermutationMatrix.h:174
RealScalar rcond() const
Definition: FullPivLU.h:250
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Derived & derived()
Definition: EigenBase.h:46
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: EigenBase.h:67
const FullPivLU< PlainObject > fullPivLu() const
Definition: FullPivLU.h:870
Index nonzeroPivots() const
Definition: FullPivLU.h:145
Definition: EigenBase.h:29
Index rank() const
Definition: FullPivLU.h:330
Expression of the inverse of another expression.
Definition: Inverse.h:43
Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:175
RealScalar threshold() const
Definition: FullPivLU.h:315
internal::traits< MatrixType >::Scalar determinant() const
Definition: FullPivLU.h:581
const MatrixType & matrixLU() const
Definition: FullPivLU.h:132
ConstTransposeReturnType transpose() const
Definition: SolverBase.h:121
FullPivLU & setThreshold(Default_t)
Definition: FullPivLU.h:305
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const Inverse< FullPivLU > inverse() const
Definition: FullPivLU.h:398
bool isInjective() const
Definition: FullPivLU.h:360
bool isSurjective() const
Definition: FullPivLU.h:373
void setIdentity()
Definition: PermutationMatrix.h:131
MatrixType reconstructedMatrix() const
Definition: FullPivLU.h:592
bool isInvertible() const
Definition: FullPivLU.h:385
const PermutationPType & permutationP() const
Definition: FullPivLU.h:160
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
Definition: Eigen_Colamd.h:50
const internal::kernel_retval< FullPivLU > kernel() const
Definition: FullPivLU.h:190
const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:152
LU decomposition of a matrix with complete pivoting, and related features.
Definition: FullPivLU.h:60
FullPivLU()
Default Constructor.
Definition: FullPivLU.h:442
const int Dynamic
Definition: Constants.h:22
Pseudo expression representing a solving operation.
Definition: Solve.h:62
Index dimensionOfKernel() const
Definition: FullPivLU.h:347
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:68
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
RealScalar maxPivot() const
Definition: FullPivLU.h:154