Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
FullPivLU.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_LU_H
12#define EIGEN_LU_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20template <typename DecompositionType>
21struct kernel_retval;
22template <typename DecompositionType>
23struct image_retval;
24
25template <typename MatrixType_, typename PermutationIndex_>
26struct traits<FullPivLU<MatrixType_, PermutationIndex_> > : traits<MatrixType_> {
27 using XprKind = MatrixXpr;
28 using StorageKind = SolverStorage;
29 using StorageIndex = PermutationIndex_;
30 enum { Flags = 0 };
31};
32
33} // end namespace internal
34
68template <typename MatrixType_, typename PermutationIndex_>
69class FullPivLU : public SolverBase<FullPivLU<MatrixType_, PermutationIndex_> >,
70 public RankRevealingBase<FullPivLU<MatrixType_, PermutationIndex_> > {
71 public:
72 using MatrixType = MatrixType_;
73 using Base = SolverBase<FullPivLU>;
74 using RankRevealingBase_ = RankRevealingBase<FullPivLU>;
75 friend class SolverBase<FullPivLU>;
76 friend class RankRevealingBase<FullPivLU>;
86
87 EIGEN_GENERIC_PUBLIC_INTERFACE(FullPivLU)
88 enum {
89 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
90 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
91 };
92 using PermutationIndex = PermutationIndex_;
93 using IntRowVectorType = typename internal::plain_row_type<MatrixType, PermutationIndex>::type;
94 using IntColVectorType = typename internal::plain_col_type<MatrixType, PermutationIndex>::type;
97 using PlainObject = typename MatrixType::PlainObject;
98
106 eigen_assert(m_isInitialized && "FullPivLU is not initialized.");
107 return Success;
108 }
109
117
124 FullPivLU(Index rows, Index cols);
125
131 template <typename InputType>
132 explicit FullPivLU(const EigenBase<InputType>& matrix);
133
141 template <typename InputType>
143
151 template <typename InputType>
153 // Recomputing with a matrix of another size is allowed, also with EIGEN_NO_AUTOMATIC_RESIZING.
154 m_lu.resize(matrix.rows(), matrix.cols());
155 m_lu = matrix.derived();
156 computeInPlace();
157 return *this;
158 }
159
166 inline const MatrixType& matrixLU() const {
167 eigen_assert(m_isInitialized && "LU is not initialized.");
168 return m_lu;
169 }
170
175 EIGEN_DEVICE_FUNC inline const PermutationPType& permutationP() const {
176 eigen_assert(m_isInitialized && "LU is not initialized.");
177 return m_p;
178 }
179
184 inline const PermutationQType& permutationQ() const {
185 eigen_assert(m_isInitialized && "LU is not initialized.");
186 return m_q;
187 }
188
203 inline const internal::kernel_retval<FullPivLU> kernel() const {
204 eigen_assert(m_isInitialized && "LU is not initialized.");
205 return internal::kernel_retval<FullPivLU>(*this);
206 }
207
227 inline const internal::image_retval<FullPivLU> image(const MatrixType& originalMatrix) const {
228 eigen_assert(m_isInitialized && "LU is not initialized.");
229 return internal::image_retval<FullPivLU>(*this, originalMatrix);
230 }
231
232#ifdef EIGEN_PARSED_BY_DOXYGEN
252 template <typename Rhs>
254#endif
255
259 inline RealScalar rcond() const {
260 eigen_assert(m_isInitialized && "FullPivLU is not initialized.");
261 if (!isInvertible()) {
262 return RealScalar(0);
263 }
264 return internal::rcond_estimate_helper(m_l1_norm, *this);
265 }
266
285 typename internal::traits<MatrixType>::Scalar determinant() const;
286
304 RealScalar absDeterminant() const;
305
320 RealScalar logAbsDeterminant() const;
321
337 Scalar signDeterminant() const;
338
340 RealScalar pivotCoeff(Index i) const { return numext::abs(m_lu.coeff(i, i)); }
341
350 eigen_assert(m_isInitialized && "LU is not initialized.");
351 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the inverse of a non-square matrix!");
352 return Inverse<FullPivLU>(*this);
353 }
354
355 MatrixType reconstructedMatrix() const;
356
357 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_lu.rows(); }
358 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_lu.cols(); }
359
360#ifndef EIGEN_PARSED_BY_DOXYGEN
361 template <typename RhsType, typename DstType>
362 void _solve_impl(const RhsType& rhs, DstType& dst) const;
363
364 template <bool Conjugate, typename RhsType, typename DstType>
365 void _solve_impl_transposed(const RhsType& rhs, DstType& dst) const;
366#endif
367
368 protected:
369 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
370
371 void computeInPlace();
372
373 MatrixType m_lu;
374 PermutationPType m_p;
375 PermutationQType m_q;
376 IntColVectorType m_rowsTranspositions;
377 IntRowVectorType m_colsTranspositions;
378 RealScalar m_l1_norm;
379 signed char m_det_pq;
380 bool m_isInitialized;
381};
382
383template <typename MatrixType, typename PermutationIndex>
385
386template <typename MatrixType, typename PermutationIndex>
388 : m_lu(rows, cols),
389 m_p(rows),
390 m_q(cols),
391 m_rowsTranspositions(rows),
392 m_colsTranspositions(cols),
393 m_isInitialized(false) {}
394
395template <typename MatrixType, typename PermutationIndex>
396template <typename InputType>
398 : m_lu(matrix.rows(), matrix.cols()),
399 m_p(matrix.rows()),
400 m_q(matrix.cols()),
401 m_rowsTranspositions(matrix.rows()),
402 m_colsTranspositions(matrix.cols()),
403 m_isInitialized(false) {
404 compute(matrix.derived());
405}
406
407template <typename MatrixType, typename PermutationIndex>
408template <typename InputType>
410 : m_lu(matrix.derived()),
411 m_p(matrix.rows()),
412 m_q(matrix.cols()),
413 m_rowsTranspositions(matrix.rows()),
414 m_colsTranspositions(matrix.cols()),
415 m_isInitialized(false) {
416 computeInPlace();
417}
418
419template <typename MatrixType, typename PermutationIndex>
420void FullPivLU<MatrixType, PermutationIndex>::computeInPlace() {
421 eigen_assert(m_lu.rows() <= NumTraits<PermutationIndex>::highest() &&
422 m_lu.cols() <= NumTraits<PermutationIndex>::highest());
423
424 if (m_lu.cols() > 0)
425 m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
426 else
427 m_l1_norm = RealScalar(0);
428
429 const Index size = m_lu.diagonalSize();
430 const Index rows = m_lu.rows();
431 const Index cols = m_lu.cols();
432
433 // will store the transpositions, before we accumulate them at the end.
434 // can't accumulate on-the-fly because that will be done in reverse order for the rows.
435 m_rowsTranspositions.resize(m_lu.rows());
436 m_colsTranspositions.resize(m_lu.cols());
437 Index number_of_transpositions = 0; // number of NONTRIVIAL transpositions, i.e. m_rowsTranspositions[i]!=i
438
439 this->m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case)
440 this->m_maxpivot = RealScalar(0);
441
442 for (Index k = 0; k < size; ++k) {
443 // First, we need to find the pivot.
444
445 // biggest coefficient in the remaining bottom-right corner (starting at row k, col k)
446 Index row_of_biggest_in_corner, col_of_biggest_in_corner;
447 using Scoring = internal::scalar_score_coeff_op<Scalar>;
448 using Score = typename Scoring::result_type;
449 Score biggest_in_corner;
450 biggest_in_corner = m_lu.bottomRightCorner(rows - k, cols - k)
451 .unaryExpr(Scoring())
452 .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
453 row_of_biggest_in_corner += k; // correct the values! since they were computed in the corner,
454 col_of_biggest_in_corner += k; // need to add k to them.
455
456 if (numext::is_exactly_zero(biggest_in_corner)) {
457 // before exiting, make sure to initialize the still uninitialized transpositions
458 // in a sane state without destroying what we already have.
459 this->m_nonzero_pivots = k;
460 for (Index i = k; i < size; ++i) {
461 m_rowsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
462 m_colsTranspositions.coeffRef(i) = internal::convert_index<StorageIndex>(i);
463 }
464 break;
465 }
466
467 RealScalar abs_pivot = internal::abs_knowing_score<Scalar>()(
468 m_lu(row_of_biggest_in_corner, col_of_biggest_in_corner), biggest_in_corner);
469 if (abs_pivot > this->m_maxpivot) this->m_maxpivot = abs_pivot;
470
471 // Now that we've found the pivot, we need to apply the row/col swaps to
472 // bring it to the location (k,k).
473
474 m_rowsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner);
475 m_colsTranspositions.coeffRef(k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner);
476 if (k != row_of_biggest_in_corner) {
477 m_lu.row(k).swap(m_lu.row(row_of_biggest_in_corner));
478 ++number_of_transpositions;
479 }
480 if (k != col_of_biggest_in_corner) {
481 m_lu.col(k).swap(m_lu.col(col_of_biggest_in_corner));
482 ++number_of_transpositions;
483 }
484
485 // Now that the pivot is at the right location, we update the remaining
486 // bottom-right corner by Gaussian elimination.
487
488 if (k < rows - 1) m_lu.col(k).tail(rows - k - 1) /= m_lu.coeff(k, k);
489 if (k < size - 1)
490 m_lu.block(k + 1, k + 1, rows - k - 1, cols - k - 1).noalias() -=
491 m_lu.col(k).tail(rows - k - 1) * m_lu.row(k).tail(cols - k - 1);
492 }
493
494 // the main loop is over, we still have to accumulate the transpositions to find the
495 // permutations P and Q
496
497 m_p.setIdentity(rows);
498 for (Index k = size - 1; k >= 0; --k) m_p.applyTranspositionOnTheRight(k, m_rowsTranspositions.coeff(k));
499
500 m_q.setIdentity(cols);
501 for (Index k = 0; k < size; ++k) m_q.applyTranspositionOnTheRight(k, m_colsTranspositions.coeff(k));
502
503 m_det_pq = (number_of_transpositions % 2) ? -1 : 1;
504
505 m_isInitialized = true;
506}
507
508template <typename MatrixType, typename PermutationIndex>
509typename internal::traits<MatrixType>::Scalar FullPivLU<MatrixType, PermutationIndex>::determinant() const {
510 eigen_assert(m_isInitialized && "LU is not initialized.");
511 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
512 return Scalar(m_det_pq) * Scalar(internal::scaled_prod(m_lu.diagonal()).value());
513}
514
515template <typename MatrixType, typename PermutationIndex>
516typename FullPivLU<MatrixType, PermutationIndex>::RealScalar FullPivLU<MatrixType, PermutationIndex>::absDeterminant()
517 const {
518 eigen_assert(m_isInitialized && "LU is not initialized.");
519 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
520 return isInjective() ? internal::scaled_prod(m_lu.diagonal()).abs() : RealScalar(0);
521}
522
523template <typename MatrixType, typename PermutationIndex>
524typename FullPivLU<MatrixType, PermutationIndex>::RealScalar
526 eigen_assert(m_isInitialized && "LU is not initialized.");
527 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
528 return isInjective() ? internal::log_abs_prod(m_lu.diagonal()) : -NumTraits<RealScalar>::infinity();
529}
530
531template <typename MatrixType, typename PermutationIndex>
532typename FullPivLU<MatrixType, PermutationIndex>::Scalar FullPivLU<MatrixType, PermutationIndex>::signDeterminant()
533 const {
534 eigen_assert(m_isInitialized && "LU is not initialized.");
535 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
536 return isInjective() ? Scalar(m_det_pq) * m_lu.diagonal().array().sign().prod() : Scalar(0);
537}
538
542template <typename MatrixType, typename PermutationIndex>
544 eigen_assert(m_isInitialized && "LU is not initialized.");
545 const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols());
546 // LU
547 MatrixType res(m_lu.rows(), m_lu.cols());
548 // FIXME: the .toDenseMatrix() calls should not be needed.
549 res.noalias() = m_lu.leftCols(smalldim).template triangularView<UnitLower>().toDenseMatrix() *
550 m_lu.topRows(smalldim).template triangularView<Upper>().toDenseMatrix();
551
552 // P^{-1}(LU)
553 res = m_p.inverse() * res;
554
555 // (P^{-1}LU)Q^{-1}
556 res = res * m_q.inverse();
557
558 return res;
559}
560
561/********* Implementation of kernel() **************************************************/
562
563namespace internal {
564template <typename MatrixType, typename PermutationIndex>
565auto fullpivlu_nonzero_pivots(const FullPivLU<MatrixType, PermutationIndex>& dec, Index rank) {
566 constexpr int MaxSmallDimAtCompileTime =
567 min_size_prefer_fixed(MatrixType::MaxColsAtCompileTime, MatrixType::MaxRowsAtCompileTime);
569 const typename MatrixType::RealScalar premultiplied_threshold = dec.maxPivot() * dec.threshold();
570 Index p = 0;
571 for (Index i = 0; i < dec.nonzeroPivots(); ++i)
572 if (numext::abs(dec.matrixLU().coeff(i, i)) > premultiplied_threshold) pivots.coeffRef(p++) = i;
573 eigen_internal_assert(p == rank);
574 return pivots;
575}
576
577template <typename MatrixType_, typename PermutationIndex_>
578struct traits<kernel_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
579 using ReturnType = Matrix<typename MatrixType_::Scalar, MatrixType_::ColsAtCompileTime, Dynamic,
580 plain_object_options<MatrixType_>::value, MatrixType_::MaxColsAtCompileTime,
581 MatrixType_::MaxColsAtCompileTime>;
582};
583
584template <typename MatrixType_, typename PermutationIndex_>
585struct kernel_retval<FullPivLU<MatrixType_, PermutationIndex_>>
586 : ReturnByValue<kernel_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
587 using DecompositionType = FullPivLU<MatrixType_, PermutationIndex_>;
588 using MatrixType = MatrixType_;
589 using Scalar = typename MatrixType::Scalar;
590
591 static constexpr int MaxSmallDimAtCompileTime =
592 min_size_prefer_fixed(MatrixType::MaxColsAtCompileTime, MatrixType::MaxRowsAtCompileTime);
593
594 explicit kernel_retval(const DecompositionType& dec)
595 : m_dec(dec), m_rank(dec.rank()), m_cols(m_rank == dec.cols() ? 1 : dec.cols() - m_rank) {}
596
597 Index rows() const { return m_dec.cols(); }
598 Index cols() const { return m_cols; }
599
600 template <typename Dest>
601 void evalTo(Dest& dst) const {
602 const Index cols = m_dec.matrixLU().cols(), dimker = cols - m_rank;
603 if (dimker == 0) {
604 // Represent the zero space by a single zero column.
605 dst.setZero();
606 return;
607 }
608
609 // PAQ = LU implies ker(A) = Q ker(U).
610 const auto pivots = fullpivlu_nonzero_pivots(m_dec, m_rank);
611
612 // Construct a temporary trapezoid matrix m by taking the U matrix and permuting
613 // the rows and cols to bring the nonnegligible pivots to the top of the main diagonal.
614 // This is needed to apply our triangular solvers.
615 // FIXME: simplify once triangularView supports rectangular matrices.
616 Matrix<typename MatrixType::Scalar, Dynamic, Dynamic, plain_object_options<MatrixType>::value,
617 MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
618 m(m_dec.matrixLU().block(0, 0, m_rank, cols));
619 for (Index i = 0; i < m_rank; ++i) {
620 if (i) m.row(i).head(i).setZero();
621 m.row(i).tail(cols - i) = m_dec.matrixLU().row(pivots.coeff(i)).tail(cols - i);
622 }
623 m.block(0, 0, m_rank, m_rank).template triangularView<StrictlyLower>().setZero();
624 for (Index i = 0; i < m_rank; ++i) m.col(i).swap(m.col(pivots.coeff(i)));
625
626 // ok, we have our trapezoid matrix, we can apply the triangular solver.
627 // notice that the math behind this suggests that we should apply this to the
628 // negative of the RHS, but for performance we just put the negative sign elsewhere, see below.
629 m.topLeftCorner(m_rank, m_rank).template triangularView<Upper>().solveInPlace(m.topRightCorner(m_rank, dimker));
630
631 // now we must undo the column permutation that we had applied!
632 for (Index i = m_rank - 1; i >= 0; --i) m.col(i).swap(m.col(pivots.coeff(i)));
633
634 // see the negative sign in the next line, that's what we were talking about above.
635 for (Index i = 0; i < m_rank; ++i) dst.row(m_dec.permutationQ().indices().coeff(i)) = -m.row(i).tail(dimker);
636 for (Index i = m_rank; i < cols; ++i) dst.row(m_dec.permutationQ().indices().coeff(i)).setZero();
637 for (Index k = 0; k < dimker; ++k) dst.coeffRef(m_dec.permutationQ().indices().coeff(m_rank + k), k) = Scalar(1);
638 }
639
640 private:
641 const DecompositionType& m_dec;
642 Index m_rank, m_cols;
643};
644
645/***** Implementation of image() *****************************************************/
646
647template <typename MatrixType_, typename PermutationIndex_>
648struct traits<image_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
649 using ReturnType = Matrix<typename MatrixType_::Scalar, MatrixType_::RowsAtCompileTime, Dynamic,
650 plain_object_options<MatrixType_>::value, MatrixType_::MaxRowsAtCompileTime,
651 MatrixType_::MaxColsAtCompileTime>;
652};
653
654template <typename MatrixType_, typename PermutationIndex_>
655struct image_retval<FullPivLU<MatrixType_, PermutationIndex_>>
656 : ReturnByValue<image_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
657 using DecompositionType = FullPivLU<MatrixType_, PermutationIndex_>;
658 using MatrixType = MatrixType_;
659
660 image_retval(const DecompositionType& dec, const MatrixType& originalMatrix)
661 : m_dec(dec), m_rank(dec.rank()), m_originalMatrix(originalMatrix) {}
662
663 Index rows() const { return m_dec.rows(); }
664 Index cols() const { return m_rank == 0 ? 1 : m_rank; }
665
666 template <typename Dest>
667 void evalTo(Dest& dst) const {
668 if (m_rank == 0) {
669 // Represent the zero space by a single zero column.
670 dst.setZero();
671 return;
672 }
673
674 // Select pivots before writing: dst may overlap an inplace decomposition's storage.
675 const auto pivots = fullpivlu_nonzero_pivots(m_dec, m_rank);
676 for (Index i = 0; i < m_rank; ++i)
677 dst.col(i) = m_originalMatrix.col(m_dec.permutationQ().indices().coeff(pivots.coeff(i)));
678 }
679
680 private:
681 const DecompositionType& m_dec;
682 Index m_rank;
683 const MatrixType& m_originalMatrix;
684};
685
686/***** Implementation of solve() *****************************************************/
687
688} // end namespace internal
689
690#ifndef EIGEN_PARSED_BY_DOXYGEN
691template <typename MatrixType_, typename PermutationIndex_>
692template <typename RhsType, typename DstType>
693void FullPivLU<MatrixType_, PermutationIndex_>::_solve_impl(const RhsType& rhs, DstType& dst) const {
694 /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}.
695 * So we proceed as follows:
696 * Step 1: compute c = P * rhs.
697 * Step 2: replace c by the solution x to Lx = c. Exists because L is invertible.
698 * Step 3: replace c by the solution x to Ux = c. May or may not exist.
699 * Step 4: result = Q * c;
700 */
701
702 const Index rows = this->rows(), cols = this->cols(), nonzero_pivots = this->rank();
703 const Index smalldim = (std::min)(rows, cols);
704
705 if (nonzero_pivots == 0) {
706 dst.setZero();
707 return;
708 }
709
710 typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
711
712 // Step 1
713 c = permutationP() * rhs;
714
715 // Step 2
716 m_lu.topLeftCorner(smalldim, smalldim).template triangularView<UnitLower>().solveInPlace(c.topRows(smalldim));
717 if (rows > cols) c.bottomRows(rows - cols).noalias() -= m_lu.bottomRows(rows - cols) * c.topRows(cols);
718
719 // Step 3
720 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
721 .template triangularView<Upper>()
722 .solveInPlace(c.topRows(nonzero_pivots));
723
724 // Step 4
725 for (Index i = 0; i < nonzero_pivots; ++i) dst.row(permutationQ().indices().coeff(i)) = c.row(i);
726 for (Index i = nonzero_pivots; i < m_lu.cols(); ++i) dst.row(permutationQ().indices().coeff(i)).setZero();
727}
728
729template <typename MatrixType_, typename PermutationIndex_>
730template <bool Conjugate, typename RhsType, typename DstType>
731void FullPivLU<MatrixType_, PermutationIndex_>::_solve_impl_transposed(const RhsType& rhs, DstType& dst) const {
732 /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1},
733 * and since permutations are real and unitary, we can write this
734 * as A^T = Q U^T L^T P,
735 * So we proceed as follows:
736 * Step 1: compute c = Q^T rhs.
737 * Step 2: replace c by the solution x to U^T x = c. May or may not exist.
738 * Step 3: replace c by the solution x to L^T x = c.
739 * Step 4: result = P^T c.
740 * If Conjugate is true, replace "^T" by "^*" above.
741 */
742
743 const Index rows = this->rows(), cols = this->cols(), nonzero_pivots = this->rank();
744 const Index smalldim = (std::min)(rows, cols);
745
746 if (nonzero_pivots == 0) {
747 dst.setZero();
748 return;
749 }
750
751 typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
752
753 // Step 1
754 c = permutationQ().inverse() * rhs;
755
756 // Step 2
757 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
758 .template triangularView<Upper>()
759 .transpose()
760 .template conjugateIf<Conjugate>()
761 .solveInPlace(c.topRows(nonzero_pivots));
762
763 // Step 3
764 m_lu.topLeftCorner(smalldim, smalldim)
765 .template triangularView<UnitLower>()
766 .transpose()
767 .template conjugateIf<Conjugate>()
768 .solveInPlace(c.topRows(smalldim));
769
770 // Step 4
771 PermutationPType invp = permutationP().inverse().eval();
772 for (Index i = 0; i < smalldim; ++i) dst.row(invp.indices().coeff(i)) = c.row(i);
773 for (Index i = smalldim; i < rows; ++i) dst.row(invp.indices().coeff(i)).setZero();
774}
775
776#endif
777
778namespace internal {
779
780/***** Implementation of inverse() *****************************************************/
781template <typename DstXprType, typename MatrixType, typename PermutationIndex>
782struct Assignment<
783 DstXprType, Inverse<FullPivLU<MatrixType, PermutationIndex> >,
784 internal::assign_op<typename DstXprType::Scalar, typename FullPivLU<MatrixType, PermutationIndex>::Scalar>,
785 Dense2Dense> {
786 using LuType = FullPivLU<MatrixType, PermutationIndex>;
787 using SrcXprType = Inverse<LuType>;
788 static void run(DstXprType& dst, const SrcXprType& src,
789 const internal::assign_op<typename DstXprType::Scalar, typename MatrixType::Scalar>&) {
790 dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
791 }
792};
793} // end namespace internal
794
795/******* MatrixBase methods *****************************************************************/
796
803template <typename Derived>
804template <typename PermutationIndex>
805inline FullPivLU<typename MatrixBase<Derived>::PlainObject, PermutationIndex> MatrixBase<Derived>::fullPivLu() const {
807}
808
809} // end namespace Eigen
810
811#endif // EIGEN_LU_H
EvalReturnType eval() const
Definition DenseBase.h:389
LU decomposition of a matrix with complete pivoting, and related features.
Definition FullPivLU.h:70
FullPivLU(EigenBase< InputType > &matrix)
Constructs a LU factorization from a given matrix.
Definition FullPivLU.h:409
const internal::image_retval< FullPivLU > image(const MatrixType &originalMatrix) const
Definition FullPivLU.h:227
RealScalar threshold() const
Definition RankRevealingBase.h:110
const PermutationPType & permutationP() const
Definition FullPivLU.h:175
ComputationInfo info() const
Reports whether the LU factorization was successful.
Definition FullPivLU.h:105
Scalar signDeterminant() const
Definition FullPivLU.h:532
RealScalar pivotCoeff(Index i) const
Definition FullPivLU.h:340
internal::traits< MatrixType >::Scalar determinant() const
Definition FullPivLU.h:509
Index nonzeroPivots() const
Definition RankRevealingBase.h:186
RealScalar rcond() const
Definition FullPivLU.h:259
bool isInvertible() const
Definition RankRevealingBase.h:174
Inverse< FullPivLU > inverse() const
Definition FullPivLU.h:349
MatrixType reconstructedMatrix() const
Definition FullPivLU.h:543
RealScalar absDeterminant() const
Definition FullPivLU.h:516
RealScalar logAbsDeterminant() const
Definition FullPivLU.h:525
bool isInjective() const
Definition RankRevealingBase.h:151
const internal::kernel_retval< FullPivLU > kernel() const
Definition FullPivLU.h:203
RealScalar maxPivot() const
Definition RankRevealingBase.h:194
FullPivLU(const EigenBase< InputType > &matrix)
Definition FullPivLU.h:397
const MatrixType & matrixLU() const
Definition FullPivLU.h:166
Solve< FullPivLU, Rhs > solve(const MatrixBase< Rhs > &b) const
FullPivLU(Index rows, Index cols)
Default Constructor with memory preallocation.
Definition FullPivLU.h:387
const PermutationQType & permutationQ() const
Definition FullPivLU.h:184
FullPivLU & compute(const EigenBase< InputType > &matrix)
Definition FullPivLU.h:152
FullPivLU()
Default Constructor.
Definition FullPivLU.h:384
Expression of the inverse of another expression.
Definition Inverse.h:44
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Permutation matrix.
Definition PermutationMatrix.h:346
Index dimensionOfKernel() const
Definition RankRevealingBase.h:139
bool isInjective() const
Definition RankRevealingBase.h:151
bool isSurjective() const
Definition RankRevealingBase.h:163
FullPivLU & setThreshold(const RealScalar &threshold)
Definition RankRevealingBase.h:87
Index nonzeroPivots() const
Definition RankRevealingBase.h:186
RealScalar threshold() const
Definition RankRevealingBase.h:110
RealScalar maxPivot() const
Definition RankRevealingBase.h:194
Index rank() const
Definition RankRevealingBase.h:125
bool isInvertible() const
Definition RankRevealingBase.h:174
Pseudo expression representing a solving operation.
Definition Solve.h:63
constexpr FullPivLU< MatrixType_, PermutationIndex_ > & derived()
ComputationInfo
Definition Constants.h:455
@ Success
Definition Constants.h:457
Definition EigenBase.h:34
constexpr Index cols() const noexcept
Definition EigenBase.h:62
constexpr Derived & derived()
Definition EigenBase.h:50
constexpr Index rows() const noexcept
Definition EigenBase.h:60
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:44