11 #ifndef EIGEN_HOUSEHOLDER_SEQUENCE_H
12 #define EIGEN_HOUSEHOLDER_SEQUENCE_H
61 template<
typename VectorsType,
typename CoeffsType,
int S
ide>
62 struct traits<HouseholderSequence<VectorsType,CoeffsType,Side> >
64 typedef typename VectorsType::Scalar Scalar;
65 typedef typename VectorsType::StorageIndex StorageIndex;
66 typedef typename VectorsType::StorageKind StorageKind;
68 RowsAtCompileTime = Side==
OnTheLeft ? traits<VectorsType>::RowsAtCompileTime
69 : traits<VectorsType>::ColsAtCompileTime,
70 ColsAtCompileTime = RowsAtCompileTime,
71 MaxRowsAtCompileTime = Side==
OnTheLeft ? traits<VectorsType>::MaxRowsAtCompileTime
72 : traits<VectorsType>::MaxColsAtCompileTime,
73 MaxColsAtCompileTime = MaxRowsAtCompileTime,
78 struct HouseholderSequenceShape {};
80 template<
typename VectorsType,
typename CoeffsType,
int S
ide>
81 struct evaluator_traits<HouseholderSequence<VectorsType,CoeffsType,Side> >
82 :
public evaluator_traits_base<HouseholderSequence<VectorsType,CoeffsType,Side> >
84 typedef HouseholderSequenceShape Shape;
87 template<
typename VectorsType,
typename CoeffsType,
int S
ide>
88 struct hseq_side_dependent_impl
90 typedef Block<const VectorsType, Dynamic, 1> EssentialVectorType;
91 typedef HouseholderSequence<VectorsType, CoeffsType, OnTheLeft> HouseholderSequenceType;
92 static EIGEN_DEVICE_FUNC inline const EssentialVectorType essentialVector(
const HouseholderSequenceType& h,
Index k)
94 Index start = k+1+h.m_shift;
95 return Block<const VectorsType,Dynamic,1>(h.m_vectors, start, k, h.rows()-start, 1);
99 template<
typename VectorsType,
typename CoeffsType>
100 struct hseq_side_dependent_impl<VectorsType, CoeffsType,
OnTheRight>
102 typedef Transpose<Block<const VectorsType, 1, Dynamic> > EssentialVectorType;
103 typedef HouseholderSequence<VectorsType, CoeffsType, OnTheRight> HouseholderSequenceType;
104 static inline const EssentialVectorType essentialVector(
const HouseholderSequenceType& h,
Index k)
106 Index start = k+1+h.m_shift;
107 return Block<const VectorsType,1,Dynamic>(h.m_vectors, k, start, 1, h.rows()-start).transpose();
111 template<
typename OtherScalarType,
typename MatrixType>
struct matrix_type_times_scalar_type
113 typedef typename ScalarBinaryOpTraits<OtherScalarType, typename MatrixType::Scalar>::ReturnType
115 typedef Matrix<ResultScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime,
116 0, MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime>
Type;
122 :
public EigenBase<HouseholderSequence<VectorsType,CoeffsType,Side> >
133 typedef typename internal::traits<HouseholderSequence>::Scalar
Scalar;
136 std::conditional_t<NumTraits<Scalar>::IsComplex,
139 std::conditional_t<NumTraits<Scalar>::IsComplex,
147 std::conditional_t<NumTraits<Scalar>::IsComplex,
154 std::conditional_t<NumTraits<Scalar>::IsComplex,
162 std::add_const_t<VectorsType>,
163 std::add_const_t<CoeffsType>,
234 return internal::hseq_side_dependent_impl<VectorsType,CoeffsType,Side>::essentialVector(*
this, k);
260 inline std::conditional_t<Cond,ConjugateReturnType,ConstHouseholderSequence>
263 typedef std::conditional_t<Cond,ConjugateReturnType,ConstHouseholderSequence> ReturnType;
264 return ReturnType(
m_vectors.template conjugateIf<Cond>(),
m_coeffs.template conjugateIf<Cond>());
280 template<
typename DestType>
290 template<
typename Dest,
typename Workspace>
292 void evalTo(Dest& dst, Workspace& workspace)
const
294 workspace.resize(
rows());
299 dst.diagonal().setOnes();
300 dst.template triangularView<StrictlyUpper>().setZero();
301 for(
Index k = vecs-1; k >= 0; --k)
305 dst.bottomRightCorner(cornerSize, cornerSize)
308 dst.bottomRightCorner(cornerSize, cornerSize)
312 dst.col(k).tail(
rows()-k-1).setZero();
329 for(
Index k = vecs-1; k >= 0; --k)
333 dst.bottomRightCorner(cornerSize, cornerSize)
336 dst.bottomRightCorner(cornerSize, cornerSize)
350 template<
typename Dest,
typename Workspace>
353 workspace.resize(dst.rows());
363 template<
typename Dest>
inline void applyThisOnTheLeft(Dest& dst,
bool inputIsIdentity =
false)
const
370 template<
typename Dest,
typename Workspace>
374 inputIsIdentity =
false;
392 std::conditional_t<Side==OnTheRight, Transpose<SubVectorsType>, SubVectorsType&> sub_vecs(sub_vecs1);
403 auto sub_dst = dst.bottomRows(dstRows);
410 workspace.resize(dst.cols());
423 auto sub_dst = dst.bottomRows(dstRows);
437 template<
typename OtherDerived>
441 res(other.template
cast<
typename internal::matrix_type_times_scalar_type<Scalar,OtherDerived>::ResultScalar>());
446 template<
typename VectorsType_,
typename CoeffsType_,
int S
ide_>
friend struct internal::hseq_side_dependent_impl;
527 template<
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
531 res(other.template
cast<
typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar,OtherDerived>::ResultScalar>());
540 template<
typename VectorsType,
typename CoeffsType>
552 template<
typename VectorsType,
typename CoeffsType>
Array< int, Dynamic, 1 > v
CastXpr< NewType >::Type cast() const
#define EIGEN_DEVICE_FUNC
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Expression of a fixed-size or dynamic-size block.
Sequence of Householder reflections acting on subspaces with decreasing size.
AdjointReturnType inverse() const
Inverse of the Householder sequence (equals the adjoint).
internal::hseq_side_dependent_impl< VectorsType, CoeffsType, Side >::EssentialVectorType EssentialVectorType
HouseholderSequence & setShift(Index shift)
Sets the shift of the Householder sequence.
HouseholderSequence & setLength(Index length)
Sets the length of the Householder sequence.
Index shift() const
Returns the shift of the Householder sequence.
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Number of columns of transformation viewed as a matrix.
internal::traits< HouseholderSequence >::Scalar Scalar
HouseholderSequence< std::conditional_t< NumTraits< Scalar >::IsComplex, internal::remove_all_t< typename VectorsType::ConjugateReturnType >, VectorsType >, std::conditional_t< NumTraits< Scalar >::IsComplex, internal::remove_all_t< typename CoeffsType::ConjugateReturnType >, CoeffsType >, Side > ConjugateReturnType
CoeffsType::Nested m_coeffs
void evalTo(DestType &dst) const
void applyThisOnTheRight(Dest &dst) const
VectorsType::Nested m_vectors
void evalTo(Dest &dst, Workspace &workspace) const
std::conditional_t< Cond, ConjugateReturnType, ConstHouseholderSequence > conjugateIf() const
HouseholderSequence< std::conditional_t< NumTraits< Scalar >::IsComplex, internal::remove_all_t< typename VectorsType::ConjugateReturnType >, VectorsType >, CoeffsType, Side > TransposeReturnType
HouseholderSequence(const HouseholderSequence &other)
Copy constructor.
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Number of rows of transformation viewed as a matrix.
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.
Index length() const
Returns the length of the Householder sequence.
ConjugateReturnType conjugate() const
Complex conjugate of the Householder sequence.
const EssentialVectorType essentialVector(Index k) const
Essential part of a Householder vector.
HouseholderSequence< std::add_const_t< VectorsType >, std::add_const_t< CoeffsType >, Side > ConstHouseholderSequence
void applyThisOnTheLeft(Dest &dst, bool inputIsIdentity=false) const
HouseholderSequence< VectorsType, std::conditional_t< NumTraits< Scalar >::IsComplex, internal::remove_all_t< typename CoeffsType::ConjugateReturnType >, CoeffsType >, Side > AdjointReturnType
HouseholderSequence & setReverseFlag(bool reverse)
TransposeReturnType transpose() const
Transpose of the Householder sequence.
AdjointReturnType adjoint() const
Adjoint (conjugate transpose) of the Householder sequence.
HouseholderSequence(const VectorsType &v, const CoeffsType &h)
Constructor.
void applyThisOnTheLeft(Dest &dst, Workspace &workspace, bool inputIsIdentity=false) const
void applyThisOnTheRight(Dest &dst, Workspace &workspace) const
Base class for all dense matrices, vectors, and expressions.
The matrix class, also used for vectors and row-vectors.
static const lastp1_t end
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
HouseholderSequence< VectorsType, CoeffsType, OnTheRight > rightHouseholderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
typename remove_all< T >::type remove_all_t
void apply_block_householder_on_the_left(MatrixType &mat, const VectorsType &vectors, const CoeffsType &hCoeffs, bool forward)
bool is_same_dense(const T1 &mat1, const T2 &mat2, std::enable_if_t< possibly_same_dense< T1, T2 >::value > *=0)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Eigen::Index Index
The interface type of indices.