16template<
typename _MatrixType>
struct traits<FullPivLU<_MatrixType> >
19 typedef MatrixXpr XprKind;
20 typedef SolverStorage StorageKind;
21 typedef int StorageIndex;
64 typedef _MatrixType MatrixType;
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;
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!");
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;
441template<
typename MatrixType>
443 : m_isInitialized(false), m_usePrescribedThreshold(false)
447template<
typename MatrixType>
452 m_rowsTranspositions(rows),
453 m_colsTranspositions(cols),
454 m_isInitialized(false),
455 m_usePrescribedThreshold(false)
459template<
typename MatrixType>
460template<
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)
473template<
typename MatrixType>
474template<
typename InputType>
476 : m_lu(matrix.derived()),
479 m_rowsTranspositions(matrix.rows()),
480 m_colsTranspositions(matrix.cols()),
481 m_isInitialized(false),
482 m_usePrescribedThreshold(false)
487template<
typename MatrixType>
490 check_template_parameters();
495 m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
497 const Index size = m_lu.diagonalSize();
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);
510 for(
Index k = 0; k < size; ++k)
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;
530 for(
Index i = k; i < size; ++i)
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);
567 m_p.setIdentity(rows);
568 for(Index k = size-1; k >= 0; --k)
569 m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k));
571 m_q.setIdentity(cols);
572 for(Index k = 0; k < size; ++k)
573 m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k));
575 m_det_pq = (number_of_transpositions%2) ? -1 : 1;
577 m_isInitialized =
true;
580template<
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());
591template<
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();
605 res = m_p.inverse() * res;
608 res = res * m_q.inverse();
616template<
typename _MatrixType>
617struct 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();
656 Matrix<Index, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(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)
661 pivots.coeffRef(p++) = i;
662 eigen_internal_assert(p == rank());
668 Matrix<
typename MatrixType::Scalar,
Dynamic,
Dynamic, MatrixType::Options,
669 MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
670 m(dec().matrixLU().block(0, 0, rank(), cols));
671 for(Index i = 0; i < rank(); ++i)
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);
676 m.block(0, 0, rank(), rank());
677 m.block(0, 0, rank(), rank()).template triangularView<StrictlyLower>().setZero();
678 for(Index i = 0; i < rank(); ++i)
679 m.col(i).swap(m.col(pivots.coeff(i)));
684 m.topLeftCorner(rank(), rank())
685 .
template triangularView<Upper>().solveInPlace(
686 m.topRightCorner(rank(), dimker)
690 for(Index i = rank()-1; i >= 0; --i)
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);
695 for(Index i = rank(); i < cols; ++i) dst.row(dec().permutationQ().indices().coeff(i)).setZero();
696 for(Index k = 0; k < dimker; ++k) dst.coeffRef(dec().permutationQ().indices().coeff(rank()+k), k) = Scalar(1);
702template<
typename _MatrixType>
703struct image_retval<FullPivLU<_MatrixType> >
704 : image_retval_base<FullPivLU<_MatrixType> >
706 EIGEN_MAKE_IMAGE_HELPERS(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
725 Matrix<Index, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(rank());
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)
730 pivots.coeffRef(p++) = i;
731 eigen_internal_assert(p == rank());
733 for(Index i = 0; i < rank(); ++i)
734 dst.col(i) = originalMatrix().col(dec().permutationQ().indices().coeff(pivots.coeff(i)));
742#ifndef EIGEN_PARSED_BY_DOXYGEN
743template<
typename _MatrixType>
744template<
typename RhsType,
typename DstType>
745void FullPivLU<_MatrixType>::_solve_impl(
const RhsType &rhs, DstType &dst)
const
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());
769 c = permutationP() * rhs;
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)
785 dst.row(permutationQ().indices().coeff(i)) = c.row(i);
786 for(Index i = nonzero_pivots; i < m_lu.cols(); ++i)
787 dst.row(permutationQ().indices().coeff(i)).setZero();
790template<
typename _MatrixType>
791template<
bool Conjugate,
typename RhsType,
typename DstType>
792void FullPivLU<_MatrixType>::_solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const
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());
818 c = permutationQ().inverse() * rhs;
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));
835 PermutationPType invp = permutationP().inverse().eval();
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();
848template<
typename DstXprType,
typename MatrixType>
849struct Assignment<DstXprType, Inverse<FullPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename FullPivLU<MatrixType>::Scalar>, Dense2Dense>
851 typedef FullPivLU<MatrixType> LuType;
852 typedef Inverse<LuType> SrcXprType;
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()));
868template<
typename Derived>
869inline const FullPivLU<typename MatrixBase<Derived>::PlainObject>
LU decomposition of a matrix with complete pivoting, and related features.
Definition: FullPivLU.h:62
RealScalar rcond() const
Definition: FullPivLU.h:250
MatrixType reconstructedMatrix() const
Definition: FullPivLU.h:592
bool isSurjective() const
Definition: FullPivLU.h:373
FullPivLU & setThreshold(Default_t)
Definition: FullPivLU.h:305
const internal::kernel_retval< FullPivLU > kernel() const
Definition: FullPivLU.h:190
Index dimensionOfKernel() const
Definition: FullPivLU.h:347
Index rank() const
Definition: FullPivLU.h:330
internal::traits< MatrixType >::Scalar determinant() const
Definition: FullPivLU.h:581
const Solve< FullPivLU, Rhs > solve(const MatrixBase< Rhs > &b) const
const PermutationPType & permutationP() const
Definition: FullPivLU.h:160
Index nonzeroPivots() const
Definition: FullPivLU.h:145
bool isInjective() const
Definition: FullPivLU.h:360
FullPivLU & setThreshold(const RealScalar &threshold)
Definition: FullPivLU.h:290
RealScalar maxPivot() const
Definition: FullPivLU.h:154
const Inverse< FullPivLU > inverse() const
Definition: FullPivLU.h:398
const MatrixType & matrixLU() const
Definition: FullPivLU.h:132
RealScalar threshold() const
Definition: FullPivLU.h:315
const PermutationQType & permutationQ() const
Definition: FullPivLU.h:170
FullPivLU & compute(const EigenBase< InputType > &matrix)
Definition: FullPivLU.h:120
const internal::image_retval< FullPivLU > image(const MatrixType &originalMatrix) const
Definition: FullPivLU.h:216
FullPivLU()
Default Constructor.
Definition: FullPivLU.h:442
bool isInvertible() const
Definition: FullPivLU.h:385
Expression of the inverse of another expression.
Definition: Inverse.h:44
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Permutation matrix.
Definition: PermutationMatrix.h:298
Pseudo expression representing a solving operation.
Definition: Solve.h:63
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:69
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:106
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
Definition: Constants.h:22
Definition: EigenBase.h:30
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
Derived & derived()
Definition: EigenBase.h:46
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:233