10 #ifndef EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H
11 #define EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H
16 template <
typename _MatrixType>
21 typedef int StorageIndex;
51 :
public SolverBase<CompleteOrthogonalDecomposition<_MatrixType> >
54 typedef _MatrixType MatrixType;
57 template<
typename Derived>
62 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
63 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
75 typename HCoeffsType::ConjugateReturnType>::type>
77 typedef typename MatrixType::PlainObject PlainObject;
99 : m_cpqr(rows, cols), m_zCoeffs((std::min)(rows, cols)), m_temp(cols) {}
117 template <
typename InputType>
119 : m_cpqr(matrix.rows(), matrix.cols()),
120 m_zCoeffs((std::min)(matrix.rows(), matrix.cols())),
121 m_temp(matrix.cols())
132 template<
typename InputType>
134 : m_cpqr(matrix.derived()),
135 m_zCoeffs((std::min)(matrix.rows(), matrix.cols())),
136 m_temp(matrix.cols())
141 #ifdef EIGEN_PARSED_BY_DOXYGEN
151 template <
typename Rhs>
157 HouseholderSequenceType matrixQ(
void)
const {
return m_cpqr.
householderQ(); }
162 MatrixType Z = MatrixType::Identity(m_cpqr.cols(), m_cpqr.cols());
163 applyZOnTheLeftInPlace<false>(Z);
185 template <
typename InputType>
188 m_cpqr.compute(matrix);
280 eigen_assert(m_cpqr.m_isInitialized &&
"CompleteOrthogonalDecomposition is not initialized.");
284 inline Index rows()
const {
return m_cpqr.rows(); }
285 inline Index cols()
const {
return m_cpqr.cols(); }
367 eigen_assert(m_cpqr.m_isInitialized &&
"Decomposition is not initialized.");
371 #ifndef EIGEN_PARSED_BY_DOXYGEN
372 template <
typename RhsType,
typename DstType>
373 void _solve_impl(
const RhsType& rhs, DstType& dst)
const;
375 template<
bool Conjugate,
typename RhsType,
typename DstType>
376 void _solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const;
380 static void check_template_parameters() {
381 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
384 template<
bool Transpose_,
typename Rhs>
385 void _check_solve_assertion(
const Rhs& b)
const {
386 EIGEN_ONLY_USED_FOR_DEBUG(b);
387 eigen_assert(m_cpqr.m_isInitialized &&
"CompleteOrthogonalDecomposition is not initialized.");
388 eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() &&
"CompleteOrthogonalDecomposition::solve(): invalid number of rows of the right hand side matrix b");
397 template <
bool Conjugate,
typename Rhs>
402 template <
typename Rhs>
405 ColPivHouseholderQR<MatrixType> m_cpqr;
406 HCoeffsType m_zCoeffs;
407 RowVectorType m_temp;
410 template <
typename MatrixType>
411 typename MatrixType::RealScalar
413 return m_cpqr.absDeterminant();
416 template <
typename MatrixType>
417 typename MatrixType::RealScalar
419 return m_cpqr.logAbsDeterminant();
429 template <
typename MatrixType>
432 check_template_parameters();
437 const Index rank = m_cpqr.rank();
438 const Index cols = m_cpqr.cols();
439 const Index rows = m_cpqr.rows();
440 m_zCoeffs.resize((std::min)(rows, cols));
455 for (
Index k = rank - 1; k >= 0; --k) {
460 m_cpqr.m_qr.col(k).head(k + 1).swap(
461 m_cpqr.m_qr.col(rank - 1).head(k + 1));
468 .tail(cols - rank + 1)
469 .makeHouseholderInPlace(m_zCoeffs(k), beta);
470 m_cpqr.m_qr(k, rank - 1) = beta;
473 m_cpqr.m_qr.topRightCorner(k, cols - rank + 1)
474 .applyHouseholderOnTheRight(
475 m_cpqr.m_qr.row(k).tail(cols - rank).adjoint(), m_zCoeffs(k),
480 m_cpqr.m_qr.col(k).head(k + 1).swap(
481 m_cpqr.m_qr.col(rank - 1).head(k + 1));
487 template <
typename MatrixType>
488 template <
bool Conjugate,
typename Rhs>
491 const Index cols = this->cols();
492 const Index nrhs = rhs.cols();
493 const Index rank = this->rank();
495 for (
Index k = rank-1; k >= 0; --k) {
497 rhs.row(k).swap(rhs.row(rank - 1));
499 rhs.middleRows(rank - 1, cols - rank + 1)
500 .applyHouseholderOnTheLeft(
501 matrixQTZ().row(k).tail(cols - rank).transpose().
template conjugateIf<!Conjugate>(), zCoeffs().
template conjugateIf<Conjugate>()(k),
504 rhs.row(k).swap(rhs.row(rank - 1));
509 template <
typename MatrixType>
510 template <
typename Rhs>
513 const Index cols = this->cols();
514 const Index nrhs = rhs.cols();
515 const Index rank = this->rank();
517 for (
Index k = 0; k < rank; ++k) {
519 rhs.row(k).swap(rhs.row(rank - 1));
521 rhs.middleRows(rank - 1, cols - rank + 1)
522 .applyHouseholderOnTheLeft(
523 matrixQTZ().row(k).tail(cols - rank).adjoint(), zCoeffs()(k),
526 rhs.row(k).swap(rhs.row(rank - 1));
531 #ifndef EIGEN_PARSED_BY_DOXYGEN
532 template <
typename _MatrixType>
533 template <
typename RhsType,
typename DstType>
535 const RhsType& rhs, DstType& dst)
const {
536 const Index rank = this->rank();
543 typename RhsType::PlainObject c(rhs);
544 c.applyOnTheLeft(matrixQ().setLength(rank).adjoint());
547 dst.topRows(rank) = matrixT()
548 .topLeftCorner(rank, rank)
549 .template triangularView<Upper>()
550 .solve(c.topRows(rank));
552 const Index cols = this->cols();
556 dst.bottomRows(cols - rank).setZero();
557 applyZAdjointOnTheLeftInPlace(dst);
561 dst = colsPermutation() * dst;
564 template<
typename _MatrixType>
565 template<
bool Conjugate,
typename RhsType,
typename DstType>
566 void CompleteOrthogonalDecomposition<_MatrixType>::_solve_impl_transposed(
const RhsType &rhs, DstType &dst)
const
568 const Index rank = this->rank();
575 typename RhsType::PlainObject c(colsPermutation().transpose()*rhs);
578 applyZOnTheLeftInPlace<!Conjugate>(c);
581 matrixT().topLeftCorner(rank, rank)
582 .template triangularView<Upper>()
583 .transpose().template conjugateIf<Conjugate>()
584 .solveInPlace(c.topRows(rank));
586 dst.topRows(rank) = c.topRows(rank);
587 dst.bottomRows(rows()-rank).setZero();
589 dst.applyOnTheLeft(householderQ().setLength(rank).
template conjugateIf<!Conjugate>() );
595 template<
typename MatrixType>
597 :
traits<typename Transpose<typename MatrixType::PlainObject>::PlainObject>
602 template<
typename DstXprType,
typename MatrixType>
610 dst = src.nestedExpression().solve(IdentityMatrixType::Identity(src.cols(), src.cols()));
617 template <
typename MatrixType>
620 return m_cpqr.householderQ();
627 template <
typename Derived>
635 #endif // EIGEN_COMPLETEORTHOGONALDECOMPOSITION_H
Expression of the inverse of another expression.
Definition: Inverse.h:44
MatrixType matrixZ() const
Definition: CompleteOrthogonalDecomposition.h:161
Definition: Constants.h:518
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
bool isInjective() const
Definition: CompleteOrthogonalDecomposition.h:253
void computeInPlace()
Definition: CompleteOrthogonalDecomposition.h:430
bool isInvertible() const
Definition: ColPivHouseholderQR.h:310
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
RealScalar maxPivot() const
Definition: CompleteOrthogonalDecomposition.h:356
Definition: EigenBase.h:30
RealScalar threshold() const
Definition: ColPivHouseholderQR.h:378
void applyZAdjointOnTheLeftInPlace(Rhs &rhs) const
Definition: CompleteOrthogonalDecomposition.h:511
const MatrixType & matrixQR() const
Definition: ColPivHouseholderQR.h:189
CompleteOrthogonalDecomposition()
Default Constructor.
Definition: CompleteOrthogonalDecomposition.h:90
Definition: AssignEvaluator.h:804
@ Success
Definition: Constants.h:441
HouseholderSequenceType householderQ(void) const
Definition: CompleteOrthogonalDecomposition.h:619
Definition: SolverBase.h:18
CompleteOrthogonalDecomposition & setThreshold(const RealScalar &threshold)
Definition: CompleteOrthogonalDecomposition.h:320
bool isInvertible() const
Definition: CompleteOrthogonalDecomposition.h:271
const MatrixType & matrixT() const
Definition: CompleteOrthogonalDecomposition.h:183
void applyZOnTheLeftInPlace(Rhs &rhs) const
Definition: CompleteOrthogonalDecomposition.h:489
Index rank() const
Definition: CompleteOrthogonalDecomposition.h:235
Index nonzeroPivots() const
Definition: ColPivHouseholderQR.h:394
Index nonzeroPivots() const
Definition: CompleteOrthogonalDecomposition.h:351
bool isSurjective() const
Definition: CompleteOrthogonalDecomposition.h:262
MatrixType::RealScalar logAbsDeterminant() const
Definition: CompleteOrthogonalDecomposition.h:418
MatrixType::RealScalar absDeterminant() const
Definition: CompleteOrthogonalDecomposition.h:412
const HCoeffsType & zCoeffs() const
Definition: CompleteOrthogonalDecomposition.h:299
Definition: Constants.h:509
ColPivHouseholderQR & setThreshold(const RealScalar &threshold)
Definition: ColPivHouseholderQR.h:353
const HCoeffsType & hCoeffs() const
Definition: CompleteOrthogonalDecomposition.h:292
CompleteOrthogonalDecomposition(const EigenBase< InputType > &matrix)
Constructs a complete orthogonal decomposition from a given matrix.
Definition: CompleteOrthogonalDecomposition.h:118
const MatrixType & matrixQTZ() const
Definition: CompleteOrthogonalDecomposition.h:170
CompleteOrthogonalDecomposition(Index rows, Index cols)
Default Constructor with memory preallocation.
Definition: CompleteOrthogonalDecomposition.h:98
Complete orthogonal decomposition (COD) of a matrix.
Definition: CompleteOrthogonalDecomposition.h:52
RealScalar maxPivot() const
Definition: ColPivHouseholderQR.h:403
Index dimensionOfKernel() const
Definition: CompleteOrthogonalDecomposition.h:244
Index dimensionOfKernel() const
Definition: ColPivHouseholderQR.h:272
const PermutationType & colsPermutation() const
Definition: CompleteOrthogonalDecomposition.h:194
Definition: AssignmentFunctors.h:21
const PermutationType & colsPermutation() const
Definition: ColPivHouseholderQR.h:214
const CompleteOrthogonalDecomposition< PlainObject > completeOrthogonalDecomposition() const
Definition: CompleteOrthogonalDecomposition.h:629
Pseudo expression representing a solving operation.
Definition: Solve.h:63
bool isInjective() const
Definition: ColPivHouseholderQR.h:285
Definition: ForwardDeclarations.h:17
RealScalar threshold() const
Definition: CompleteOrthogonalDecomposition.h:342
Definition: AssignEvaluator.h:814
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Index rank() const
Definition: ColPivHouseholderQR.h:255
ComputationInfo info() const
Reports whether the complete orthogonal decomposition was successful.
Definition: CompleteOrthogonalDecomposition.h:366
ComputationInfo
Definition: Constants.h:439
bool isSurjective() const
Definition: ColPivHouseholderQR.h:298
const HCoeffsType & hCoeffs() const
Definition: ColPivHouseholderQR.h:334
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:213
HouseholderSequenceType householderQ() const
Definition: ColPivHouseholderQR.h:655
CompleteOrthogonalDecomposition(EigenBase< InputType > &matrix)
Constructs a complete orthogonal decomposition from a given matrix.
Definition: CompleteOrthogonalDecomposition.h:133
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:69
CompleteOrthogonalDecomposition & setThreshold(Default_t)
Definition: CompleteOrthogonalDecomposition.h:333
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:42
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition: HouseholderSequence.h:121
const Inverse< CompleteOrthogonalDecomposition > pseudoInverse() const
Definition: CompleteOrthogonalDecomposition.h:278