333 eigen_assert(m_isInitialized &&
"LU is not initialized.");
336 for(
Index i = 0; i < m_nonzero_pivots; ++i)
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());
507 m_nonzero_pivots = size;
508 m_maxpivot = RealScalar(0);
510 for(
Index k = 0; k < size; ++k)
517 typedef typename Scoring::result_type Score;
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.");
597 MatrixType res(m_lu.rows(),m_lu.cols());
605 res = m_p.inverse() * res;
608 res = res * m_q.inverse();
616template<
typename _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();
659 for(
Index i = 0; i < dec().nonzeroPivots(); ++i)
662 eigen_internal_assert(p == rank());
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());
678 for(
Index i = 0; i < rank(); ++i)
679 m.col(i).swap(m.col(
pivots.coeff(i)));
684 m.topLeftCorner(rank(), rank())
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>
708 enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
709 MatrixType::MaxColsAtCompileTime,
710 MatrixType::MaxRowsAtCompileTime)
713 template<
typename Dest>
void evalTo(
Dest&
dst)
const
728 for(
Index i = 0; i < dec().nonzeroPivots(); ++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>
755 const Index rows = this->rows(),
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>
855 dst =
src.nestedExpression().solve(MatrixType::Identity(
src.rows(),
src.cols()));
868template<
typename Derived>