11 #ifndef EIGEN_HOUSEHOLDER_SEQUENCE_H 12 #define EIGEN_HOUSEHOLDER_SEQUENCE_H 59 template<
typename VectorsType,
typename CoeffsType,
int S
ide>
60 struct traits<HouseholderSequence<VectorsType,CoeffsType,Side> >
62 typedef typename VectorsType::Scalar Scalar;
63 typedef typename VectorsType::Index Index;
64 typedef typename VectorsType::StorageKind StorageKind;
66 RowsAtCompileTime = Side==
OnTheLeft ? traits<VectorsType>::RowsAtCompileTime
67 : traits<VectorsType>::ColsAtCompileTime,
68 ColsAtCompileTime = RowsAtCompileTime,
69 MaxRowsAtCompileTime = Side==
OnTheLeft ? traits<VectorsType>::MaxRowsAtCompileTime
70 : traits<VectorsType>::MaxColsAtCompileTime,
71 MaxColsAtCompileTime = MaxRowsAtCompileTime,
76 template<
typename VectorsType,
typename CoeffsType,
int S
ide>
77 struct hseq_side_dependent_impl
79 typedef Block<const VectorsType, Dynamic, 1> EssentialVectorType;
80 typedef HouseholderSequence<VectorsType, CoeffsType, OnTheLeft> HouseholderSequenceType;
81 typedef typename VectorsType::Index Index;
82 static inline const EssentialVectorType essentialVector(
const HouseholderSequenceType& h, Index k)
84 Index start = k+1+h.m_shift;
85 return Block<const VectorsType,Dynamic,1>(h.m_vectors, start, k, h.rows()-start, 1);
89 template<
typename VectorsType,
typename CoeffsType>
90 struct hseq_side_dependent_impl<VectorsType, CoeffsType,
OnTheRight>
92 typedef Transpose<Block<const VectorsType, 1, Dynamic> > EssentialVectorType;
93 typedef HouseholderSequence<VectorsType, CoeffsType, OnTheRight> HouseholderSequenceType;
94 typedef typename VectorsType::Index Index;
95 static inline const EssentialVectorType essentialVector(
const HouseholderSequenceType& h, Index k)
97 Index start = k+1+h.m_shift;
98 return Block<const VectorsType,1,Dynamic>(h.m_vectors, k, start, 1, h.rows()-start).transpose();
102 template<
typename OtherScalarType,
typename MatrixType>
struct matrix_type_times_scalar_type
104 typedef typename scalar_product_traits<OtherScalarType, typename MatrixType::Scalar>::ReturnType
106 typedef Matrix<ResultScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime,
107 0, MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime> Type;
112 template<
typename VectorsType,
typename CoeffsType,
int S
ide>
class HouseholderSequence
113 :
public EigenBase<HouseholderSequence<VectorsType,CoeffsType,Side> >
115 typedef typename internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::EssentialVectorType EssentialVectorType;
119 RowsAtCompileTime = internal::traits<HouseholderSequence>::RowsAtCompileTime,
120 ColsAtCompileTime = internal::traits<HouseholderSequence>::ColsAtCompileTime,
121 MaxRowsAtCompileTime = internal::traits<HouseholderSequence>::MaxRowsAtCompileTime,
122 MaxColsAtCompileTime = internal::traits<HouseholderSequence>::MaxColsAtCompileTime
124 typedef typename internal::traits<HouseholderSequence>::Scalar Scalar;
125 typedef typename VectorsType::Index Index;
127 typedef HouseholderSequence<
128 typename internal::conditional<NumTraits<Scalar>::IsComplex,
129 typename internal::remove_all<typename VectorsType::ConjugateReturnType>::type,
131 typename internal::conditional<NumTraits<Scalar>::IsComplex,
132 typename internal::remove_all<typename CoeffsType::ConjugateReturnType>::type,
135 > ConjugateReturnType;
155 : m_vectors(v), m_coeffs(h), m_trans(false), m_length(v.diagonalSize()),
162 : m_vectors(other.m_vectors),
163 m_coeffs(other.m_coeffs),
164 m_trans(other.m_trans),
165 m_length(other.m_length),
166 m_shift(other.m_shift)
174 Index
rows()
const {
return Side==
OnTheLeft ? m_vectors.rows() : m_vectors.cols(); }
180 Index
cols()
const {
return rows(); }
198 eigen_assert(k >= 0 && k < m_length);
199 return internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::essentialVector(*
this, k);
211 return ConjugateReturnType(m_vectors.conjugate(), m_coeffs.conjugate())
220 return conjugate().setTrans(!m_trans);
224 ConjugateReturnType
inverse()
const {
return adjoint(); }
227 template<
typename DestType>
inline void evalTo(DestType& dst)
const 229 Matrix<Scalar, DestType::RowsAtCompileTime, 1,
231 evalTo(dst, workspace);
235 template<
typename Dest,
typename Workspace>
236 void evalTo(Dest& dst, Workspace& workspace)
const 238 workspace.resize(rows());
239 Index vecs = m_length;
240 const typename Dest::Scalar *dst_data = internal::extract_data(dst);
241 if( internal::is_same<
typename internal::remove_all<VectorsType>::type,Dest>::value
242 && dst_data!=0 && dst_data == internal::extract_data(m_vectors))
245 dst.diagonal().setOnes();
246 dst.template triangularView<StrictlyUpper>().setZero();
247 for(Index k = vecs-1; k >= 0; --k)
249 Index cornerSize = rows() - k - m_shift;
251 dst.bottomRightCorner(cornerSize, cornerSize)
252 .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data());
254 dst.bottomRightCorner(cornerSize, cornerSize)
255 .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data());
258 dst.col(k).tail(rows()-k-1).setZero();
261 for(Index k = 0; k<cols()-vecs ; ++k)
262 dst.col(k).tail(rows()-k-1).setZero();
266 dst.setIdentity(rows(), rows());
267 for(Index k = vecs-1; k >= 0; --k)
269 Index cornerSize = rows() - k - m_shift;
271 dst.bottomRightCorner(cornerSize, cornerSize)
272 .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), &workspace.coeffRef(0));
274 dst.bottomRightCorner(cornerSize, cornerSize)
275 .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), &workspace.coeffRef(0));
281 template<
typename Dest>
inline void applyThisOnTheRight(Dest& dst)
const 284 applyThisOnTheRight(dst, workspace);
288 template<
typename Dest,
typename Workspace>
289 inline void applyThisOnTheRight(Dest& dst, Workspace& workspace)
const 291 workspace.resize(dst.rows());
292 for(Index k = 0; k < m_length; ++k)
294 Index actual_k = m_trans ? m_length-k-1 : k;
295 dst.rightCols(rows()-m_shift-actual_k)
296 .applyHouseholderOnTheRight(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
301 template<
typename Dest>
inline void applyThisOnTheLeft(Dest& dst)
const 304 applyThisOnTheLeft(dst, workspace);
308 template<
typename Dest,
typename Workspace>
309 inline void applyThisOnTheLeft(Dest& dst, Workspace& workspace)
const 311 workspace.resize(dst.cols());
312 for(Index k = 0; k < m_length; ++k)
314 Index actual_k = m_trans ? k : m_length-k-1;
315 dst.bottomRows(rows()-m_shift-actual_k)
316 .applyHouseholderOnTheLeft(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
327 template<
typename OtherDerived>
331 res(other.template cast<
typename internal::matrix_type_times_scalar_type<Scalar,OtherDerived>::ResultScalar>());
332 applyThisOnTheLeft(res);
336 template<
typename _VectorsType,
typename _CoeffsType,
int _S
ide>
friend struct internal::hseq_side_dependent_impl;
370 Index
length()
const {
return m_length; }
371 Index
shift()
const {
return m_shift; }
374 template <
typename VectorsType2,
typename CoeffsType2,
int S
ide2>
friend class HouseholderSequence;
392 bool trans()
const {
return m_trans; }
394 typename VectorsType::Nested m_vectors;
395 typename CoeffsType::Nested m_coeffs;
409 template<
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
413 res(other.template cast<
typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::ResultScalar>());
414 h.applyThisOnTheRight(res);
422 template<
typename VectorsType,
typename CoeffsType>
434 template<
typename VectorsType,
typename CoeffsType>
442 #endif // EIGEN_HOUSEHOLDER_SEQUENCE_H ConjugateReturnType adjoint() const
Adjoint (conjugate transpose) of the Householder sequence.
Definition: HouseholderSequence.h:218
internal::matrix_type_times_scalar_type< Scalar, OtherDerived >::Type operator*(const MatrixBase< OtherDerived > &other) const
Computes the product of a Householder sequence with a matrix.
Definition: HouseholderSequence.h:328
ConjugateReturnType inverse() const
Inverse of the Householder sequence (equals the adjoint).
Definition: HouseholderSequence.h:224
HouseholderSequence transpose() const
Transpose of the Householder sequence.
Definition: HouseholderSequence.h:203
Index cols() const
Number of columns of transformation viewed as a matrix.
Definition: HouseholderSequence.h:180
Definition: Constants.h:279
HouseholderSequence(const HouseholderSequence &other)
Copy constructor.
Definition: HouseholderSequence.h:161
HouseholderSequence & setLength(Index length)
Sets the length of the Householder sequence.
Definition: HouseholderSequence.h:347
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition: HouseholderSequence.h:423
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition: ForwardDeclarations.h:227
HouseholderSequence & setShift(Index shift)
Sets the shift of the Householder sequence.
Definition: HouseholderSequence.h:364
Definition: Constants.h:277
Index rows() const
Number of rows of transformation viewed as a matrix.
Definition: HouseholderSequence.h:174
Index shift() const
Returns the shift of the Householder sequence.
Definition: HouseholderSequence.h:371
Definition: Constants.h:264
HouseholderSequence(const VectorsType &v, const CoeffsType &h)
Constructor.
Definition: HouseholderSequence.h:154
bool trans() const
Returns the transpose flag.
Definition: HouseholderSequence.h:392
HouseholderSequence< VectorsType, CoeffsType, OnTheRight > rightHouseholderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition: HouseholderSequence.h:435
Definition: Eigen_Colamd.h:50
Definition: Constants.h:268
const EssentialVectorType essentialVector(Index k) const
Essential part of a Householder vector.
Definition: HouseholderSequence.h:196
Index length() const
Returns the length of the Householder sequence.
Definition: HouseholderSequence.h:370
HouseholderSequence & setTrans(bool trans)
Sets the transpose flag.
Definition: HouseholderSequence.h:386
ConjugateReturnType conjugate() const
Complex conjugate of the Householder sequence.
Definition: HouseholderSequence.h:209
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48