11 #ifndef EIGEN_PARTIALLU_H
12 #define EIGEN_PARTIALLU_H
19 template<
typename MatrixType_,
typename PermutationIndex_>
struct traits<PartialPivLU<MatrixType_, PermutationIndex_> >
22 typedef MatrixXpr XprKind;
23 typedef SolverStorage StorageKind;
24 typedef PermutationIndex_ StorageIndex;
25 typedef traits<MatrixType_> BaseTraits;
32 template<
typename T,
typename Derived>
38 template<
typename T,
typename Derived>
39 struct enable_if_ref<Ref<
T>,Derived> {
78 template<
typename MatrixType_,
typename PermutationIndex_>
class PartialPivLU
79 :
public SolverBase<PartialPivLU<MatrixType_, PermutationIndex_> >
120 template<
typename InputType>
130 template<
typename InputType>
133 template<
typename InputType>
160 #ifdef EIGEN_PARSED_BY_DOXYGEN
178 template<
typename Rhs>
225 #ifndef EIGEN_PARSED_BY_DOXYGEN
226 template<
typename RhsType,
typename DstType>
228 void _solve_impl(
const RhsType &rhs, DstType &dst)
const {
240 m_lu.template triangularView<UnitLower>().solveInPlace(dst);
243 m_lu.template triangularView<Upper>().solveInPlace(dst);
246 template<
bool Conjugate,
typename RhsType,
typename DstType>
248 void _solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const {
259 dst =
m_lu.template triangularView<Upper>().transpose()
260 .template conjugateIf<Conjugate>().solve(rhs);
262 m_lu.template triangularView<UnitLower>().transpose()
263 .template conjugateIf<Conjugate>().solveInPlace(dst);
283 template<
typename MatrixType,
typename PermutationIndex>
287 m_rowsTranspositions(),
290 m_isInitialized(false)
294 template<
typename MatrixType,
typename PermutationIndex>
298 m_rowsTranspositions(
size),
301 m_isInitialized(false)
305 template<
typename MatrixType,
typename PermutationIndex>
306 template<
typename InputType>
308 : m_lu(matrix.
rows(),matrix.
cols()),
310 m_rowsTranspositions(matrix.
rows()),
313 m_isInitialized(false)
318 template<
typename MatrixType,
typename PermutationIndex>
319 template<
typename InputType>
321 : m_lu(matrix.derived()),
323 m_rowsTranspositions(matrix.
rows()),
326 m_isInitialized(false)
334 template<
typename Scalar,
int StorageOrder,
typename PivIndex,
int SizeAtCompileTime=Dynamic>
335 struct partial_lu_impl
337 static constexpr
int UnBlockedBound = 16;
338 static constexpr
bool UnBlockedAtCompileTime = SizeAtCompileTime!=
Dynamic && SizeAtCompileTime<=UnBlockedBound;
339 static constexpr
int ActualSizeAtCompileTime = UnBlockedAtCompileTime ? SizeAtCompileTime :
Dynamic;
341 static constexpr
int RRows = SizeAtCompileTime==2 ? 1 :
Dynamic;
342 static constexpr
int RCols = SizeAtCompileTime==2 ? 1 :
Dynamic;
358 static Index unblocked_lu(MatrixTypeRef&
lu, PivIndex* row_transpositions, PivIndex& nb_transpositions)
360 typedef scalar_score_coeff_op<Scalar> Scoring;
361 typedef typename Scoring::result_type Score;
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);
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));
404 if(UnBlockedAtCompileTime)
407 row_transpositions[k] = PivIndex(k);
409 first_zero_pivot = k;
412 return first_zero_pivot;
430 static Index blocked_lu(
Index rows,
Index cols, Scalar* lu_data,
Index luStride, PivIndex* row_transpositions, PivIndex& nb_transpositions,
Index maxBlockSize=256)
437 if(UnBlockedAtCompileTime ||
size<=UnBlockedBound)
439 return unblocked_lu(
lu, row_transpositions, nb_transpositions);
447 blockSize = (blockSize/16)*16;
451 nb_transpositions = 0;
452 Index first_zero_pivot = -1;
463 BlockType A_0 =
lu.block(0,0,
rows,k);
464 BlockType A_2 =
lu.block(0,k+bs,
rows,tsize);
465 BlockType A11 =
lu.block(k,k,bs,bs);
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;
473 Index ret = blocked_lu(trows+bs, bs, &
lu.coeffRef(k,k), luStride,
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;
482 Index piv = (row_transpositions[
i] += internal::convert_index<PivIndex>(k));
483 A_0.row(
i).swap(A_0.row(piv));
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;
504 template<
typename MatrixType,
typename TranspositionType>
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);
524 template<
typename MatrixType,
typename PermutationIndex>
530 m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
532 m_l1_norm = RealScalar(0);
534 eigen_assert(m_lu.rows() == m_lu.cols() &&
"PartialPivLU is only for square (and moreover invertible) matrices");
537 m_rowsTranspositions.resize(
size);
541 m_det_p = (nb_transpositions%2) ? -1 : 1;
543 m_p = m_rowsTranspositions;
545 m_isInitialized =
true;
548 template<
typename MatrixType,
typename PermutationIndex>
551 eigen_assert(m_isInitialized &&
"PartialPivLU is not initialized.");
552 return Scalar(m_det_p) * m_lu.diagonal().prod();
558 template<
typename MatrixType,
typename PermutationIndex>
561 eigen_assert(m_isInitialized &&
"LU is not initialized.");
563 MatrixType res = m_lu.template triangularView<UnitLower>().toDenseMatrix()
564 * m_lu.template triangularView<Upper>();
567 res = m_p.inverse() *
res;
577 template<
typename DstXprType,
typename MatrixType,
typename PermutationIndex>
578 struct Assignment<DstXprType,
Inverse<
PartialPivLU<
MatrixType, PermutationIndex> >,
internal::assign_op<typename DstXprType::Scalar,typename PartialPivLU<MatrixType, PermutationIndex>::Scalar>, Dense2Dense>
582 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename LuType::Scalar> &)
584 dst = src.
nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
597 template<
typename Derived>
598 template<
typename PermutationIndex>
613 template<
typename Derived>
614 template<
typename PermutationIndex>
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
#define EIGEN_DEVICE_FUNC
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Matrix< float, 1, Dynamic > MatrixType
NumTraits< Scalar >::Real RealScalar
Expression of the inverse of another expression.
const XprTypeNestedCleaned & nestedExpression() const
Base class for all dense matrices, vectors, and expressions.
const PartialPivLU< PlainObject, PermutationIndex > lu() const
const PartialPivLU< PlainObject, PermutationIndex > partialPivLu() const
The matrix class, also used for vectors and row-vectors.
Base::PlainObject PlainObject
LU decomposition of a matrix with partial pivoting, and related features.
SolverBase< PartialPivLU > Base
TranspositionType m_rowsTranspositions
PartialPivLU & compute(const EigenBase< InputType > &matrix)
MatrixType::PlainObject PlainObject
const Solve< PartialPivLU, Rhs > solve(const MatrixBase< Rhs > &b) const
MatrixType reconstructedMatrix() const
const PermutationType & permutationP() const
PermutationIndex_ PermutationIndex
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
PartialPivLU()
Default Constructor.
Transpositions< RowsAtCompileTime, MaxRowsAtCompileTime, PermutationIndex > TranspositionType
const Inverse< PartialPivLU > inverse() const
const MatrixType & matrixLU() const
Scalar determinant() const
PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime, PermutationIndex > PermutationType
InverseReturnType transpose() const
static ConstMapType Map(const Scalar *data)
A matrix or vector expression mapping an existing expression.
Pseudo expression representing a solving operation.
A base class for matrix decomposition and solvers.
internal::traits< PartialPivLU< MatrixType_, PermutationIndex_ > >::Scalar Scalar
IndicesType::Scalar StorageIndex
cout<< "Here is the matrix m:"<< endl<< m<< endl;Eigen::FullPivLU< Matrix5x3 > lu(m)
const unsigned int RowMajorBit
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
void partial_lu_inplace(MatrixType &lu, TranspositionType &row_transpositions, typename TranspositionType::StorageIndex &nb_transpositions)
constexpr int min_size_prefer_fixed(A a, B b)
Decomposition::RealScalar rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition &dec)
Reciprocal condition number estimator.
bool is_exactly_zero(const X &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Eigen::Index Index
The interface type of indices.
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.