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 internal::scaled_product<Scalar> det = internal::scaled_prod(m_lu.diagonal());
513 det.multiply(Scalar(m_det_pq));
514 return det.value();
515}
516
517template <typename MatrixType, typename PermutationIndex>
518typename FullPivLU<MatrixType, PermutationIndex>::RealScalar FullPivLU<MatrixType, PermutationIndex>::absDeterminant()
519 const {
520 eigen_assert(m_isInitialized && "LU is not initialized.");
521 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
522 return isInjective() ? internal::scaled_prod(m_lu.diagonal()).abs() : RealScalar(0);
523}
524
525template <typename MatrixType, typename PermutationIndex>
526typename FullPivLU<MatrixType, PermutationIndex>::RealScalar
528 eigen_assert(m_isInitialized && "LU is not initialized.");
529 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
530 return isInjective() ? internal::log_abs_prod(m_lu.diagonal()) : -NumTraits<RealScalar>::infinity();
531}
532
533template <typename MatrixType, typename PermutationIndex>
534typename FullPivLU<MatrixType, PermutationIndex>::Scalar FullPivLU<MatrixType, PermutationIndex>::signDeterminant()
535 const {
536 eigen_assert(m_isInitialized && "LU is not initialized.");
537 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(m_lu, "You can't take the determinant of a non-square matrix!");
538 return isInjective() ? Scalar(m_det_pq) * m_lu.diagonal().array().sign().prod() : Scalar(0);
539}
540
544template <typename MatrixType, typename PermutationIndex>
546 eigen_assert(m_isInitialized && "LU is not initialized.");
547 const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols());
548 // LU
549 MatrixType res(m_lu.rows(), m_lu.cols());
550 // FIXME: the .toDenseMatrix() calls should not be needed.
551 res.noalias() = m_lu.leftCols(smalldim).template triangularView<UnitLower>().toDenseMatrix() *
552 m_lu.topRows(smalldim).template triangularView<Upper>().toDenseMatrix();
553
554 // P^{-1}(LU)
555 res = m_p.inverse() * res;
556
557 // (P^{-1}LU)Q^{-1}
558 res = res * m_q.inverse();
559
560 return res;
561}
562
563/********* Implementation of kernel() **************************************************/
564
565namespace internal {
566template <typename MatrixType, typename PermutationIndex>
567auto fullpivlu_nonzero_pivots(const FullPivLU<MatrixType, PermutationIndex>& dec, Index rank) {
568 constexpr int MaxSmallDimAtCompileTime =
569 min_size_prefer_fixed(MatrixType::MaxColsAtCompileTime, MatrixType::MaxRowsAtCompileTime);
571 const typename MatrixType::RealScalar premultiplied_threshold = dec.maxPivot() * dec.threshold();
572 Index p = 0;
573 for (Index i = 0; i < dec.nonzeroPivots(); ++i)
574 if (numext::abs(dec.matrixLU().coeff(i, i)) > premultiplied_threshold) pivots.coeffRef(p++) = i;
575 eigen_internal_assert(p == rank);
576 return pivots;
577}
578
579template <typename MatrixType_, typename PermutationIndex_>
580struct traits<kernel_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
581 using ReturnType = Matrix<typename MatrixType_::Scalar, MatrixType_::ColsAtCompileTime, Dynamic,
582 plain_object_options<MatrixType_>::value, MatrixType_::MaxColsAtCompileTime,
583 MatrixType_::MaxColsAtCompileTime>;
584};
585
586template <typename MatrixType_, typename PermutationIndex_>
587struct kernel_retval<FullPivLU<MatrixType_, PermutationIndex_>>
588 : ReturnByValue<kernel_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
589 using DecompositionType = FullPivLU<MatrixType_, PermutationIndex_>;
590 using MatrixType = MatrixType_;
591 using Scalar = typename MatrixType::Scalar;
592
593 static constexpr int MaxSmallDimAtCompileTime =
594 min_size_prefer_fixed(MatrixType::MaxColsAtCompileTime, MatrixType::MaxRowsAtCompileTime);
595
596 explicit kernel_retval(const DecompositionType& dec)
597 : m_dec(dec), m_rank(dec.rank()), m_cols(m_rank == dec.cols() ? 1 : dec.cols() - m_rank) {}
598
599 Index rows() const { return m_dec.cols(); }
600 Index cols() const { return m_cols; }
601
602 template <typename Dest>
603 void evalTo(Dest& dst) const {
604 const Index cols = m_dec.matrixLU().cols(), dimker = cols - m_rank;
605 if (dimker == 0) {
606 // Represent the zero space by a single zero column.
607 dst.setZero();
608 return;
609 }
610
611 // PAQ = LU implies ker(A) = Q ker(U).
612 const auto pivots = fullpivlu_nonzero_pivots(m_dec, m_rank);
613
614 // Construct a temporary trapezoid matrix m by taking the U matrix and permuting
615 // the rows and cols to bring the nonnegligible pivots to the top of the main diagonal.
616 // This is needed to apply our triangular solvers.
617 // FIXME: simplify once triangularView supports rectangular matrices.
618 Matrix<typename MatrixType::Scalar, Dynamic, Dynamic, plain_object_options<MatrixType>::value,
619 MaxSmallDimAtCompileTime, MatrixType::MaxColsAtCompileTime>
620 m(m_dec.matrixLU().block(0, 0, m_rank, cols));
621 for (Index i = 0; i < m_rank; ++i) {
622 if (i) m.row(i).head(i).setZero();
623 m.row(i).tail(cols - i) = m_dec.matrixLU().row(pivots.coeff(i)).tail(cols - i);
624 }
625 m.block(0, 0, m_rank, m_rank).template triangularView<StrictlyLower>().setZero();
626 for (Index i = 0; i < m_rank; ++i) m.col(i).swap(m.col(pivots.coeff(i)));
627
628 // ok, we have our trapezoid matrix, we can apply the triangular solver.
629 // notice that the math behind this suggests that we should apply this to the
630 // negative of the RHS, but for performance we just put the negative sign elsewhere, see below.
631 m.topLeftCorner(m_rank, m_rank).template triangularView<Upper>().solveInPlace(m.topRightCorner(m_rank, dimker));
632
633 // now we must undo the column permutation that we had applied!
634 for (Index i = m_rank - 1; i >= 0; --i) m.col(i).swap(m.col(pivots.coeff(i)));
635
636 // see the negative sign in the next line, that's what we were talking about above.
637 for (Index i = 0; i < m_rank; ++i) dst.row(m_dec.permutationQ().indices().coeff(i)) = -m.row(i).tail(dimker);
638 for (Index i = m_rank; i < cols; ++i) dst.row(m_dec.permutationQ().indices().coeff(i)).setZero();
639 for (Index k = 0; k < dimker; ++k) dst.coeffRef(m_dec.permutationQ().indices().coeff(m_rank + k), k) = Scalar(1);
640 }
641
642 private:
643 const DecompositionType& m_dec;
644 Index m_rank, m_cols;
645};
646
647/***** Implementation of image() *****************************************************/
648
649template <typename MatrixType_, typename PermutationIndex_>
650struct traits<image_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
651 using ReturnType = Matrix<typename MatrixType_::Scalar, MatrixType_::RowsAtCompileTime, Dynamic,
652 plain_object_options<MatrixType_>::value, MatrixType_::MaxRowsAtCompileTime,
653 MatrixType_::MaxColsAtCompileTime>;
654};
655
656template <typename MatrixType_, typename PermutationIndex_>
657struct image_retval<FullPivLU<MatrixType_, PermutationIndex_>>
658 : ReturnByValue<image_retval<FullPivLU<MatrixType_, PermutationIndex_>>> {
659 using DecompositionType = FullPivLU<MatrixType_, PermutationIndex_>;
660 using MatrixType = MatrixType_;
661
662 image_retval(const DecompositionType& dec, const MatrixType& originalMatrix)
663 : m_dec(dec), m_rank(dec.rank()), m_originalMatrix(originalMatrix) {}
664
665 Index rows() const { return m_dec.rows(); }
666 Index cols() const { return m_rank == 0 ? 1 : m_rank; }
667
668 template <typename Dest>
669 void evalTo(Dest& dst) const {
670 if (m_rank == 0) {
671 // Represent the zero space by a single zero column.
672 dst.setZero();
673 return;
674 }
675
676 // Select pivots before writing: dst may overlap an inplace decomposition's storage.
677 const auto pivots = fullpivlu_nonzero_pivots(m_dec, m_rank);
678 for (Index i = 0; i < m_rank; ++i)
679 dst.col(i) = m_originalMatrix.col(m_dec.permutationQ().indices().coeff(pivots.coeff(i)));
680 }
681
682 private:
683 const DecompositionType& m_dec;
684 Index m_rank;
685 const MatrixType& m_originalMatrix;
686};
687
688/***** Implementation of solve() *****************************************************/
689
690} // end namespace internal
691
692#ifndef EIGEN_PARSED_BY_DOXYGEN
693template <typename MatrixType_, typename PermutationIndex_>
694template <typename RhsType, typename DstType>
695void FullPivLU<MatrixType_, PermutationIndex_>::_solve_impl(const RhsType& rhs, DstType& dst) const {
696 /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}.
697 * So we proceed as follows:
698 * Step 1: compute c = P * rhs.
699 * Step 2: replace c by the solution x to Lx = c. Exists because L is invertible.
700 * Step 3: replace c by the solution x to Ux = c. May or may not exist.
701 * Step 4: result = Q * c;
702 */
703
704 const Index rows = this->rows(), cols = this->cols(), nonzero_pivots = this->rank();
705 const Index smalldim = (std::min)(rows, cols);
706
707 if (nonzero_pivots == 0) {
708 dst.setZero();
709 return;
710 }
711
712 typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
713
714 // Step 1
715 c = permutationP() * rhs;
716
717 // Step 2
718 m_lu.topLeftCorner(smalldim, smalldim).template triangularView<UnitLower>().solveInPlace(c.topRows(smalldim));
719 if (rows > cols) c.bottomRows(rows - cols).noalias() -= m_lu.bottomRows(rows - cols) * c.topRows(cols);
720
721 // Step 3
722 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
723 .template triangularView<Upper>()
724 .solveInPlace(c.topRows(nonzero_pivots));
725
726 // Step 4
727 for (Index i = 0; i < nonzero_pivots; ++i) dst.row(permutationQ().indices().coeff(i)) = c.row(i);
728 for (Index i = nonzero_pivots; i < m_lu.cols(); ++i) dst.row(permutationQ().indices().coeff(i)).setZero();
729}
730
731template <typename MatrixType_, typename PermutationIndex_>
732template <bool Conjugate, typename RhsType, typename DstType>
733void FullPivLU<MatrixType_, PermutationIndex_>::_solve_impl_transposed(const RhsType& rhs, DstType& dst) const {
734 /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1},
735 * and since permutations are real and unitary, we can write this
736 * as A^T = Q U^T L^T P,
737 * So we proceed as follows:
738 * Step 1: compute c = Q^T rhs.
739 * Step 2: replace c by the solution x to U^T x = c. May or may not exist.
740 * Step 3: replace c by the solution x to L^T x = c.
741 * Step 4: result = P^T c.
742 * If Conjugate is true, replace "^T" by "^*" above.
743 */
744
745 const Index rows = this->rows(), cols = this->cols(), nonzero_pivots = this->rank();
746 const Index smalldim = (std::min)(rows, cols);
747
748 if (nonzero_pivots == 0) {
749 dst.setZero();
750 return;
751 }
752
753 typename RhsType::PlainObject c(rhs.rows(), rhs.cols());
754
755 // Step 1
756 c = permutationQ().inverse() * rhs;
757
758 // Step 2
759 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
760 .template triangularView<Upper>()
761 .transpose()
762 .template conjugateIf<Conjugate>()
763 .solveInPlace(c.topRows(nonzero_pivots));
764
765 // Step 3
766 m_lu.topLeftCorner(smalldim, smalldim)
767 .template triangularView<UnitLower>()
768 .transpose()
769 .template conjugateIf<Conjugate>()
770 .solveInPlace(c.topRows(smalldim));
771
772 // Step 4
773 PermutationPType invp = permutationP().inverse().eval();
774 for (Index i = 0; i < smalldim; ++i) dst.row(invp.indices().coeff(i)) = c.row(i);
775 for (Index i = smalldim; i < rows; ++i) dst.row(invp.indices().coeff(i)).setZero();
776}
777
778#endif
779
780namespace internal {
781
782/***** Implementation of inverse() *****************************************************/
783template <typename DstXprType, typename MatrixType, typename PermutationIndex>
784struct Assignment<
785 DstXprType, Inverse<FullPivLU<MatrixType, PermutationIndex> >,
786 internal::assign_op<typename DstXprType::Scalar, typename FullPivLU<MatrixType, PermutationIndex>::Scalar>,
787 Dense2Dense> {
788 using LuType = FullPivLU<MatrixType, PermutationIndex>;
789 using SrcXprType = Inverse<LuType>;
790 static void run(DstXprType& dst, const SrcXprType& src,
791 const internal::assign_op<typename DstXprType::Scalar, typename MatrixType::Scalar>&) {
792 dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
793 }
794};
795} // end namespace internal
796
797/******* MatrixBase methods *****************************************************************/
798
805template <typename Derived>
806template <typename PermutationIndex>
807inline FullPivLU<typename MatrixBase<Derived>::PlainObject, PermutationIndex> MatrixBase<Derived>::fullPivLu() const {
809}
810
811} // end namespace Eigen
812
813#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:534
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:545
RealScalar absDeterminant() const
Definition FullPivLU.h:518
RealScalar logAbsDeterminant() const
Definition FullPivLU.h:527
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