19 template <
typename MatrixType_,
typename PermutationIndex_>
62 template <
typename MatrixType_,
typename PermutationIndex_>
102 template <
typename InputType>
112 template <
typename InputType>
122 template <
typename InputType>
218 #ifdef EIGEN_PARSED_BY_DOXYGEN
238 template <
typename Rhs>
385 eigen_assert(
m_lu.rows() ==
m_lu.cols() &&
"You can't take the inverse of a non-square matrix!");
394 #ifndef EIGEN_PARSED_BY_DOXYGEN
395 template <
typename RhsType,
typename DstType>
396 void _solve_impl(
const RhsType& rhs, DstType& dst)
const;
398 template <
bool Conjugate,
typename RhsType,
typename DstType>
419 template <
typename MatrixType,
typename PermutationIndex>
422 template <
typename MatrixType,
typename PermutationIndex>
427 m_rowsTranspositions(
rows),
428 m_colsTranspositions(
cols),
429 m_isInitialized(false),
430 m_usePrescribedThreshold(false) {}
432 template <
typename MatrixType,
typename PermutationIndex>
433 template <
typename InputType>
440 m_isInitialized(false),
441 m_usePrescribedThreshold(false) {
445 template <
typename MatrixType,
typename PermutationIndex>
446 template <
typename InputType>
453 m_isInitialized(false),
454 m_usePrescribedThreshold(false) {
458 template <
typename MatrixType,
typename PermutationIndex>
463 m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
471 m_rowsTranspositions.resize(m_lu.rows());
472 m_colsTranspositions.resize(m_lu.cols());
473 Index number_of_transpositions = 0;
475 m_nonzero_pivots =
size;
482 Index row_of_biggest_in_corner, col_of_biggest_in_corner;
484 typedef typename Scoring::result_type Score;
485 Score biggest_in_corner;
486 biggest_in_corner = m_lu.bottomRightCorner(
rows -
k,
cols -
k)
487 .unaryExpr(Scoring())
488 .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
489 row_of_biggest_in_corner +=
k;
490 col_of_biggest_in_corner +=
k;
495 m_nonzero_pivots =
k;
497 m_rowsTranspositions.coeffRef(
i) = internal::convert_index<StorageIndex>(
i);
498 m_colsTranspositions.coeffRef(
i) = internal::convert_index<StorageIndex>(
i);
504 m_lu(row_of_biggest_in_corner, col_of_biggest_in_corner), biggest_in_corner);
505 if (abs_pivot > m_maxpivot) m_maxpivot = abs_pivot;
510 m_rowsTranspositions.coeffRef(
k) = internal::convert_index<StorageIndex>(row_of_biggest_in_corner);
511 m_colsTranspositions.coeffRef(
k) = internal::convert_index<StorageIndex>(col_of_biggest_in_corner);
512 if (
k != row_of_biggest_in_corner) {
513 m_lu.row(
k).swap(m_lu.row(row_of_biggest_in_corner));
514 ++number_of_transpositions;
516 if (
k != col_of_biggest_in_corner) {
517 m_lu.col(
k).swap(m_lu.col(col_of_biggest_in_corner));
518 ++number_of_transpositions;
524 if (
k <
rows - 1) m_lu.col(
k).tail(
rows -
k - 1) /= m_lu.coeff(
k,
k);
526 m_lu.block(
k + 1,
k + 1,
rows -
k - 1,
cols -
k - 1).noalias() -=
527 m_lu.col(
k).tail(
rows -
k - 1) * m_lu.row(
k).tail(
cols -
k - 1);
533 m_p.setIdentity(
rows);
534 for (
Index k =
size - 1;
k >= 0; --
k) m_p.applyTranspositionOnTheRight(
k, m_rowsTranspositions.coeff(
k));
536 m_q.setIdentity(
cols);
537 for (
Index k = 0;
k <
size; ++
k) m_q.applyTranspositionOnTheRight(
k, m_colsTranspositions.coeff(
k));
539 m_det_pq = (number_of_transpositions % 2) ? -1 : 1;
541 m_isInitialized =
true;
544 template <
typename MatrixType,
typename PermutationIndex>
546 eigen_assert(m_isInitialized &&
"LU is not initialized.");
547 eigen_assert(m_lu.rows() == m_lu.cols() &&
"You can't take the determinant of a non-square matrix!");
548 return Scalar(m_det_pq) *
Scalar(m_lu.diagonal().prod());
554 template <
typename MatrixType,
typename PermutationIndex>
556 eigen_assert(m_isInitialized &&
"LU is not initialized.");
561 res = m_lu.leftCols(smalldim).template triangularView<UnitLower>().toDenseMatrix() *
562 m_lu.topRows(smalldim).template triangularView<Upper>().toDenseMatrix();
565 res = m_p.inverse() *
res;
568 res =
res * m_q.inverse();
576 template <
typename MatrixType_,
typename PermutationIndex_>
583 MaxSmallDimAtCompileTime =
min_size_prefer_fixed(MatrixType::MaxColsAtCompileTime, MatrixType::MaxRowsAtCompileTime)
586 template <
typename Dest>
589 const Index cols = dec().matrixLU().cols(), dimker =
cols - rank();
615 RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
617 for (
Index i = 0;
i < dec().nonzeroPivots(); ++
i)
618 if (
abs(dec().matrixLU().coeff(
i,
i)) > premultiplied_threshold) pivots.
coeffRef(
p++) =
i;
626 MatrixType::MaxColsAtCompileTime>
627 m(dec().matrixLU().
block(0, 0, rank(),
cols));
628 for (
Index i = 0;
i < rank(); ++
i) {
629 if (
i)
m.row(
i).head(
i).setZero();
632 m.block(0, 0, rank(), rank());
633 m.block(0, 0, rank(), rank()).template triangularView<StrictlyLower>().setZero();
639 m.topLeftCorner(rank(), rank()).
template triangularView<Upper>().solveInPlace(
m.topRightCorner(rank(), dimker));
645 for (
Index i = 0;
i < rank(); ++
i) dst.row(dec().permutationQ().indices().coeff(
i)) = -
m.row(
i).tail(dimker);
646 for (
Index i = rank();
i <
cols; ++
i) dst.row(dec().permutationQ().indices().coeff(
i)).
setZero();
647 for (
Index k = 0;
k < dimker; ++
k) dst.coeffRef(dec().permutationQ().indices().coeff(rank() +
k),
k) =
Scalar(1);
653 template <
typename MatrixType_,
typename PermutationIndex_>
660 MaxSmallDimAtCompileTime =
min_size_prefer_fixed(MatrixType::MaxColsAtCompileTime, MatrixType::MaxRowsAtCompileTime)
663 template <
typename Dest>
675 RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
677 for (
Index i = 0;
i < dec().nonzeroPivots(); ++
i)
678 if (
abs(dec().matrixLU().coeff(
i,
i)) > premultiplied_threshold) pivots.
coeffRef(
p++) =
i;
682 dst.col(
i) = originalMatrix().col(dec().permutationQ().indices().coeff(pivots.
coeff(
i)));
690 #ifndef EIGEN_PARSED_BY_DOXYGEN
691 template <
typename MatrixType_,
typename PermutationIndex_>
692 template <
typename RhsType,
typename DstType>
705 if (nonzero_pivots == 0) {
710 typename RhsType::PlainObject
c(rhs.rows(), rhs.cols());
713 c = permutationP() * rhs;
716 m_lu.topLeftCorner(smalldim, smalldim).template triangularView<UnitLower>().solveInPlace(
c.topRows(smalldim));
720 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
721 .template triangularView<Upper>()
722 .solveInPlace(
c.topRows(nonzero_pivots));
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();
729 template <
typename MatrixType_,
typename PermutationIndex_>
730 template <
bool Conjugate,
typename RhsType,
typename DstType>
746 if (nonzero_pivots == 0) {
751 typename RhsType::PlainObject
c(rhs.rows(), rhs.cols());
754 c = permutationQ().inverse() * rhs;
757 m_lu.topLeftCorner(nonzero_pivots, nonzero_pivots)
758 .template triangularView<Upper>()
760 .template conjugateIf<Conjugate>()
761 .solveInPlace(
c.topRows(nonzero_pivots));
764 m_lu.topLeftCorner(smalldim, smalldim)
765 .template triangularView<UnitLower>()
767 .template conjugateIf<Conjugate>()
768 .solveInPlace(
c.topRows(smalldim));
781 template <
typename DstXprType,
typename MatrixType,
typename PermutationIndex>
784 internal::
assign_op<typename DstXprType::Scalar, typename FullPivLU<MatrixType, PermutationIndex>::Scalar>,
803 template <
typename Derived>
804 template <
typename PermutationIndex>
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType)
Definition: Image.h:66
#define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType)
Definition: Kernel.h:64
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1149
#define eigen_internal_assert(x)
Definition: Macros.h:916
#define EIGEN_NOEXCEPT
Definition: Macros.h:1267
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define eigen_assert(x)
Definition: Macros.h:910
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition: StaticAssert.h:74
float * p
Definition: Tutorial_Map_using.cpp:9
m m block(1, 0, 2, 2)<< 4
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
LU decomposition of a matrix with complete pivoting, and related features.
Definition: FullPivLU.h:63
IntColVectorType m_rowsTranspositions
Definition: FullPivLU.h:410
internal::plain_row_type< MatrixType, PermutationIndex >::type IntRowVectorType
Definition: FullPivLU.h:75
FullPivLU & setThreshold(const RealScalar &threshold)
Definition: FullPivLU.h:284
bool isInjective() const
Definition: FullPivLU.h:348
bool isInvertible() const
Definition: FullPivLU.h:371
internal::traits< MatrixType >::Scalar determinant() const
Definition: FullPivLU.h:545
internal::plain_col_type< MatrixType, PermutationIndex >::type IntColVectorType
Definition: FullPivLU.h:76
MatrixType m_lu
Definition: FullPivLU.h:407
RealScalar rcond() const
Definition: FullPivLU.h:245
IntRowVectorType m_colsTranspositions
Definition: FullPivLU.h:411
void computeInPlace()
Definition: FullPivLU.h:459
MatrixType_ MatrixType
Definition: FullPivLU.h:65
Index nonzeroPivots() const
Definition: FullPivLU.h:147
RealScalar m_l1_norm
Definition: FullPivLU.h:413
bool m_usePrescribedThreshold
Definition: FullPivLU.h:416
MatrixType::PlainObject PlainObject
Definition: FullPivLU.h:79
signed char m_det_pq
Definition: FullPivLU.h:415
MatrixType reconstructedMatrix() const
Definition: FullPivLU.h:555
const MatrixType & matrixLU() const
Definition: FullPivLU.h:135
const Inverse< FullPivLU > inverse() const
Definition: FullPivLU.h:383
bool m_isInitialized
Definition: FullPivLU.h:416
Index m_nonzero_pivots
Definition: FullPivLU.h:412
FullPivLU & compute(const EigenBase< InputType > &matrix)
Definition: FullPivLU.h:123
RealScalar maxPivot() const
Definition: FullPivLU.h:155
Index rank() const
Definition: FullPivLU.h:321
PermutationIndex_ PermutationIndex
Definition: FullPivLU.h:74
FullPivLU & setThreshold(Default_t)
Definition: FullPivLU.h:298
RealScalar m_prescribedThreshold
Definition: FullPivLU.h:414
EIGEN_DEVICE_FUNC const PermutationPType & permutationP() const
Definition: FullPivLU.h:161
@ MaxRowsAtCompileTime
Definition: FullPivLU.h:71
@ MaxColsAtCompileTime
Definition: FullPivLU.h:72
SolverBase< FullPivLU > Base
Definition: FullPivLU.h:66
RealScalar m_maxpivot
Definition: FullPivLU.h:414
PermutationMatrix< ColsAtCompileTime, MaxColsAtCompileTime, PermutationIndex > PermutationQType
Definition: FullPivLU.h:77
void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const
Definition: FullPivLU.h:731
bool isSurjective() const
Definition: FullPivLU.h:360
const internal::image_retval< FullPivLU > image(const MatrixType &originalMatrix) const
Definition: FullPivLU.h:213
RealScalar threshold() const
Definition: FullPivLU.h:307
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: FullPivLU.h:391
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: FullPivLU.h:392
const internal::kernel_retval< FullPivLU > kernel() const
Definition: FullPivLU.h:189
PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime, PermutationIndex > PermutationPType
Definition: FullPivLU.h:78
PermutationPType m_p
Definition: FullPivLU.h:408
void _solve_impl(const RhsType &rhs, DstType &dst) const
Definition: FullPivLU.h:693
const PermutationQType & permutationQ() const
Definition: FullPivLU.h:170
PermutationQType m_q
Definition: FullPivLU.h:409
Index dimensionOfKernel() const
Definition: FullPivLU.h:336
FullPivLU()
Default Constructor.
Definition: FullPivLU.h:420
Expression of the inverse of another expression.
Definition: Inverse.h:43
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Inverse.h:55
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Inverse.h:54
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned & nestedExpression() const
Definition: Inverse.h:57
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
const FullPivLU< PlainObject, PermutationIndex > fullPivLu() const
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:217
InverseReturnType inverse() const
Definition: PermutationMatrix.h:172
const IndicesType & indices() const
Definition: PermutationMatrix.h:334
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:198
Pseudo expression representing a solving operation.
Definition: Solve.h:62
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:72
const Solve< FullPivLU< MatrixType_, PermutationIndex_ >, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:106
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
#define min(a, b)
Definition: datatypes.h:22
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
constexpr int min_size_prefer_fixed(A a, B b)
Definition: Meta.h:683
Decomposition::RealScalar rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition &dec)
Reciprocal condition number estimator.
Definition: ConditionEstimator.h:157
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Default_t
Definition: Constants.h:361
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
int c
Definition: calibrate.py:100
Definition: Eigen_Colamd.h:49
double epsilon
Definition: osc_ring_sarah_asymptotics.h:43
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
Definition: EigenBase.h:33
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
Definition: Constants.h:534
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: Constants.h:525
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename MatrixType::Scalar > &)
Definition: FullPivLU.h:788
Inverse< LuType > SrcXprType
Definition: FullPivLU.h:787
FullPivLU< MatrixType, PermutationIndex > LuType
Definition: FullPivLU.h:786
Definition: AssignEvaluator.h:773
Definition: AssignEvaluator.h:756
Definition: functors/UnaryFunctors.h:71
Template functor for scalar/packet assignment.
Definition: AssignmentFunctors.h:25
void evalTo(Dest &dst) const
Definition: FullPivLU.h:664
Definition: ForwardDeclarations.h:207
void evalTo(Dest &dst) const
Definition: FullPivLU.h:587
Definition: ForwardDeclarations.h:203
std::conditional_t< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixColType, ArrayColType > type
Definition: XprHelper.h:782
std::conditional_t< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixRowType, ArrayRowType > type
Definition: XprHelper.h:768
Template functor to compute the score of a scalar, to chose a pivot.
Definition: functors/UnaryFunctors.h:63
SolverStorage StorageKind
Definition: FullPivLU.h:22
MatrixXpr XprKind
Definition: FullPivLU.h:21
PermutationIndex_ StorageIndex
Definition: FullPivLU.h:23
Definition: ForwardDeclarations.h:21