60 template<
typename _MatrixType>
class FullPivLU
61 :
public SolverBase<FullPivLU<_MatrixType> >
100 template<
typename InputType>
109 template<
typename InputType>
119 template<
typename InputType>
222 #ifdef EIGEN_PARSED_BY_DOXYGEN
242 template<
typename Rhs>
401 eigen_assert(
m_lu.rows() ==
m_lu.cols() &&
"You can't take the inverse of a non-square matrix!");
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>
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>
467 m_isInitialized(false),
468 m_usePrescribedThreshold(false)
473 template<
typename MatrixType>
474 template<
typename InputType>
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();
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;
515 Index row_of_biggest_in_corner, col_of_biggest_in_corner;
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);
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);
569 m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k));
571 m_q.setIdentity(
cols);
573 m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(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.");
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();
616 template<
typename _MatrixType>
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)
669 MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
670 m(dec().matrixLU().
block(0, 0, rank(),
cols));
673 if(
i)
m.row(
i).head(
i).setZero();
676 m.block(0, 0, rank(), rank());
677 m.block(0, 0, rank(), rank()).template triangularView<StrictlyLower>().setZero();
684 m.topLeftCorner(rank(), rank())
685 .
template triangularView<Upper>().solveInPlace(
686 m.topRightCorner(rank(), dimker)
690 for(
Index i = rank()-1;
i >= 0; --
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);
702 template<
typename _MatrixType>
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)
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>
757 nonzero_pivots = this->rank();
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));
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();
790 template<
typename _MatrixType>
791 template<
bool Conjugate,
typename RhsType,
typename DstType>
806 nonzero_pivots = this->rank();
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));
848 template<
typename DstXprType,
typename MatrixType>
868 template<
typename Derived>