46 template<
typename _MatrixType>
class FullPivLU
49 typedef _MatrixType MatrixType;
51 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
52 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
54 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
55 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
58 typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
59 typedef typename internal::traits<MatrixType>::StorageKind StorageKind;
60 typedef typename MatrixType::Index Index;
61 typedef typename internal::plain_row_type<MatrixType, Index>::type IntRowVectorType;
62 typedef typename internal::plain_col_type<MatrixType, Index>::type IntColVectorType;
63 typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime> PermutationQType;
64 typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationPType;
106 eigen_assert(m_isInitialized &&
"LU is not initialized.");
119 eigen_assert(m_isInitialized &&
"LU is not initialized.");
120 return m_nonzero_pivots;
134 eigen_assert(m_isInitialized &&
"LU is not initialized.");
144 eigen_assert(m_isInitialized &&
"LU is not initialized.");
164 eigen_assert(m_isInitialized &&
"LU is not initialized.");
188 image(
const MatrixType& originalMatrix)
const 190 eigen_assert(m_isInitialized &&
"LU is not initialized.");
213 template<
typename Rhs>
217 eigen_assert(m_isInitialized &&
"LU is not initialized.");
257 m_usePrescribedThreshold =
true;
272 m_usePrescribedThreshold =
false;
282 eigen_assert(m_isInitialized || m_usePrescribedThreshold);
283 return m_usePrescribedThreshold ? m_prescribedThreshold
298 eigen_assert(m_isInitialized &&
"LU is not initialized.");
299 RealScalar premultiplied_threshold = abs(m_maxpivot) *
threshold();
301 for(Index i = 0; i < m_nonzero_pivots; ++i)
302 result += (abs(m_lu.coeff(i,i)) > premultiplied_threshold);
314 eigen_assert(m_isInitialized &&
"LU is not initialized.");
315 return cols() -
rank();
327 eigen_assert(m_isInitialized &&
"LU is not initialized.");
328 return rank() == cols();
340 eigen_assert(m_isInitialized &&
"LU is not initialized.");
341 return rank() == rows();
352 eigen_assert(m_isInitialized &&
"LU is not initialized.");
353 return isInjective() && (m_lu.rows() == m_lu.cols());
365 eigen_assert(m_isInitialized &&
"LU is not initialized.");
366 eigen_assert(m_lu.rows() == m_lu.cols() &&
"You can't take the inverse of a non-square matrix!");
368 (*
this, MatrixType::Identity(m_lu.rows(), m_lu.cols()));
373 inline Index rows()
const {
return m_lu.rows(); }
374 inline Index cols()
const {
return m_lu.cols(); }
378 static void check_template_parameters()
380 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
384 PermutationPType m_p;
385 PermutationQType m_q;
386 IntColVectorType m_rowsTranspositions;
387 IntRowVectorType m_colsTranspositions;
388 Index m_det_pq, m_nonzero_pivots;
389 RealScalar m_maxpivot, m_prescribedThreshold;
390 bool m_isInitialized, m_usePrescribedThreshold;
393 template<
typename MatrixType>
395 : m_isInitialized(false), m_usePrescribedThreshold(false)
399 template<
typename MatrixType>
404 m_rowsTranspositions(rows),
405 m_colsTranspositions(cols),
406 m_isInitialized(false),
407 m_usePrescribedThreshold(false)
411 template<
typename MatrixType>
413 : m_lu(matrix.rows(), matrix.cols()),
416 m_rowsTranspositions(matrix.rows()),
417 m_colsTranspositions(matrix.cols()),
418 m_isInitialized(false),
419 m_usePrescribedThreshold(false)
424 template<
typename MatrixType>
427 check_template_parameters();
432 m_isInitialized =
true;
435 const Index
size = matrix.diagonalSize();
436 const Index rows = matrix.rows();
437 const Index cols = matrix.cols();
441 m_rowsTranspositions.resize(matrix.rows());
442 m_colsTranspositions.resize(matrix.cols());
443 Index number_of_transpositions = 0;
445 m_nonzero_pivots =
size;
446 m_maxpivot = RealScalar(0);
448 for(Index k = 0; k <
size; ++k)
453 Index row_of_biggest_in_corner, col_of_biggest_in_corner;
454 RealScalar biggest_in_corner;
455 biggest_in_corner = m_lu.bottomRightCorner(rows-k, cols-k)
457 .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
458 row_of_biggest_in_corner += k;
459 col_of_biggest_in_corner += k;
461 if(biggest_in_corner==RealScalar(0))
465 m_nonzero_pivots = k;
466 for(Index i = k; i <
size; ++i)
468 m_rowsTranspositions.coeffRef(i) = i;
469 m_colsTranspositions.coeffRef(i) = i;
474 if(biggest_in_corner > m_maxpivot) m_maxpivot = biggest_in_corner;
479 m_rowsTranspositions.coeffRef(k) = row_of_biggest_in_corner;
480 m_colsTranspositions.coeffRef(k) = col_of_biggest_in_corner;
481 if(k != row_of_biggest_in_corner) {
482 m_lu.row(k).swap(m_lu.row(row_of_biggest_in_corner));
483 ++number_of_transpositions;
485 if(k != col_of_biggest_in_corner) {
486 m_lu.col(k).swap(m_lu.col(col_of_biggest_in_corner));
487 ++number_of_transpositions;
494 m_lu.col(k).tail(rows-k-1) /= m_lu.coeff(k,k);
496 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);
502 m_p.setIdentity(rows);
503 for(Index k = size-1; k >= 0; --k)
504 m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k));
506 m_q.setIdentity(cols);
507 for(Index k = 0; k <
size; ++k)
508 m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k));
510 m_det_pq = (number_of_transpositions%2) ? -1 : 1;
514 template<
typename MatrixType>
517 eigen_assert(m_isInitialized &&
"LU is not initialized.");
518 eigen_assert(m_lu.rows() == m_lu.cols() &&
"You can't take the determinant of a non-square matrix!");
519 return Scalar(m_det_pq) *
Scalar(m_lu.diagonal().prod());
525 template<
typename MatrixType>
528 eigen_assert(m_isInitialized &&
"LU is not initialized.");
529 const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols());
531 MatrixType res(m_lu.rows(),m_lu.cols());
533 res = m_lu.leftCols(smalldim)
534 .template triangularView<UnitLower>().toDenseMatrix()
535 * m_lu.topRows(smalldim)
536 .template triangularView<Upper>().toDenseMatrix();
539 res = m_p.inverse() * res;
542 res = res * m_q.inverse();
550 template<
typename _MatrixType>
556 enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
557 MatrixType::MaxColsAtCompileTime,
558 MatrixType::MaxRowsAtCompileTime)
561 template<
typename Dest>
void evalTo(Dest& dst)
const 564 const Index cols = dec().matrixLU().cols(), dimker = cols - rank();
591 RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
593 for(Index i = 0; i < dec().nonzeroPivots(); ++i)
594 if(abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold)
595 pivots.coeffRef(p++) = i;
596 eigen_internal_assert(p == rank());
603 MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
604 m(dec().matrixLU().block(0, 0, rank(), cols));
605 for(Index i = 0; i < rank(); ++i)
607 if(i) m.row(i).head(i).setZero();
608 m.row(i).tail(cols-i) = dec().matrixLU().row(pivots.coeff(i)).
tail(cols-i);
610 m.block(0, 0, rank(), rank());
611 m.block(0, 0, rank(), rank()).template triangularView<StrictlyLower>().setZero();
612 for(Index i = 0; i < rank(); ++i)
613 m.col(i).swap(m.col(pivots.coeff(i)));
618 m.topLeftCorner(rank(), rank())
619 .template triangularView<Upper>().solveInPlace(
620 m.topRightCorner(rank(), dimker)
624 for(Index i = rank()-1; i >= 0; --i)
625 m.col(i).swap(m.col(pivots.coeff(i)));
628 for(Index i = 0; i < rank(); ++i) dst.row(dec().permutationQ().indices().coeff(i)) = -m.row(i).tail(dimker);
629 for(Index i = rank(); i < cols; ++i) dst.row(dec().permutationQ().indices().coeff(i)).setZero();
630 for(Index k = 0; k < dimker; ++k) dst.coeffRef(dec().permutationQ().indices().coeff(rank()+k), k) =
Scalar(1);
636 template<
typename _MatrixType>
642 enum { MaxSmallDimAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(
643 MatrixType::MaxColsAtCompileTime,
644 MatrixType::MaxRowsAtCompileTime)
647 template<
typename Dest>
void evalTo(Dest& dst)
const 660 RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
662 for(Index i = 0; i < dec().nonzeroPivots(); ++i)
663 if(abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold)
664 pivots.coeffRef(p++) = i;
665 eigen_internal_assert(p == rank());
667 for(Index i = 0; i < rank(); ++i)
668 dst.col(i) = originalMatrix().col(dec().permutationQ().indices().coeff(pivots.coeff(i)));
674 template<
typename _MatrixType,
typename Rhs>
680 template<
typename Dest>
void evalTo(Dest& dst)
const 690 const Index rows = dec().rows(), cols = dec().cols(),
691 nonzero_pivots = dec().rank();
692 eigen_assert(rhs().rows() == rows);
693 const Index smalldim = (std::min)(rows, cols);
695 if(nonzero_pivots == 0)
701 typename Rhs::PlainObject c(rhs().rows(), rhs().cols());
704 c = dec().permutationP() * rhs();
708 .topLeftCorner(smalldim,smalldim)
709 .template triangularView<UnitLower>()
710 .solveInPlace(c.topRows(smalldim));
713 c.bottomRows(rows-cols)
714 -= dec().matrixLU().bottomRows(rows-cols)
720 .topLeftCorner(nonzero_pivots, nonzero_pivots)
721 .template triangularView<Upper>()
722 .solveInPlace(c.topRows(nonzero_pivots));
725 for(Index i = 0; i < nonzero_pivots; ++i)
726 dst.row(dec().permutationQ().indices().coeff(i)) = c.row(i);
727 for(Index i = nonzero_pivots; i < dec().matrixLU().cols(); ++i)
728 dst.row(dec().permutationQ().indices().coeff(i)).setZero();
742 template<
typename Derived>
const internal::image_retval< FullPivLU > image(const MatrixType &originalMatrix) const
Definition: FullPivLU.h:188
Definition: ForwardDeclarations.h:124
FullPivLU & setThreshold(const RealScalar &threshold)
Allows to prescribe a threshold to be used by certain methods, such as rank(), who need to determine ...
Definition: FullPivLU.h:255
const PermutationQType & permutationQ() const
Definition: FullPivLU.h:142
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
typename detail::split_list_< List... >::tail tail
Get the list without its first element.
Definition: SplitList.h:58
Index nonzeroPivots() const
Definition: FullPivLU.h:117
Index rank() const
Definition: FullPivLU.h:295
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
RealScalar threshold() const
Returns the threshold that will be used by certain methods such as rank().
Definition: FullPivLU.h:280
internal::traits< MatrixType >::Scalar determinant() const
Definition: FullPivLU.h:515
Definition: ForwardDeclarations.h:127
const MatrixType & matrixLU() const
Definition: FullPivLU.h:104
FullPivLU & setThreshold(Default_t)
Allows to come back to the default behavior, letting Eigen use its default formula for determining th...
Definition: FullPivLU.h:270
bool isInjective() const
Definition: FullPivLU.h:325
bool isSurjective() const
Definition: FullPivLU.h:338
FullPivLU & compute(const MatrixType &matrix)
Computes the LU decomposition of the given matrix.
Definition: FullPivLU.h:425
MatrixType reconstructedMatrix() const
Definition: FullPivLU.h:526
bool isInvertible() const
Definition: FullPivLU.h:350
const PermutationPType & permutationP() const
Definition: FullPivLU.h:132
Definition: BandTriangularSolver.h:13
const internal::solve_retval< FullPivLU, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: FullPivLU.h:215
const internal::kernel_retval< FullPivLU > kernel() const
Definition: FullPivLU.h:162
Definition: ForwardDeclarations.h:126
LU decomposition of a matrix with complete pivoting, and related features.
Definition: ForwardDeclarations.h:216
FullPivLU()
Default Constructor.
Definition: FullPivLU.h:394
Definition: ForwardDeclarations.h:125
Definition: ForwardDeclarations.h:129
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Index dimensionOfKernel() const
Definition: FullPivLU.h:312
const internal::solve_retval< FullPivLU, typename MatrixType::IdentityReturnType > inverse() const
Definition: FullPivLU.h:363
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
Definition: osvr_print_tree.cpp:52
RealScalar maxPivot() const
Definition: FullPivLU.h:126
Definition: ForwardDeclarations.h:128
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48