155class HouseholderSequence :
public EigenBase<HouseholderSequence<VectorsType, CoeffsType, Side> > {
156 using EssentialVectorType =
157 typename internal::hseq_side_dependent_impl<VectorsType, CoeffsType, Side>::EssentialVectorType;
161 RowsAtCompileTime = internal::traits<HouseholderSequence>::RowsAtCompileTime,
162 ColsAtCompileTime = internal::traits<HouseholderSequence>::ColsAtCompileTime,
163 MaxRowsAtCompileTime = internal::traits<HouseholderSequence>::MaxRowsAtCompileTime,
164 MaxColsAtCompileTime = internal::traits<HouseholderSequence>::MaxColsAtCompileTime
166 using Scalar =
typename internal::traits<HouseholderSequence>::Scalar;
168 using ConjugateReturnType = HouseholderSequence<
169 std::conditional_t<NumTraits<Scalar>::IsComplex,
170 internal::remove_all_t<typename VectorsType::ConjugateReturnType>, VectorsType>,
171 std::conditional_t<NumTraits<Scalar>::IsComplex, internal::remove_all_t<typename CoeffsType::ConjugateReturnType>,
175 using AdjointReturnType = HouseholderSequence<
177 std::conditional_t<NumTraits<Scalar>::IsComplex, internal::remove_all_t<typename CoeffsType::ConjugateReturnType>,
181 using TransposeReturnType = HouseholderSequence<
182 std::conditional_t<NumTraits<Scalar>::IsComplex,
183 internal::remove_all_t<typename VectorsType::ConjugateReturnType>, VectorsType>,
186 using ConstHouseholderSequence =
187 HouseholderSequence<std::add_const_t<VectorsType>, std::add_const_t<CoeffsType>, Side>;
207 : m_vectors(v), m_coeffs(h), m_reverse(false), m_length(v.diagonalSize()), m_shift(0) {}
211 : m_vectors(other.m_vectors),
212 m_coeffs(other.m_coeffs),
213 m_reverse(other.m_reverse),
214 m_length(other.m_length),
215 m_shift(other.m_shift) {}
221 EIGEN_DEVICE_FUNC
constexpr Index rows() const noexcept {
222 return Side ==
OnTheLeft ? m_vectors.rows() : m_vectors.cols();
246 eigen_assert(k >= 0 && k < m_length);
247 return internal::hseq_side_dependent_impl<VectorsType, CoeffsType, Side>::essentialVector(*
this, k);
252 return TransposeReturnType(m_vectors.conjugate(), m_coeffs)
253 .setReverseFlag(!m_reverse)
260 return ConjugateReturnType(m_vectors.conjugate(), m_coeffs.conjugate())
261 .setReverseFlag(m_reverse)
273 EIGEN_DEVICE_FUNC
inline std::conditional_t<Cond, ConjugateReturnType, ConstHouseholderSequence>
conjugateIf()
const {
274 using ReturnType = std::conditional_t<Cond, ConjugateReturnType, ConstHouseholderSequence>;
280 return AdjointReturnType(m_vectors, m_coeffs.conjugate())
281 .setReverseFlag(!m_reverse)
290 template <
typename DestType>
291 inline EIGEN_DEVICE_FUNC
void evalTo(DestType& dst)
const {
294 evalTo(dst, workspace);
298 template <
typename Dest,
typename Workspace>
299 EIGEN_DEVICE_FUNC
void evalTo(Dest& dst, Workspace& workspace)
const {
300 evalToImpl(dst, workspace, internal::hseq_applies_to_complex_parts<Scalar, Dest>());
305 template <
typename Dest,
typename Workspace>
306 EIGEN_DEVICE_FUNC
void evalToImpl(Dest& dst, Workspace&, std::true_type)
const {
307 typename internal::hseq_real_part_type<Scalar, Dest>::type real_dst;
309 dst = real_dst.template cast<typename Dest::Scalar>();
312 template <
typename Dest,
typename Workspace>
313 EIGEN_DEVICE_FUNC
void evalToImpl(Dest& dst, Workspace& workspace, std::false_type)
const {
314 workspace.resize(
rows());
315 Index vecs = m_length;
316 if (internal::is_same_dense(dst, m_vectors)) {
318 dst.diagonal().setOnes();
319 dst.template triangularView<StrictlyUpper>().setZero();
320 for (
Index k = vecs - 1; k >= 0; --k) {
323 dst.bottomRightCorner(cornerSize, cornerSize)
324 .applyHouseholderOnTheRight(
essentialVector(k), m_coeffs.coeff(k), workspace.data());
326 dst.bottomRightCorner(cornerSize, cornerSize)
327 .applyHouseholderOnTheLeft(
essentialVector(k), m_coeffs.coeff(k), workspace.data());
330 dst.col(k).tail(
rows() - k - 1).setZero();
333 for (
Index k = 0; k <
cols() - vecs; ++k) dst.col(k).tail(
rows() - k - 1).setZero();
334 }
else if (m_length > BlockSize) {
336 applyThisOnTheLeft(dst, workspace,
true);
339 for (
Index k = vecs - 1; k >= 0; --k) {
342 dst.bottomRightCorner(cornerSize, cornerSize)
343 .applyHouseholderOnTheRight(
essentialVector(k), m_coeffs.coeff(k), workspace.data());
345 dst.bottomRightCorner(cornerSize, cornerSize)
346 .applyHouseholderOnTheLeft(
essentialVector(k), m_coeffs.coeff(k), workspace.data());
353 template <
typename Dest>
354 inline void applyThisOnTheRight(Dest& dst)
const {
355 Matrix<Scalar, 1, Dest::RowsAtCompileTime, RowMajor, 1, Dest::MaxRowsAtCompileTime> workspace(dst.rows());
356 applyThisOnTheRight(dst, workspace);
360 template <
typename Dest,
typename Workspace>
361 inline void applyThisOnTheRight(Dest& dst, Workspace& workspace)
const {
362 applyThisOnTheRightImpl(dst, workspace, internal::hseq_applies_to_complex_parts<Scalar, Dest>());
367 template <
typename Dest,
typename Workspace>
368 void applyThisOnTheRightImpl(Dest& dst, Workspace&, std::true_type)
const {
369 typename internal::hseq_real_part_type<Scalar, Dest>::type part = dst.real();
370 applyThisOnTheRight(part);
373 applyThisOnTheRight(part);
377 template <
typename Dest,
typename Workspace>
378 inline void applyThisOnTheRightImpl(Dest& dst, Workspace& workspace, std::false_type)
const {
382 if (m_length >= BlockSize &&
rows() - m_shift >= 4 * BlockSize) {
383 applyBlockOnTheRight(dst);
385 workspace.resize(dst.rows());
386 for (
Index k = 0; k < m_length; ++k) {
387 Index actual_k = m_reverse ? m_length - k - 1 : k;
388 dst.rightCols(
rows() - m_shift - actual_k)
389 .applyHouseholderOnTheRight(
essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
396 template <
typename Dest>
397 EIGEN_DONT_INLINE
void applyBlockOnTheRight(Dest& dst)
const {
399 Index blockSize = m_length <
Index(2 * BlockSize) ? (m_length + 1) / 2 :
Index(BlockSize);
400 for (
Index i = 0; i < m_length; i += blockSize) {
403 Index end = m_reverse ? m_length - i : (std::min)(m_length, i + blockSize);
404 Index k = m_reverse ? (std::max)(
Index(0), end - blockSize) : i;
406 Index start = k + m_shift;
408 using SubVectorsType = Block<internal::remove_all_t<VectorsType>, Dynamic, Dynamic>;
409 SubVectorsType sub_vecs1(m_vectors.const_cast_derived(), Side ==
OnTheRight ? k : start,
411 Side ==
OnTheRight ? m_vectors.cols() - start : bs);
412 std::conditional_t<Side == OnTheRight, Transpose<SubVectorsType>, SubVectorsType&> sub_vecs(sub_vecs1);
415 auto sub_dst = dst.rightCols(dstCols);
416 internal::apply_block_householder_on_the_right(sub_dst, sub_vecs, m_coeffs.segment(k, bs), !m_reverse);
422 template <
typename Dest>
423 inline void applyThisOnTheLeft(Dest& dst,
bool inputIsIdentity =
false)
const {
424 Matrix<Scalar, 1, Dest::ColsAtCompileTime, RowMajor, 1, Dest::MaxColsAtCompileTime> workspace;
425 applyThisOnTheLeft(dst, workspace, inputIsIdentity);
429 template <
typename Dest,
typename Workspace>
430 inline void applyThisOnTheLeft(Dest& dst, Workspace& workspace,
bool inputIsIdentity =
false)
const {
431 applyThisOnTheLeftImpl(dst, workspace, inputIsIdentity, internal::hseq_applies_to_complex_parts<Scalar, Dest>());
436 template <
typename Dest,
typename Workspace>
437 void applyThisOnTheLeftImpl(Dest& dst, Workspace&,
bool inputIsIdentity, std::true_type)
const {
438 typename internal::hseq_real_part_type<Scalar, Dest>::type part = dst.real();
439 applyThisOnTheLeft(part, inputIsIdentity);
442 applyThisOnTheLeft(part, inputIsIdentity);
446 template <
typename Dest,
typename Workspace>
447 inline void applyThisOnTheLeftImpl(Dest& dst, Workspace& workspace,
bool inputIsIdentity, std::false_type)
const {
448 if (inputIsIdentity && m_reverse) inputIsIdentity =
false;
450 if (m_length >= BlockSize && dst.cols() > 1) {
452 Index blockSize = m_length <
Index(2 * BlockSize) ? (m_length + 1) / 2 :
Index(BlockSize);
453 for (
Index i = 0; i < m_length; i += blockSize) {
454 Index end = m_reverse ? (std::min)(m_length, i + blockSize) : m_length - i;
455 Index k = m_reverse ? i : (std::max)(
Index(0), end - blockSize);
457 Index start = k + m_shift;
459 using SubVectorsType = Block<internal::remove_all_t<VectorsType>, Dynamic, Dynamic>;
460 SubVectorsType sub_vecs1(m_vectors.const_cast_derived(), Side ==
OnTheRight ? k : start,
462 Side ==
OnTheRight ? m_vectors.cols() - start : bs);
463 std::conditional_t<Side == OnTheRight, Transpose<SubVectorsType>, SubVectorsType&> sub_vecs(sub_vecs1);
467 if (inputIsIdentity) {
468 Block<Dest, Dynamic, Dynamic> sub_dst = dst.bottomRightCorner(dstRows, dstRows);
469 apply_block_householder_on_the_left(sub_dst, sub_vecs, m_coeffs.segment(k, bs), !m_reverse);
471 auto sub_dst = dst.bottomRows(dstRows);
472 apply_block_householder_on_the_left(sub_dst, sub_vecs, m_coeffs.segment(k, bs), !m_reverse);
476 workspace.resize(dst.cols());
477 for (
Index k = 0; k < m_length; ++k) {
478 Index actual_k = m_reverse ? k : m_length - k - 1;
479 Index dstRows =
rows() - m_shift - actual_k;
481 if (inputIsIdentity) {
482 Block<Dest, Dynamic, Dynamic> sub_dst = dst.bottomRightCorner(dstRows, dstRows);
483 sub_dst.applyHouseholderOnTheLeft(
essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
485 auto sub_dst = dst.bottomRows(dstRows);
486 sub_dst.applyHouseholderOnTheLeft(
essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
500 template <
typename OtherDerived>
501 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type
operator*(
503 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type res(
504 other.template cast<
typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::ResultScalar>());
505 applyThisOnTheLeft(res, internal::is_identity<OtherDerived>::value && res.rows() == res.cols());
514 template <
typename OtherDerived>
515 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type
operator*(
517 return applyToUpperTriangularOnTheLeft<
518 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type>(other,
true);
526 template <
typename OtherDerived>
527 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type
operator*(
529 constexpr bool kUpperTriangular =
531 return applyToUpperTriangularOnTheLeft<
532 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type>(other, kUpperTriangular);
540 template <
typename OtherDerived>
541 typename internal::permutation_type_as_matrix_type<Scalar, OtherDerived>::Type
operator*(
543 using ResultType =
typename internal::permutation_type_as_matrix_type<Scalar, OtherDerived>::Type;
544 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(*
this, other);
545 ResultType res = ResultType::Identity(
rows(),
rows());
546 applyThisOnTheLeft(res,
true);
548 res.noalias() = res * other.
derived();
553 template <
typename OtherDerived>
554 typename internal::permutation_type_as_matrix_type<Scalar, Inverse<OtherDerived>>::Type
operator*(
555 const InverseImpl<OtherDerived, PermutationStorage>& other)
const {
556 using ResultType =
typename internal::permutation_type_as_matrix_type<Scalar, Inverse<OtherDerived>>::Type;
557 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(*
this, other);
558 ResultType res = ResultType::Identity(
rows(),
rows());
559 applyThisOnTheLeft(res,
true);
560 res.noalias() = res * other.derived();
564 template <
typename VectorsType_,
typename CoeffsType_,
int S
ide_>
565 friend struct internal::hseq_side_dependent_impl;
571 template <
typename ResultType,
typename OtherDerived>
573 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(*
this, other);
575 internal::assign_householder_operand(res, other);
576 applyThisOnTheLeft(res, upperTriangular && res.rows() == res.cols());
620 template <
typename VectorsType2,
typename CoeffsType2,
int S
ide2>
639 bool reverseFlag()
const {
return m_reverse; }
641 typename VectorsType::Nested m_vectors;
642 typename CoeffsType::Nested m_coeffs;
646 enum { BlockSize = 48 };
657template <
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
658typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type operator*(
660 typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type res(
661 other.template cast<
typename internal::matrix_type_times_scalar_type<
typename VectorsType::Scalar, OtherDerived,
662 false>::ResultScalar>());
663 h.applyThisOnTheRight(res);
671template <
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
672typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type operator*(
675 typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type;
676 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(other, h);
677 ResultType res = ResultType::Identity(h.rows(), h.rows());
678 h.applyThisOnTheLeft(res,
true);
681 res = other.derived() * res;
690template <
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
691typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type operator*(
694 typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type;
696 internal::assign_householder_operand(res, other);
697 h.applyThisOnTheRight(res);
706template <
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
707typename internal::permutation_type_as_matrix_type<typename VectorsType::Scalar, OtherDerived>::Type operator*(
710 typename internal::permutation_type_as_matrix_type<typename VectorsType::Scalar, OtherDerived>::Type;
711 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(other, h);
712 ResultType res = ResultType::Identity(h.rows(), h.rows());
713 h.applyThisOnTheLeft(res,
true);
715 res.noalias() = other.derived() * res;
720template <
typename OtherDerived,
typename VectorsType,
typename CoeffsType,
int S
ide>
721typename internal::permutation_type_as_matrix_type<typename VectorsType::Scalar, Inverse<OtherDerived>>::Type operator*(
722 const InverseImpl<OtherDerived, PermutationStorage>& other,
725 typename internal::permutation_type_as_matrix_type<typename VectorsType::Scalar, Inverse<OtherDerived>>::Type;
726 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(other, h);
727 ResultType res = ResultType::Identity(h.rows(), h.rows());
728 h.applyThisOnTheLeft(res,
true);
729 res.noalias() = other.derived() * res;
738template <
typename VectorsType,
typename CoeffsType>
750template <
typename VectorsType,
typename CoeffsType>
752 const CoeffsType& h) {