11 #ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_H 12 #define EIGEN_COLPIVOTINGHOUSEHOLDERQR_H 54 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
55 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
56 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
57 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
87 m_colsTranspositions(),
91 m_isInitialized(false),
92 m_usePrescribedThreshold(false) {}
102 m_hCoeffs((
std::
min)(rows,cols)),
103 m_colsPermutation(PermIndexType(cols)),
104 m_colsTranspositions(cols),
106 m_colNormsUpdated(cols),
107 m_colNormsDirect(cols),
108 m_isInitialized(false),
109 m_usePrescribedThreshold(false) {}
123 template<
typename InputType>
125 : m_qr(matrix.
rows(), matrix.
cols()),
127 m_colsPermutation(PermIndexType(matrix.
cols())),
128 m_colsTranspositions(matrix.
cols()),
129 m_temp(matrix.
cols()),
130 m_colNormsUpdated(matrix.
cols()),
131 m_colNormsDirect(matrix.
cols()),
132 m_isInitialized(false),
133 m_usePrescribedThreshold(false)
144 template<
typename InputType>
146 : m_qr(matrix.derived()),
148 m_colsPermutation(PermIndexType(matrix.
cols())),
149 m_colsTranspositions(matrix.
cols()),
150 m_temp(matrix.
cols()),
151 m_colNormsUpdated(matrix.
cols()),
152 m_colNormsDirect(matrix.
cols()),
153 m_isInitialized(false),
154 m_usePrescribedThreshold(false)
173 template<
typename Rhs>
177 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
181 HouseholderSequenceType householderQ()
const;
184 return householderQ();
191 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
206 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
210 template<
typename InputType>
216 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
217 return m_colsPermutation;
258 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
259 RealScalar premultiplied_threshold =
abs(m_maxpivot) * threshold();
261 for(
Index i = 0;
i < m_nonzero_pivots; ++
i)
262 result += (
abs(m_qr.coeff(
i,
i)) > premultiplied_threshold);
274 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
275 return cols() - rank();
287 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
288 return rank() ==
cols();
300 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
301 return rank() ==
rows();
312 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
313 return isInjective() && isSurjective();
323 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
334 const HCoeffsType&
hCoeffs()
const {
return m_hCoeffs; }
355 m_usePrescribedThreshold =
true;
356 m_prescribedThreshold = threshold;
370 m_usePrescribedThreshold =
false;
380 eigen_assert(m_isInitialized || m_usePrescribedThreshold);
381 return m_usePrescribedThreshold ? m_prescribedThreshold
396 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
397 return m_nonzero_pivots;
413 eigen_assert(m_isInitialized &&
"Decomposition is not initialized.");
417 #ifndef EIGEN_PARSED_BY_DOXYGEN 418 template<
typename RhsType,
typename DstType>
420 void _solve_impl(
const RhsType &rhs, DstType &dst)
const;
432 void computeInPlace();
447 template<
typename MatrixType>
451 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
452 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
453 return abs(m_qr.diagonal().prod());
456 template<
typename MatrixType>
459 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
460 eigen_assert(m_qr.rows() == m_qr.cols() &&
"You can't take the determinant of a non-square matrix!");
461 return m_qr.diagonal().cwiseAbs().array().log().sum();
470 template<
typename MatrixType>
471 template<
typename InputType>
479 template<
typename MatrixType>
482 check_template_parameters();
493 m_hCoeffs.resize(size);
497 m_colsTranspositions.resize(m_qr.cols());
498 Index number_of_transpositions = 0;
500 m_colNormsUpdated.resize(cols);
501 m_colNormsDirect.resize(cols);
505 m_colNormsDirect.coeffRef(k) = m_qr.col(k).norm();
506 m_colNormsUpdated.coeffRef(k) = m_colNormsDirect.coeffRef(k);
512 m_nonzero_pivots =
size;
518 Index biggest_col_index;
519 RealScalar biggest_col_sq_norm =
numext::abs2(m_colNormsUpdated.tail(cols-k).maxCoeff(&biggest_col_index));
520 biggest_col_index += k;
524 if(m_nonzero_pivots==size && biggest_col_sq_norm < threshold_helper *
RealScalar(rows-k))
525 m_nonzero_pivots = k;
528 m_colsTranspositions.coeffRef(k) = biggest_col_index;
529 if(k != biggest_col_index) {
530 m_qr.col(k).swap(m_qr.col(biggest_col_index));
531 std::swap(m_colNormsUpdated.coeffRef(k), m_colNormsUpdated.coeffRef(biggest_col_index));
532 std::swap(m_colNormsDirect.coeffRef(k), m_colNormsDirect.coeffRef(biggest_col_index));
533 ++number_of_transpositions;
538 m_qr.col(k).tail(rows-k).makeHouseholderInPlace(m_hCoeffs.coeffRef(k), beta);
541 m_qr.coeffRef(k,k) = beta;
544 if(
abs(beta) > m_maxpivot) m_maxpivot =
abs(beta);
547 m_qr.bottomRightCorner(rows-k, cols-k-1)
548 .applyHouseholderOnTheLeft(m_qr.col(k).tail(rows-k-1), m_hCoeffs.coeffRef(k), &m_temp.coeffRef(k+1));
556 if (m_colNormsUpdated.coeffRef(
j) !=
RealScalar(0)) {
557 RealScalar temp =
abs(m_qr.coeffRef(k,
j)) / m_colNormsUpdated.coeffRef(
j);
560 RealScalar temp2 = temp * numext::abs2<RealScalar>(m_colNormsUpdated.coeffRef(
j) /
561 m_colNormsDirect.coeffRef(
j));
562 if (temp2 <= norm_downdate_threshold) {
565 m_colNormsDirect.coeffRef(
j) = m_qr.col(
j).tail(rows - k - 1).norm();
566 m_colNormsUpdated.coeffRef(
j) = m_colNormsDirect.coeffRef(
j);
576 m_colsPermutation.applyTranspositionOnTheRight(k,
PermIndexType(m_colsTranspositions.coeff(k)));
578 m_det_pq = (number_of_transpositions%2) ? -1 : 1;
579 m_isInitialized =
true;
582 #ifndef EIGEN_PARSED_BY_DOXYGEN 583 template<
typename _MatrixType>
584 template<
typename RhsType,
typename DstType>
589 const Index nonzero_pivots = nonzeroPivots();
591 if(nonzero_pivots == 0)
597 typename RhsType::PlainObject
c(rhs);
601 .setLength(nonzero_pivots)
605 m_qr.topLeftCorner(nonzero_pivots, nonzero_pivots)
606 .template triangularView<Upper>()
607 .solveInPlace(c.topRows(nonzero_pivots));
609 for(
Index i = 0;
i < nonzero_pivots; ++
i) dst.row(m_colsPermutation.indices().coeff(
i)) = c.row(
i);
610 for(
Index i = nonzero_pivots;
i <
cols(); ++
i) dst.row(m_colsPermutation.indices().coeff(
i)).
setZero();
616 template<
typename DstXprType,
typename MatrixType>
632 template<
typename MatrixType>
636 eigen_assert(m_isInitialized &&
"ColPivHouseholderQR is not initialized.");
644 template<
typename Derived>
653 #endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_H PermutationMatrix< ColsAtCompileTime, MaxColsAtCompileTime > PermutationType
Inverse< QrType > SrcXprType
const PermutationType & colsPermutation() const
ColPivHouseholderQR(EigenBase< InputType > &matrix)
Constructs a QR factorization from a given matrix.
Index nonzeroPivots() const
const Inverse< ColPivHouseholderQR > inverse() const
EIGEN_DEVICE_FUNC Index rows() const
ColPivHouseholderQR()
Default Constructor.
ColPivHouseholderQR(Index rows, Index cols)
Default Constructor with memory preallocation.
RealScalar m_prescribedThreshold
EIGEN_DEVICE_FUNC void _solve_impl(const RhsType &rhs, DstType &dst) const
const Solve< ColPivHouseholderQR, Rhs > solve(const MatrixBase< Rhs > &b) const
MatrixType::RealScalar logAbsDeterminant() const
MatrixType::StorageIndex StorageIndex
PermutationType::StorageIndex PermIndexType
bool isInvertible() const
internal::plain_diag_type< MatrixType >::type HCoeffsType
HouseholderSequence< MatrixType, typename internal::remove_all< typename HCoeffsType::ConjugateReturnType >::type > HouseholderSequenceType
Namespace containing all symbols from the Eigen library.
PermutationType m_colsPermutation
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Complete orthogonal decomposition (COD) of a matrix.
RealRowVectorType m_colNormsUpdated
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
ComputationInfo info() const
Reports whether the QR factorization was succesful.
Sequence of Householder reflections acting on subspaces with decreasing size.
ColPivHouseholderQR(const EigenBase< InputType > &matrix)
Constructs a QR factorization from a given matrix.
Expression of the inverse of another expression.
ColPivHouseholderQR & compute(const EigenBase< InputType > &matrix)
ColPivHouseholderQR & setThreshold(Default_t)
RealScalar threshold() const
internal::plain_row_type< MatrixType >::type RowVectorType
const MatrixType & matrixR() const
Householder rank-revealing QR decomposition of a matrix with column-pivoting.
const MatrixType & matrixQR() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
HouseholderSequenceType householderQ() const
MatrixType::Scalar Scalar
EIGEN_DEVICE_FUNC Index cols() const
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename QrType::Scalar > &)
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
const HCoeffsType & hCoeffs() const
bool m_usePrescribedThreshold
NumTraits< Scalar >::Real RealScalar
const ColPivHouseholderQR< PlainObject > colPivHouseholderQr() const
MatrixType::PlainObject PlainObject
internal::plain_row_type< MatrixType, RealScalar >::type RealRowVectorType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
RealRowVectorType m_colNormsDirect
ColPivHouseholderQR & setThreshold(const RealScalar &threshold)
ColPivHouseholderQR< MatrixType > QrType
RealScalar maxPivot() const
MatrixType::RealScalar absDeterminant() const
bool isSurjective() const
HouseholderSequenceType matrixQ() const
static void check_template_parameters()
internal::plain_row_type< MatrixType, Index >::type IntRowVectorType
Traits::StorageIndex StorageIndex
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Pseudo expression representing a solving operation.
IntRowVectorType m_colsTranspositions
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sqrt(const float &x)
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned & nestedExpression() const
EIGEN_DEVICE_FUNC Derived & derived()
Base class for all dense matrices, vectors, and expressions.
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Index dimensionOfKernel() const
MatrixType::RealScalar RealScalar