Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_HOUSEHOLDER_H
00027 #define EIGEN_HOUSEHOLDER_H
00028
00029 namespace internal {
00030 template<int n> struct decrement_size
00031 {
00032 enum {
00033 ret = n==Dynamic ? n : n-1
00034 };
00035 };
00036 }
00037
00038 template<typename Derived>
00039 void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta)
00040 {
00041 VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret> essentialPart(derived(), 1, size()-1);
00042 makeHouseholder(essentialPart, tau, beta);
00043 }
00044
00060 template<typename Derived>
00061 template<typename EssentialPart>
00062 void MatrixBase<Derived>::makeHouseholder(
00063 EssentialPart& essential,
00064 Scalar& tau,
00065 RealScalar& beta) const
00066 {
00067 EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
00068 VectorBlock<const Derived, EssentialPart::SizeAtCompileTime> tail(derived(), 1, size()-1);
00069
00070 RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
00071 Scalar c0 = coeff(0);
00072
00073 if(tailSqNorm == RealScalar(0) && internal::imag(c0)==RealScalar(0))
00074 {
00075 tau = RealScalar(0);
00076 beta = internal::real(c0);
00077 essential.setZero();
00078 }
00079 else
00080 {
00081 beta = internal::sqrt(internal::abs2(c0) + tailSqNorm);
00082 if (internal::real(c0)>=RealScalar(0))
00083 beta = -beta;
00084 essential = tail / (c0 - beta);
00085 tau = internal::conj((beta - c0) / beta);
00086 }
00087 }
00088
00089 template<typename Derived>
00090 template<typename EssentialPart>
00091 void MatrixBase<Derived>::applyHouseholderOnTheLeft(
00092 const EssentialPart& essential,
00093 const Scalar& tau,
00094 Scalar* workspace)
00095 {
00096 if(rows() == 1)
00097 {
00098 *this *= Scalar(1)-tau;
00099 }
00100 else
00101 {
00102 Map<typename internal::plain_row_type<PlainObject>::type> tmp(workspace,cols());
00103 Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime> bottom(derived(), 1, 0, rows()-1, cols());
00104 tmp.noalias() = essential.adjoint() * bottom;
00105 tmp += this->row(0);
00106 this->row(0) -= tau * tmp;
00107 bottom.noalias() -= tau * essential * tmp;
00108 }
00109 }
00110
00111 template<typename Derived>
00112 template<typename EssentialPart>
00113 void MatrixBase<Derived>::applyHouseholderOnTheRight(
00114 const EssentialPart& essential,
00115 const Scalar& tau,
00116 Scalar* workspace)
00117 {
00118 if(cols() == 1)
00119 {
00120 *this *= Scalar(1)-tau;
00121 }
00122 else
00123 {
00124 Map<typename internal::plain_col_type<PlainObject>::type> tmp(workspace,rows());
00125 Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime> right(derived(), 0, 1, rows(), cols()-1);
00126 tmp.noalias() = right * essential.conjugate();
00127 tmp += this->col(0);
00128 this->col(0) -= tau * tmp;
00129 right.noalias() -= tau * tmp * essential.transpose();
00130 }
00131 }
00132
00133 #endif // EIGEN_HOUSEHOLDER_H