11 #ifndef EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H
12 #define EIGEN_FULLPIVOTINGHOUSEHOLDERQR_H
20 template<
typename MatrixType_,
typename PermutationIndex_>
struct traits<FullPivHouseholderQR<MatrixType_, PermutationIndex_> >
23 typedef MatrixXpr XprKind;
24 typedef SolverStorage StorageKind;
25 typedef PermutationIndex_ PermutationIndex;
29 template<
typename MatrixType,
typename PermutationIndex>
struct FullPivHouseholderQRMatrixQReturnType;
31 template<
typename MatrixType,
typename PermutationIndex>
32 struct traits<FullPivHouseholderQRMatrixQReturnType<
MatrixType, PermutationIndex> >
63 :
public SolverBase<FullPivHouseholderQR<MatrixType_, PermutationIndex_> >
77 typedef internal::FullPivHouseholderQRMatrixQReturnType<MatrixType, PermutationIndex>
MatrixQReturnType;
78 typedef typename internal::plain_diag_type<MatrixType>::type
HCoeffsType;
83 typedef typename internal::plain_row_type<MatrixType>::type
RowVectorType;
84 typedef typename internal::plain_col_type<MatrixType>::type
ColVectorType;
130 template<
typename InputType>
150 template<
typename InputType>
164 #ifdef EIGEN_PARSED_BY_DOXYGEN
180 template<
typename Rhs>
197 template<
typename InputType>
271 result += (
abs(
m_qr.coeff(
i,
i)) > premultiplied_threshold);
414 #ifndef EIGEN_PARSED_BY_DOXYGEN
415 template<
typename RhsType,
typename DstType>
416 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
418 template<
bool Conjugate,
typename RhsType,
typename DstType>
419 void _solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const;
441 template<
typename MatrixType,
typename PermutationIndex>
444 eigen_assert(m_isInitialized &&
"HouseholderQR is not initialized.");
445 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
447 internal::householder_determinant<HCoeffsType, Scalar, NumTraits<Scalar>::IsComplex>::run(m_hCoeffs, detQ);
448 return m_qr.diagonal().prod() * detQ *
Scalar(m_det_p);
451 template<
typename MatrixType,
typename PermutationIndex>
455 eigen_assert(m_isInitialized &&
"FullPivHouseholderQR is not initialized.");
456 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
457 return abs(m_qr.diagonal().prod());
460 template<
typename MatrixType,
typename PermutationIndex>
463 eigen_assert(m_isInitialized &&
"FullPivHouseholderQR is not initialized.");
464 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
465 return m_qr.diagonal().cwiseAbs().array().log().sum();
474 template<
typename MatrixType,
typename PermutationIndex>
475 template<
typename InputType>
483 template<
typename MatrixType,
typename PermutationIndex>
493 m_hCoeffs.resize(
size);
499 m_rows_transpositions.resize(
size);
500 m_cols_transpositions.resize(
size);
501 Index number_of_transpositions = 0;
503 RealScalar biggest(0);
505 m_nonzero_pivots =
size;
506 m_maxpivot = RealScalar(0);
510 Index row_of_biggest_in_corner, col_of_biggest_in_corner;
511 typedef internal::scalar_score_coeff_op<Scalar> Scoring;
512 typedef typename Scoring::result_type Score;
514 Score score = m_qr.bottomRightCorner(
rows-k,
cols-k)
515 .unaryExpr(Scoring())
516 .maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
517 row_of_biggest_in_corner += k;
518 col_of_biggest_in_corner += k;
519 RealScalar biggest_in_corner = internal::abs_knowing_score<Scalar>()(m_qr(row_of_biggest_in_corner, col_of_biggest_in_corner), score);
520 if(k==0) biggest = biggest_in_corner;
525 m_nonzero_pivots = k;
528 m_rows_transpositions.coeffRef(
i) = internal::convert_index<PermutationIndex>(
i);
529 m_cols_transpositions.coeffRef(
i) = internal::convert_index<PermutationIndex>(
i);
530 m_hCoeffs.coeffRef(
i) =
Scalar(0);
535 m_rows_transpositions.coeffRef(k) = internal::convert_index<PermutationIndex>(row_of_biggest_in_corner);
536 m_cols_transpositions.coeffRef(k) = internal::convert_index<PermutationIndex>(col_of_biggest_in_corner);
537 if(k != row_of_biggest_in_corner) {
538 m_qr.row(k).tail(
cols-k).swap(m_qr.row(row_of_biggest_in_corner).tail(
cols-k));
539 ++number_of_transpositions;
541 if(k != col_of_biggest_in_corner) {
542 m_qr.col(k).swap(m_qr.col(col_of_biggest_in_corner));
543 ++number_of_transpositions;
547 m_qr.col(k).tail(
rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta);
548 m_qr.coeffRef(k,k) = beta;
551 if(
abs(beta) > m_maxpivot) m_maxpivot =
abs(beta);
553 m_qr.bottomRightCorner(
rows-k,
cols-k-1)
554 .applyHouseholderOnTheLeft(m_qr.col(k).tail(
rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1));
557 m_cols_permutation.setIdentity(
cols);
559 m_cols_permutation.applyTranspositionOnTheRight(k, m_cols_transpositions.coeff(k));
561 m_det_p = (number_of_transpositions%2) ? -1 : 1;
562 m_isInitialized =
true;
565 #ifndef EIGEN_PARSED_BY_DOXYGEN
566 template<
typename MatrixType_,
typename PermutationIndex_>
567 template<
typename RhsType,
typename DstType>
570 const Index l_rank = rank();
580 typename RhsType::PlainObject
c(rhs);
582 Matrix<typename RhsType::Scalar,1,RhsType::ColsAtCompileTime> temp(rhs.cols());
583 for (
Index k = 0; k < l_rank; ++k)
586 c.row(k).
swap(
c.row(m_rows_transpositions.coeff(k)));
587 c.bottomRightCorner(remainingSize, rhs.cols())
588 .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingSize-1),
589 m_hCoeffs.coeff(k), &temp.coeffRef(0));
592 m_qr.topLeftCorner(l_rank, l_rank)
593 .template triangularView<Upper>()
594 .solveInPlace(
c.topRows(l_rank));
596 for(
Index i = 0;
i < l_rank; ++
i) dst.row(m_cols_permutation.indices().coeff(
i)) =
c.row(
i);
597 for(
Index i = l_rank;
i <
cols(); ++
i) dst.row(m_cols_permutation.indices().coeff(
i)).
setZero();
600 template<
typename MatrixType_,
typename PermutationIndex_>
601 template<
bool Conjugate,
typename RhsType,
typename DstType>
602 void FullPivHouseholderQR<MatrixType_, PermutationIndex_>::_solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const
604 const Index l_rank = rank();
612 typename RhsType::PlainObject
c(m_cols_permutation.transpose()*rhs);
614 m_qr.topLeftCorner(l_rank, l_rank)
615 .template triangularView<Upper>()
616 .transpose().template conjugateIf<Conjugate>()
617 .solveInPlace(
c.topRows(l_rank));
619 dst.topRows(l_rank) =
c.topRows(l_rank);
622 Matrix<Scalar, 1, DstType::ColsAtCompileTime> temp(dst.cols());
628 dst.bottomRightCorner(remainingSize, dst.cols())
629 .applyHouseholderOnTheLeft(m_qr.col(k).tail(remainingSize-1).template conjugateIf<!Conjugate>(),
630 m_hCoeffs.template conjugateIf<Conjugate>().coeff(k), &temp.coeffRef(0));
632 dst.row(k).swap(dst.row(m_rows_transpositions.coeff(k)));
639 template<
typename DstXprType,
typename MatrixType,
typename PermutationIndex>
640 struct Assignment<DstXprType, Inverse<FullPivHouseholderQR<
MatrixType, PermutationIndex> >,
internal::assign_op<typename DstXprType::Scalar,typename FullPivHouseholderQR<MatrixType, PermutationIndex>::Scalar>, Dense2Dense>
642 typedef FullPivHouseholderQR<MatrixType, PermutationIndex> QrType;
643 typedef Inverse<QrType> SrcXprType;
644 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename QrType::Scalar> &)
646 dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
656 template<
typename MatrixType,
typename PermutationIndex>
struct FullPivHouseholderQRMatrixQReturnType
657 :
public ReturnByValue<FullPivHouseholderQRMatrixQReturnType<MatrixType, PermutationIndex> >
661 typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
663 MatrixType::MaxRowsAtCompileTime> WorkVectorType;
665 FullPivHouseholderQRMatrixQReturnType(
const MatrixType&
qr,
666 const HCoeffsType& hCoeffs,
667 const IntDiagSizeVectorType& rowsTranspositions)
670 m_rowsTranspositions(rowsTranspositions)
673 template <
typename ResultType>
674 void evalTo(ResultType& result)
const
677 WorkVectorType workspace(
rows);
678 evalTo(result, workspace);
681 template <
typename ResultType>
682 void evalTo(ResultType& result, WorkVectorType& workspace)
const
691 workspace.resize(
rows);
696 .applyHouseholderOnTheLeft(m_qr.col(k).tail(
rows-k-1),
conj(m_hCoeffs.coeff(k)), &workspace.coeffRef(k));
697 result.row(k).swap(result.row(m_rowsTranspositions.coeff(k)));
701 Index rows()
const {
return m_qr.rows(); }
702 Index cols()
const {
return m_qr.rows(); }
705 typename MatrixType::Nested m_qr;
706 typename HCoeffsType::Nested m_hCoeffs;
707 typename IntDiagSizeVectorType::Nested m_rowsTranspositions;
717 template<
typename MatrixType,
typename PermutationIndex>
720 eigen_assert(m_isInitialized &&
"FullPivHouseholderQR is not initialized.");
728 template<
typename Derived>
729 template<
typename PermutationIndex>
const AbsReturnType abs() const
HouseholderQR< MatrixXf > qr(A)
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Matrix< float, 1, Dynamic > MatrixType
NumTraits< Scalar >::Real RealScalar
internal::traits< Derived >::Scalar Scalar
void swap(const DenseBase< OtherDerived > &other)
Householder rank-revealing QR decomposition of a matrix with full pivoting.
IntDiagSizeVectorType m_rows_transpositions
const MatrixType & matrixQR() const
const IntDiagSizeVectorType & rowsTranspositions() const
FullPivHouseholderQR & compute(const EigenBase< InputType > &matrix)
Index dimensionOfKernel() const
const PermutationType & colsPermutation() const
internal::plain_col_type< MatrixType >::type ColVectorType
IntDiagSizeVectorType m_cols_transpositions
MatrixQReturnType matrixQ(void) const
RealScalar m_prescribedThreshold
const HCoeffsType & hCoeffs() const
bool isInvertible() const
MatrixType::RealScalar logAbsDeterminant() const
PermutationMatrix< ColsAtCompileTime, MaxColsAtCompileTime, PermutationIndex > PermutationType
bool m_usePrescribedThreshold
internal::plain_diag_type< MatrixType >::type HCoeffsType
Matrix< PermutationIndex, 1, internal::min_size_prefer_dynamic(ColsAtCompileTime, RowsAtCompileTime), RowMajor, 1, internal::min_size_prefer_fixed(MaxColsAtCompileTime, MaxRowsAtCompileTime)> IntDiagSizeVectorType
bool isSurjective() const
internal::FullPivHouseholderQRMatrixQReturnType< MatrixType, PermutationIndex > MatrixQReturnType
RealScalar maxPivot() const
MatrixType::Scalar determinant() const
FullPivHouseholderQR()
Default Constructor.
MatrixType::PlainObject PlainObject
PermutationType m_cols_permutation
MatrixType::RealScalar absDeterminant() const
FullPivHouseholderQR(Index rows, Index cols)
Default Constructor with memory preallocation.
const Inverse< FullPivHouseholderQR > inverse() const
const Solve< FullPivHouseholderQR, Rhs > solve(const MatrixBase< Rhs > &b) const
FullPivHouseholderQR(const EigenBase< InputType > &matrix)
Constructs a QR factorization from a given matrix.
SolverBase< FullPivHouseholderQR > Base
FullPivHouseholderQR & setThreshold(const RealScalar &threshold)
FullPivHouseholderQR(EigenBase< InputType > &matrix)
Constructs a QR factorization from a given matrix.
internal::plain_row_type< MatrixType >::type RowVectorType
FullPivHouseholderQR & setThreshold(Default_t)
PermutationIndex_ PermutationIndex
Index nonzeroPivots() const
RealScalar threshold() const
Expression of the inverse of another expression.
Base class for all dense matrices, vectors, and expressions.
const FullPivHouseholderQR< PlainObject, PermutationIndex > fullPivHouseholderQr() const
The matrix class, also used for vectors and row-vectors.
Base::PlainObject PlainObject
Derived & setZero(Index size)
void evalTo(Dest &dst) const
Pseudo expression representing a solving operation.
A base class for matrix decomposition and solvers.
internal::traits< FullPivHouseholderQR< MatrixType_, PermutationIndex_ > >::Scalar Scalar
FullPivHouseholderQR< MatrixType_, PermutationIndex_ > & derived()
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
constexpr int min_size_prefer_fixed(A a, B b)
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
constexpr int min_size_prefer_dynamic(A a, B b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
Eigen::Index Index
The interface type of indices.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.