11#ifndef EIGEN_PARTIALLU_H
12#define EIGEN_PARTIALLU_H
30template<
typename T,
typename Derived>
36template<
typename T,
typename Derived>
77 :
public SolverBase<PartialPivLU<_MatrixType> >
117 template<
typename InputType>
127 template<
typename InputType>
130 template<
typename InputType>
157 #ifdef EIGEN_PARSED_BY_DOXYGEN
175 template<
typename Rhs>
222 #ifndef EIGEN_PARSED_BY_DOXYGEN
223 template<
typename RhsType,
typename DstType>
237 m_lu.template triangularView<UnitLower>().solveInPlace(dst);
240 m_lu.template triangularView<Upper>().solveInPlace(dst);
243 template<
bool Conjugate,
typename RhsType,
typename DstType>
256 dst =
m_lu.template triangularView<Upper>().transpose()
257 .template conjugateIf<Conjugate>().solve(rhs);
259 m_lu.template triangularView<UnitLower>().transpose()
260 .template conjugateIf<Conjugate>().solveInPlace(dst);
283template<
typename MatrixType>
287 m_rowsTranspositions(),
290 m_isInitialized(false)
294template<
typename MatrixType>
298 m_rowsTranspositions(
size),
301 m_isInitialized(false)
305template<
typename MatrixType>
306template<
typename InputType>
308 : m_lu(matrix.rows(),matrix.cols()),
310 m_rowsTranspositions(matrix.rows()),
313 m_isInitialized(false)
318template<
typename MatrixType>
319template<
typename InputType>
321 : m_lu(matrix.derived()),
323 m_rowsTranspositions(matrix.rows()),
326 m_isInitialized(false)
334template<
typename Scalar,
int StorageOrder,
typename PivIndex,
int SizeAtCompileTime=Dynamic>
361 typedef typename Scoring::result_type Score;
362 const Index rows = lu.rows();
363 const Index cols = lu.cols();
368 nb_transpositions = 0;
369 Index first_zero_pivot = -1;
370 for(
Index k = 0; k < endk; ++k)
372 int rrows = internal::convert_index<int>(rows-k-1);
373 int rcols = internal::convert_index<int>(cols-k-1);
375 Index row_of_biggest_in_col;
376 Score biggest_in_corner
377 = lu.col(k).tail(rows-k).unaryExpr(Scoring()).maxCoeff(&row_of_biggest_in_col);
378 row_of_biggest_in_col += k;
380 row_transpositions[k] = PivIndex(row_of_biggest_in_col);
382 if(biggest_in_corner != Score(0))
384 if(k != row_of_biggest_in_col)
386 lu.row(k).swap(lu.row(row_of_biggest_in_col));
390 lu.col(k).tail(fix<RRows>(rrows)) /= lu.coeff(k,k);
392 else if(first_zero_pivot==-1)
396 first_zero_pivot = k;
400 lu.bottomRightCorner(fix<RRows>(rrows),fix<RCols>(rcols)).noalias() -= lu.col(k).tail(fix<RRows>(rrows)) * lu.row(k).tail(fix<RCols>(rcols));
407 row_transpositions[k] = PivIndex(k);
408 if (Scoring()(lu(k, k)) == Score(0) && first_zero_pivot == -1)
409 first_zero_pivot = k;
412 return first_zero_pivot;
439 return unblocked_lu(lu, row_transpositions, nb_transpositions);
447 blockSize = (blockSize/16)*16;
451 nb_transpositions = 0;
452 Index first_zero_pivot = -1;
456 Index trows = rows - k - bs;
464 BlockType A_2 = lu.block(0,k+bs,rows,tsize);
466 BlockType A12 = lu.block(k,k+bs,bs,tsize);
467 BlockType A21 = lu.block(k+bs,k,trows,bs);
468 BlockType A22 = lu.block(k+bs,k+bs,trows,tsize);
470 PivIndex nb_transpositions_in_panel;
474 row_transpositions+k, nb_transpositions_in_panel, 16);
475 if(ret>=0 && first_zero_pivot==-1)
476 first_zero_pivot = k+ret;
478 nb_transpositions += nb_transpositions_in_panel;
480 for(
Index i=k; i<k+bs; ++i)
482 Index piv = (row_transpositions[i] += internal::convert_index<PivIndex>(k));
483 A_0.row(i).swap(A_0.row(piv));
489 for(
Index i=k;i<k+bs; ++i)
490 A_2.row(i).swap(A_2.row(row_transpositions[i]));
493 A11.template triangularView<UnitLower>().solveInPlace(A12);
495 A22.noalias() -= A21 * A12;
498 return first_zero_pivot;
504template<
typename MatrixType,
typename TranspositionType>
505void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions,
typename TranspositionType::StorageIndex& nb_transpositions)
508 if (lu.rows() == 0 || lu.cols() == 0) {
509 nb_transpositions = 0;
513 eigen_assert(row_transpositions.size() < 2 || (&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1);
517 typename TranspositionType::StorageIndex,
519 ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions);
524template<
typename MatrixType>
527 check_template_parameters();
533 m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
535 m_l1_norm = RealScalar(0);
537 eigen_assert(m_lu.rows() == m_lu.cols() &&
"PartialPivLU is only for square (and moreover invertible) matrices");
540 m_rowsTranspositions.resize(
size);
544 m_det_p = (nb_transpositions%2) ? -1 : 1;
546 m_p = m_rowsTranspositions;
548 m_isInitialized =
true;
551template<
typename MatrixType>
554 eigen_assert(m_isInitialized &&
"PartialPivLU is not initialized.");
555 return Scalar(m_det_p) * m_lu.diagonal().prod();
561template<
typename MatrixType>
564 eigen_assert(m_isInitialized &&
"LU is not initialized.");
566 MatrixType res = m_lu.template triangularView<UnitLower>().toDenseMatrix()
567 * m_lu.template triangularView<Upper>();
570 res =
m_p.inverse() * res;
580template<
typename DstXprType,
typename MatrixType>
600template<
typename Derived>
615template<
typename Derived>
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Just a side note.
Definition: Macros.h:1274
#define EIGEN_NOEXCEPT
Definition: Macros.h:1428
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
Definition: Macros.h:1312
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Definition: StaticAssert.h:187
Expression of the inverse of another expression.
Definition: Inverse.h:44
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned & nestedExpression() const
Definition: Inverse.h:60
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Inverse.h:58
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Inverse.h:57
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
const PartialPivLU< PlainObject > partialPivLu() const
\lu_module
Definition: PartialPivLU.h:602
const PartialPivLU< PlainObject > lu() const
\lu_module
Definition: PartialPivLU.h:617
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
Convenience specialization of Stride to specify only an outer stride See class Map for some examples.
Definition: Stride.h:107
LU decomposition of a matrix with partial pivoting, and related features.
Definition: PartialPivLU.h:78
_MatrixType MatrixType
Definition: PartialPivLU.h:81
SolverBase< PartialPivLU > Base
Definition: PartialPivLU.h:82
const Inverse< PartialPivLU > inverse() const
Definition: PartialPivLU.h:196
RealScalar m_l1_norm
Definition: PartialPivLU.h:278
const PermutationType & permutationP() const
Definition: PartialPivLU.h:151
MatrixType m_lu
Definition: PartialPivLU.h:275
RealScalar rcond() const
Definition: PartialPivLU.h:183
PartialPivLU & compute(const EigenBase< InputType > &matrix)
Definition: PartialPivLU.h:131
Scalar determinant() const
Definition: PartialPivLU.h:552
static void check_template_parameters()
Definition: PartialPivLU.h:268
signed char m_det_p
Definition: PartialPivLU.h:279
PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime > PermutationType
Definition: PartialPivLU.h:90
PartialPivLU()
Default Constructor.
Definition: PartialPivLU.h:284
EIGEN_DEVICE_FUNC void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const
Definition: PartialPivLU.h:245
const MatrixType & matrixLU() const
Definition: PartialPivLU.h:143
void compute()
Definition: PartialPivLU.h:525
bool m_isInitialized
Definition: PartialPivLU.h:280
TranspositionType m_rowsTranspositions
Definition: PartialPivLU.h:277
MatrixType::PlainObject PlainObject
Definition: PartialPivLU.h:92
EIGEN_DEVICE_FUNC void _solve_impl(const RhsType &rhs, DstType &dst) const
Definition: PartialPivLU.h:225
MatrixType reconstructedMatrix() const
Definition: PartialPivLU.h:562
@ MaxRowsAtCompileTime
Definition: PartialPivLU.h:87
@ MaxColsAtCompileTime
Definition: PartialPivLU.h:88
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PartialPivLU.h:220
Transpositions< RowsAtCompileTime, MaxRowsAtCompileTime > TranspositionType
Definition: PartialPivLU.h:91
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PartialPivLU.h:219
PermutationType m_p
Definition: PartialPivLU.h:276
InverseReturnType transpose() const
Definition: PermutationMatrix.h:191
NumTraits< Scalar >::Real RealScalar
Definition: PlainObjectBase.h:109
static ConstMapType Map(const Scalar *data)
Definition: PlainObjectBase.h:644
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:283
Pseudo expression representing a solving operation.
Definition: Solve.h:63
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:69
internal::traits< PartialPivLU< _MatrixType > >::Scalar Scalar
Definition: SolverBase.h:73
const Solve< PartialPivLU< _MatrixType >, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:106
IndicesType::Scalar StorageIndex
Definition: Transpositions.h:162
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:319
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:321
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:66
constexpr common_t< T1, T2 > max(const T1 x, const T2 y) noexcept
Compile-time pairwise maximum function.
Definition: max.hpp:35
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
void partial_lu_inplace(MatrixType &lu, TranspositionType &row_transpositions, typename TranspositionType::StorageIndex &nb_transpositions)
Definition: PartialPivLU.h:505
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
Decomposition::RealScalar rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition &dec)
Reciprocal condition number estimator.
Definition: ConditionEstimator.h:159
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition: Constants.h:22
Definition: Eigen_Colamd.h:50
static constexpr const mass::kilogram_t m_p(1.672621898e-27)
proton mass.
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: EigenBase.h:67
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
The type used to identify a matrix expression.
Definition: Constants.h:522
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
The type used to identify a general solver (factored) storage.
Definition: Constants.h:513
Inverse< LuType > SrcXprType
Definition: PartialPivLU.h:584
PartialPivLU< MatrixType > LuType
Definition: PartialPivLU.h:583
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename LuType::Scalar > &)
Definition: PartialPivLU.h:585
Definition: AssignEvaluator.h:824
Definition: AssignEvaluator.h:814
Definition: AssignmentFunctors.h:21
Derived type
Definition: PartialPivLU.h:38
Definition: PartialPivLU.h:31
Definition: PartialPivLU.h:336
static const bool UnBlockedAtCompileTime
Definition: PartialPivLU.h:338
static const int ActualSizeAtCompileTime
Definition: PartialPivLU.h:339
Matrix< Scalar, ActualSizeAtCompileTime, ActualSizeAtCompileTime, StorageOrder > MatrixType
Definition: PartialPivLU.h:343
static Index blocked_lu(Index rows, Index cols, Scalar *lu_data, Index luStride, PivIndex *row_transpositions, PivIndex &nb_transpositions, Index maxBlockSize=256)
Definition: PartialPivLU.h:430
Ref< Matrix< Scalar, Dynamic, Dynamic, StorageOrder > > BlockType
Definition: PartialPivLU.h:345
static const int UnBlockedBound
Definition: PartialPivLU.h:337
Ref< MatrixType > MatrixTypeRef
Definition: PartialPivLU.h:344
static const int RCols
Definition: PartialPivLU.h:342
static Index unblocked_lu(MatrixTypeRef &lu, PivIndex *row_transpositions, PivIndex &nb_transpositions)
Definition: PartialPivLU.h:358
static const int RRows
Definition: PartialPivLU.h:341
MatrixType::RealScalar RealScalar
Definition: PartialPivLU.h:346
Definition: UnaryFunctors.h:64
int StorageIndex
Definition: PartialPivLU.h:22
SolverStorage StorageKind
Definition: PartialPivLU.h:21
MatrixXpr XprKind
Definition: PartialPivLU.h:20
traits< _MatrixType > BaseTraits
Definition: PartialPivLU.h:23
Definition: ForwardDeclarations.h:17