10 #ifndef EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H 11 #define EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H 16 template <
typename _MatrixType>
17 struct traits<CompleteOrthogonalDecomposition<_MatrixType> >
18 : traits<_MatrixType> {
46 template <
typename _MatrixType>
47 class CompleteOrthogonalDecomposition {
49 typedef _MatrixType MatrixType;
51 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
52 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
53 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
54 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
56 typedef typename MatrixType::Scalar Scalar;
57 typedef typename MatrixType::RealScalar RealScalar;
58 typedef typename MatrixType::StorageIndex StorageIndex;
59 typedef typename internal::plain_diag_type<MatrixType>::type HCoeffsType;
60 typedef PermutationMatrix<ColsAtCompileTime, MaxColsAtCompileTime>
62 typedef typename internal::plain_row_type<MatrixType, Index>::type
64 typedef typename internal::plain_row_type<MatrixType>::type RowVectorType;
65 typedef typename internal::plain_row_type<MatrixType, RealScalar>::type
67 typedef HouseholderSequence<
68 MatrixType,
typename internal::remove_all<
69 typename HCoeffsType::ConjugateReturnType>::type>
70 HouseholderSequenceType;
71 typedef typename MatrixType::PlainObject PlainObject;
74 typedef typename PermutationType::Index PermIndexType;
93 : m_cpqr(rows, cols), m_zCoeffs((
std::min)(rows, cols)), m_temp(cols) {}
111 template <
typename InputType>
113 : m_cpqr(matrix.rows(), matrix.cols()),
114 m_zCoeffs((
std::min)(matrix.rows(), matrix.cols())),
115 m_temp(matrix.cols())
126 template<
typename InputType>
128 : m_cpqr(matrix.derived()),
129 m_zCoeffs((
std::min)(matrix.rows(), matrix.cols())),
130 m_temp(matrix.cols())
145 template <
typename Rhs>
148 eigen_assert(m_cpqr.m_isInitialized &&
149 "CompleteOrthogonalDecomposition is not initialized.");
153 HouseholderSequenceType householderQ(
void)
const;
154 HouseholderSequenceType matrixQ(
void)
const {
return m_cpqr.householderQ(); }
159 MatrixType Z = MatrixType::Identity(m_cpqr.cols(), m_cpqr.cols());
160 applyZAdjointOnTheLeftInPlace(Z);
167 const MatrixType&
matrixQTZ()
const {
return m_cpqr.matrixQR(); }
180 const MatrixType&
matrixT()
const {
return m_cpqr.matrixQR(); }
182 template <
typename InputType>
185 m_cpqr.compute(matrix);
192 return m_cpqr.colsPermutation();
208 typename MatrixType::RealScalar absDeterminant()
const;
223 typename MatrixType::RealScalar logAbsDeterminant()
const;
280 inline Index rows()
const {
return m_cpqr.rows(); }
281 inline Index cols()
const {
return m_cpqr.cols(); }
288 inline const HCoeffsType&
hCoeffs()
const {
return m_cpqr.hCoeffs(); }
295 const HCoeffsType&
zCoeffs()
const {
return m_zCoeffs; }
338 RealScalar
threshold()
const {
return m_cpqr.threshold(); }
352 inline RealScalar
maxPivot()
const {
return m_cpqr.maxPivot(); }
363 eigen_assert(m_cpqr.m_isInitialized &&
"Decomposition is not initialized.");
367 #ifndef EIGEN_PARSED_BY_DOXYGEN 368 template <
typename RhsType,
typename DstType>
369 EIGEN_DEVICE_FUNC
void _solve_impl(
const RhsType& rhs, DstType& dst)
const;
373 static void check_template_parameters() {
374 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
377 void computeInPlace();
381 template <
typename Rhs>
382 void applyZAdjointOnTheLeftInPlace(Rhs& rhs)
const;
385 HCoeffsType m_zCoeffs;
386 RowVectorType m_temp;
389 template <
typename MatrixType>
390 typename MatrixType::RealScalar
392 return m_cpqr.absDeterminant();
395 template <
typename MatrixType>
396 typename MatrixType::RealScalar
398 return m_cpqr.logAbsDeterminant();
408 template <
typename MatrixType>
411 check_template_parameters();
416 const Index rank = m_cpqr.rank();
417 const Index cols = m_cpqr.cols();
418 const Index rows = m_cpqr.rows();
419 m_zCoeffs.resize((std::min)(rows, cols));
434 for (
Index k = rank - 1; k >= 0; --k) {
439 m_cpqr.m_qr.col(k).head(k + 1).swap(
440 m_cpqr.m_qr.col(rank - 1).head(k + 1));
447 .tail(cols - rank + 1)
448 .makeHouseholderInPlace(m_zCoeffs(k), beta);
449 m_cpqr.m_qr(k, rank - 1) = beta;
452 m_cpqr.m_qr.topRightCorner(k, cols - rank + 1)
453 .applyHouseholderOnTheRight(
454 m_cpqr.m_qr.row(k).tail(cols - rank).transpose(), m_zCoeffs(k),
459 m_cpqr.m_qr.col(k).head(k + 1).swap(
460 m_cpqr.m_qr.col(rank - 1).head(k + 1));
466 template <
typename MatrixType>
467 template <
typename Rhs>
470 const Index cols = this->cols();
471 const Index nrhs = rhs.cols();
472 const Index rank = this->rank();
474 for (
Index k = 0; k < rank; ++k) {
476 rhs.row(k).swap(rhs.row(rank - 1));
478 rhs.middleRows(rank - 1, cols - rank + 1)
479 .applyHouseholderOnTheLeft(
480 matrixQTZ().row(k).tail(cols - rank).adjoint(), zCoeffs()(k),
483 rhs.row(k).swap(rhs.row(rank - 1));
488 #ifndef EIGEN_PARSED_BY_DOXYGEN 489 template <
typename _MatrixType>
490 template <
typename RhsType,
typename DstType>
492 const RhsType& rhs, DstType& dst)
const {
493 eigen_assert(rhs.rows() == this->rows());
495 const Index rank = this->rank();
504 typename RhsType::PlainObject c(rhs);
509 dst.topRows(rank) = matrixT()
510 .topLeftCorner(rank, rank)
511 .template triangularView<Upper>()
512 .solve(c.topRows(rank));
514 const Index cols = this->cols();
518 dst.bottomRows(cols - rank).setZero();
519 applyZAdjointOnTheLeftInPlace(dst);
523 dst = colsPermutation() * dst;
529 template<
typename DstXprType,
typename MatrixType>
530 struct Assignment<DstXprType, Inverse<CompleteOrthogonalDecomposition<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename CompleteOrthogonalDecomposition<MatrixType>::Scalar>, Dense2Dense>
534 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename CodType::Scalar> &)
536 dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.rows()));
543 template <
typename MatrixType>
546 return m_cpqr.householderQ();
554 template <
typename Derived>
563 #endif // EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H const MatrixType & matrixT() const
Definition: CompleteOrthogonalDecomposition.h:180
CompleteOrthogonalDecomposition()
Default Constructor.
Definition: CompleteOrthogonalDecomposition.h:84
const CompleteOrthogonalDecomposition< PlainObject > completeOrthogonalDecomposition() const
Definition: CompleteOrthogonalDecomposition.h:556
Index rank() const
Definition: CompleteOrthogonalDecomposition.h:232
MatrixType matrixZ() const
Definition: CompleteOrthogonalDecomposition.h:158
const Solve< CompleteOrthogonalDecomposition, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: CompleteOrthogonalDecomposition.h:146
CompleteOrthogonalDecomposition(EigenBase< InputType > &matrix)
Constructs a complete orthogonal decomposition from a given matrix.
Definition: CompleteOrthogonalDecomposition.h:127
Namespace containing all symbols from the Eigen library.
Definition: Core:271
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:167
MatrixType::RealScalar logAbsDeterminant() const
Definition: CompleteOrthogonalDecomposition.h:397
bool isSurjective() const
Definition: CompleteOrthogonalDecomposition.h:259
Derived & derived()
Definition: EigenBase.h:44
bool isInvertible() const
Definition: CompleteOrthogonalDecomposition.h:268
Complete orthogonal decomposition (COD) of a matrix.
Definition: ForwardDeclarations.h:257
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition: HouseholderSequence.h:451
Definition: EigenBase.h:28
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition: ForwardDeclarations.h:262
CompleteOrthogonalDecomposition & setThreshold(const RealScalar &threshold)
Definition: CompleteOrthogonalDecomposition.h:316
const PermutationType & colsPermutation() const
Definition: CompleteOrthogonalDecomposition.h:191
Expression of the inverse of another expression.
Definition: Inverse.h:43
RealScalar threshold() const
Definition: CompleteOrthogonalDecomposition.h:338
const MatrixType & matrixQTZ() const
Definition: CompleteOrthogonalDecomposition.h:167
CompleteOrthogonalDecomposition(const EigenBase< InputType > &matrix)
Constructs a complete orthogonal decomposition from a given matrix.
Definition: CompleteOrthogonalDecomposition.h:112
void computeInPlace()
Definition: CompleteOrthogonalDecomposition.h:409
void applyZAdjointOnTheLeftInPlace(Rhs &rhs) const
Definition: CompleteOrthogonalDecomposition.h:468
Index dimensionOfKernel() const
Definition: CompleteOrthogonalDecomposition.h:241
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
const HCoeffsType & hCoeffs() const
Definition: CompleteOrthogonalDecomposition.h:288
HouseholderSequenceType householderQ(void) const
Definition: CompleteOrthogonalDecomposition.h:545
Definition: Constants.h:432
Index nonzeroPivots() const
Definition: CompleteOrthogonalDecomposition.h:347
MatrixType::RealScalar absDeterminant() const
Definition: CompleteOrthogonalDecomposition.h:391
Definition: Eigen_Colamd.h:50
const HCoeffsType & zCoeffs() const
Definition: CompleteOrthogonalDecomposition.h:295
RealScalar maxPivot() const
Definition: CompleteOrthogonalDecomposition.h:352
CompleteOrthogonalDecomposition(Index rows, Index cols)
Default Constructor with memory preallocation.
Definition: CompleteOrthogonalDecomposition.h:92
Pseudo expression representing a solving operation.
Definition: Solve.h:62
CompleteOrthogonalDecomposition & setThreshold(Default_t)
Definition: CompleteOrthogonalDecomposition.h:329
const Inverse< CompleteOrthogonalDecomposition > pseudoInverse() const
Definition: CompleteOrthogonalDecomposition.h:275
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
ComputationInfo
Definition: Constants.h:430
ComputationInfo info() const
Reports whether the complete orthogonal decomposition was succesful.
Definition: CompleteOrthogonalDecomposition.h:362
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
bool isInjective() const
Definition: CompleteOrthogonalDecomposition.h:250