Warning, file /include/eigen3/Eigen/src/Householder/Householder.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_HOUSEHOLDER_H
0012 #define EIGEN_HOUSEHOLDER_H
0013
0014 namespace Eigen {
0015
0016 namespace internal {
0017 template<int n> struct decrement_size
0018 {
0019 enum {
0020 ret = n==Dynamic ? n : n-1
0021 };
0022 };
0023 }
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template<typename Derived>
0042 EIGEN_DEVICE_FUNC
0043 void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta)
0044 {
0045 VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret> essentialPart(derived(), 1, size()-1);
0046 makeHouseholder(essentialPart, tau, beta);
0047 }
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 template<typename Derived>
0065 template<typename EssentialPart>
0066 EIGEN_DEVICE_FUNC
0067 void MatrixBase<Derived>::makeHouseholder(
0068 EssentialPart& essential,
0069 Scalar& tau,
0070 RealScalar& beta) const
0071 {
0072 using std::sqrt;
0073 using numext::conj;
0074
0075 EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
0076 VectorBlock<const Derived, EssentialPart::SizeAtCompileTime> tail(derived(), 1, size()-1);
0077
0078 RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
0079 Scalar c0 = coeff(0);
0080 const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
0081
0082 if(tailSqNorm <= tol && numext::abs2(numext::imag(c0))<=tol)
0083 {
0084 tau = RealScalar(0);
0085 beta = numext::real(c0);
0086 essential.setZero();
0087 }
0088 else
0089 {
0090 beta = sqrt(numext::abs2(c0) + tailSqNorm);
0091 if (numext::real(c0)>=RealScalar(0))
0092 beta = -beta;
0093 essential = tail / (c0 - beta);
0094 tau = conj((beta - c0) / beta);
0095 }
0096 }
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 template<typename Derived>
0114 template<typename EssentialPart>
0115 EIGEN_DEVICE_FUNC
0116 void MatrixBase<Derived>::applyHouseholderOnTheLeft(
0117 const EssentialPart& essential,
0118 const Scalar& tau,
0119 Scalar* workspace)
0120 {
0121 if(rows() == 1)
0122 {
0123 *this *= Scalar(1)-tau;
0124 }
0125 else if(tau!=Scalar(0))
0126 {
0127 Map<typename internal::plain_row_type<PlainObject>::type> tmp(workspace,cols());
0128 Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime> bottom(derived(), 1, 0, rows()-1, cols());
0129 tmp.noalias() = essential.adjoint() * bottom;
0130 tmp += this->row(0);
0131 this->row(0) -= tau * tmp;
0132 bottom.noalias() -= tau * essential * tmp;
0133 }
0134 }
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 template<typename Derived>
0152 template<typename EssentialPart>
0153 EIGEN_DEVICE_FUNC
0154 void MatrixBase<Derived>::applyHouseholderOnTheRight(
0155 const EssentialPart& essential,
0156 const Scalar& tau,
0157 Scalar* workspace)
0158 {
0159 if(cols() == 1)
0160 {
0161 *this *= Scalar(1)-tau;
0162 }
0163 else if(tau!=Scalar(0))
0164 {
0165 Map<typename internal::plain_col_type<PlainObject>::type> tmp(workspace,rows());
0166 Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime> right(derived(), 0, 1, rows(), cols()-1);
0167 tmp.noalias() = right * essential;
0168 tmp += this->col(0);
0169 this->col(0) -= tau * tmp;
0170 right.noalias() -= tau * tmp * essential.adjoint();
0171 }
0172 }
0173
0174 }
0175
0176 #endif