Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
HouseholderSequence.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_HOUSEHOLDER_SEQUENCE_H
13#define EIGEN_HOUSEHOLDER_SEQUENCE_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
60
61namespace internal {
62
63template <typename VectorsType, typename CoeffsType, int Side>
64struct traits<HouseholderSequence<VectorsType, CoeffsType, Side> > {
65 using Scalar = typename VectorsType::Scalar;
66 using StorageIndex = typename VectorsType::StorageIndex;
67 using StorageKind = typename VectorsType::StorageKind;
68 enum {
69 RowsAtCompileTime =
70 Side == OnTheLeft ? traits<VectorsType>::RowsAtCompileTime : traits<VectorsType>::ColsAtCompileTime,
71 ColsAtCompileTime = RowsAtCompileTime,
72 MaxRowsAtCompileTime =
73 Side == OnTheLeft ? traits<VectorsType>::MaxRowsAtCompileTime : traits<VectorsType>::MaxColsAtCompileTime,
74 MaxColsAtCompileTime = MaxRowsAtCompileTime,
75 Flags = 0
76 };
77};
78
79struct HouseholderSequenceShape {};
80
81template <typename VectorsType, typename CoeffsType, int Side>
82struct evaluator_traits<HouseholderSequence<VectorsType, CoeffsType, Side> >
83 : public evaluator_traits_base<HouseholderSequence<VectorsType, CoeffsType, Side> > {
84 using Shape = HouseholderSequenceShape;
85};
86
87template <typename VectorsType, typename CoeffsType, int Side>
88struct hseq_side_dependent_impl {
89 using EssentialVectorType = Block<const VectorsType, Dynamic, 1>;
90 using HouseholderSequenceType = HouseholderSequence<VectorsType, CoeffsType, OnTheLeft>;
91 static EIGEN_DEVICE_FUNC inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k) {
92 Index start = k + 1 + h.m_shift;
93 return Block<const VectorsType, Dynamic, 1>(h.m_vectors, start, k, h.rows() - start, 1);
94 }
95};
96
97template <typename VectorsType, typename CoeffsType>
98struct hseq_side_dependent_impl<VectorsType, CoeffsType, OnTheRight> {
99 using EssentialVectorType = Transpose<Block<const VectorsType, 1, Dynamic>>;
100 using HouseholderSequenceType = HouseholderSequence<VectorsType, CoeffsType, OnTheRight>;
101 static inline const EssentialVectorType essentialVector(const HouseholderSequenceType& h, Index k) {
102 Index start = k + 1 + h.m_shift;
103 return Block<const VectorsType, 1, Dynamic>(h.m_vectors, k, start, 1, h.rows() - start).transpose();
104 }
105};
106
107template <typename OtherScalarType, typename MatrixType, bool ScalarOnLeft = true>
108struct matrix_type_times_scalar_type {
109 using ResultScalar =
110 typename std::conditional_t<ScalarOnLeft, ScalarBinaryOpTraits<OtherScalarType, typename MatrixType::Scalar>,
111 ScalarBinaryOpTraits<typename MatrixType::Scalar, OtherScalarType>>::ReturnType;
112 using Type =
113 Matrix<ResultScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime,
114 (MatrixType::MaxRowsAtCompileTime == 1 && MatrixType::MaxColsAtCompileTime != 1) ? RowMajor : ColMajor,
115 MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime>;
116};
117
118// A permutation has no scalar type; its product with a Householder sequence takes the sequence's.
119template <typename Scalar, typename PermutationType>
120struct permutation_type_as_matrix_type {
121 using Type = Matrix<Scalar, PermutationType::RowsAtCompileTime, PermutationType::ColsAtCompileTime, 0,
122 PermutationType::MaxRowsAtCompileTime, PermutationType::MaxColsAtCompileTime>;
123};
124
125// A diagonal or triangular operand is assigned to the result directly when the scalar types agree. The triangular
126// assignment kernel does not convert scalars, so a promoted result evaluates the operand and casts it, as the dense
127// product casts its operand.
128template <typename ResultType, typename OtherDerived>
129std::enable_if_t<std::is_same<typename ResultType::Scalar, typename OtherDerived::Scalar>::value>
130assign_householder_operand(ResultType& res, const EigenBase<OtherDerived>& other) {
131 res = other.derived();
132}
133template <typename ResultType, typename OtherDerived>
134std::enable_if_t<!std::is_same<typename ResultType::Scalar, typename OtherDerived::Scalar>::value>
135assign_householder_operand(ResultType& res, const EigenBase<OtherDerived>& other) {
136 res = other.derived().toDenseMatrix().template cast<typename ResultType::Scalar>();
137}
138
139// A real sequence applied to a complex destination, which happens in a product with a complex matrix.
140template <typename SequenceScalar, typename Dest>
141using hseq_applies_to_complex_parts =
142 bool_constant<!NumTraits<SequenceScalar>::IsComplex && NumTraits<typename Dest::Scalar>::IsComplex>;
143
144// The real matrix holding the real or imaginary part of a destination.
145template <typename SequenceScalar, typename Dest>
146struct hseq_real_part_type {
147 using type = Matrix<SequenceScalar, Dest::RowsAtCompileTime, Dest::ColsAtCompileTime,
148 (Dest::MaxRowsAtCompileTime == 1 && Dest::MaxColsAtCompileTime != 1) ? RowMajor : ColMajor,
149 Dest::MaxRowsAtCompileTime, Dest::MaxColsAtCompileTime>;
150};
151
152} // end namespace internal
153
154template <typename VectorsType, typename CoeffsType, int Side>
155class HouseholderSequence : public EigenBase<HouseholderSequence<VectorsType, CoeffsType, Side> > {
156 using EssentialVectorType =
157 typename internal::hseq_side_dependent_impl<VectorsType, CoeffsType, Side>::EssentialVectorType;
158
159 public:
160 enum {
161 RowsAtCompileTime = internal::traits<HouseholderSequence>::RowsAtCompileTime,
162 ColsAtCompileTime = internal::traits<HouseholderSequence>::ColsAtCompileTime,
163 MaxRowsAtCompileTime = internal::traits<HouseholderSequence>::MaxRowsAtCompileTime,
164 MaxColsAtCompileTime = internal::traits<HouseholderSequence>::MaxColsAtCompileTime
165 };
166 using Scalar = typename internal::traits<HouseholderSequence>::Scalar;
167
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>,
172 CoeffsType>,
173 Side>;
174
175 using AdjointReturnType = HouseholderSequence<
176 VectorsType,
177 std::conditional_t<NumTraits<Scalar>::IsComplex, internal::remove_all_t<typename CoeffsType::ConjugateReturnType>,
178 CoeffsType>,
179 Side>;
180
181 using TransposeReturnType = HouseholderSequence<
182 std::conditional_t<NumTraits<Scalar>::IsComplex,
183 internal::remove_all_t<typename VectorsType::ConjugateReturnType>, VectorsType>,
184 CoeffsType, Side>;
185
186 using ConstHouseholderSequence =
187 HouseholderSequence<std::add_const_t<VectorsType>, std::add_const_t<CoeffsType>, Side>;
188
206 EIGEN_DEVICE_FUNC HouseholderSequence(const VectorsType& v, const CoeffsType& h)
207 : m_vectors(v), m_coeffs(h), m_reverse(false), m_length(v.diagonalSize()), m_shift(0) {}
208
210 EIGEN_DEVICE_FUNC HouseholderSequence(const HouseholderSequence& other)
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) {}
216
221 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept {
222 return Side == OnTheLeft ? m_vectors.rows() : m_vectors.cols();
223 }
224
229 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return rows(); }
230
245 EIGEN_DEVICE_FUNC const EssentialVectorType essentialVector(Index k) const {
246 eigen_assert(k >= 0 && k < m_length);
247 return internal::hseq_side_dependent_impl<VectorsType, CoeffsType, Side>::essentialVector(*this, k);
248 }
249
251 TransposeReturnType transpose() const {
252 return TransposeReturnType(m_vectors.conjugate(), m_coeffs)
253 .setReverseFlag(!m_reverse)
254 .setLength(m_length)
255 .setShift(m_shift);
256 }
257
259 ConjugateReturnType conjugate() const {
260 return ConjugateReturnType(m_vectors.conjugate(), m_coeffs.conjugate())
261 .setReverseFlag(m_reverse)
262 .setLength(m_length)
263 .setShift(m_shift);
264 }
265
272 template <bool Cond>
273 EIGEN_DEVICE_FUNC inline std::conditional_t<Cond, ConjugateReturnType, ConstHouseholderSequence> conjugateIf() const {
274 using ReturnType = std::conditional_t<Cond, ConjugateReturnType, ConstHouseholderSequence>;
275 return ReturnType(m_vectors.template conjugateIf<Cond>(), m_coeffs.template conjugateIf<Cond>());
276 }
277
279 AdjointReturnType adjoint() const {
280 return AdjointReturnType(m_vectors, m_coeffs.conjugate())
281 .setReverseFlag(!m_reverse)
282 .setLength(m_length)
283 .setShift(m_shift);
284 }
285
287 AdjointReturnType inverse() const { return adjoint(); }
288
290 template <typename DestType>
291 inline EIGEN_DEVICE_FUNC void evalTo(DestType& dst) const {
293 rows());
294 evalTo(dst, workspace);
295 }
296
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>());
301 }
302
303 private:
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;
308 evalTo(real_dst);
309 dst = real_dst.template cast<typename Dest::Scalar>();
310 }
311
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)) {
317 // in-place
318 dst.diagonal().setOnes();
319 dst.template triangularView<StrictlyUpper>().setZero();
320 for (Index k = vecs - 1; k >= 0; --k) {
321 Index cornerSize = rows() - k - m_shift;
322 if (m_reverse)
323 dst.bottomRightCorner(cornerSize, cornerSize)
324 .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data());
325 else
326 dst.bottomRightCorner(cornerSize, cornerSize)
327 .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data());
328
329 // clear the off diagonal vector
330 dst.col(k).tail(rows() - k - 1).setZero();
331 }
332 // clear the remaining columns if needed
333 for (Index k = 0; k < cols() - vecs; ++k) dst.col(k).tail(rows() - k - 1).setZero();
334 } else if (m_length > BlockSize) {
335 dst.setIdentity(rows(), rows());
336 applyThisOnTheLeft(dst, workspace, true);
337 } else {
338 dst.setIdentity(rows(), rows());
339 for (Index k = vecs - 1; k >= 0; --k) {
340 Index cornerSize = rows() - k - m_shift;
341 if (m_reverse)
342 dst.bottomRightCorner(cornerSize, cornerSize)
343 .applyHouseholderOnTheRight(essentialVector(k), m_coeffs.coeff(k), workspace.data());
344 else
345 dst.bottomRightCorner(cornerSize, cornerSize)
346 .applyHouseholderOnTheLeft(essentialVector(k), m_coeffs.coeff(k), workspace.data());
347 }
348 }
349 }
350
351 public:
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);
357 }
358
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>());
363 }
364
365 private:
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);
371 dst.real() = part;
372 part = dst.imag();
373 applyThisOnTheRight(part);
374 dst.imag() = part;
375 }
376
377 template <typename Dest, typename Workspace>
378 inline void applyThisOnTheRightImpl(Dest& dst, Workspace& workspace, std::false_type) const {
379 // Use the block path when the reflectors are long enough for GEMM to outperform GEMV.
380 // The threshold on rows() (the reflector length) is higher than for the left-side path because
381 // the right-side block application has more overhead from the tmp = mat * V product layout.
382 if (m_length >= BlockSize && rows() - m_shift >= 4 * BlockSize) {
383 applyBlockOnTheRight(dst);
384 } else {
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());
390 }
391 }
392 }
393
396 template <typename Dest>
397 EIGEN_DONT_INLINE void applyBlockOnTheRight(Dest& dst) const {
398 // Make sure we have at least 2 useful blocks, otherwise it is point-less:
399 Index blockSize = m_length < Index(2 * BlockSize) ? (m_length + 1) / 2 : Index(BlockSize);
400 for (Index i = 0; i < m_length; i += blockSize) {
401 // Right-side application processes blocks in opposite order to left-side:
402 // forward (m_reverse=false): first block first; reversed: last block first.
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;
405 Index bs = end - k;
406 Index start = k + m_shift;
407
408 using SubVectorsType = Block<internal::remove_all_t<VectorsType>, Dynamic, Dynamic>;
409 SubVectorsType sub_vecs1(m_vectors.const_cast_derived(), Side == OnTheRight ? k : start,
410 Side == OnTheRight ? start : k, Side == OnTheRight ? bs : m_vectors.rows() - start,
411 Side == OnTheRight ? m_vectors.cols() - start : bs);
412 std::conditional_t<Side == OnTheRight, Transpose<SubVectorsType>, SubVectorsType&> sub_vecs(sub_vecs1);
413
414 Index dstCols = rows() - m_shift - k;
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);
417 }
418 }
419
420 public:
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);
426 }
427
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>());
432 }
433
434 private:
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);
440 dst.real() = part;
441 part = dst.imag();
442 applyThisOnTheLeft(part, inputIsIdentity);
443 dst.imag() = part;
444 }
445
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;
449 // if the entries are large enough, then apply the reflectors by block
450 if (m_length >= BlockSize && dst.cols() > 1) {
451 // Make sure we have at least 2 useful blocks, otherwise it is point-less:
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);
456 Index bs = end - k;
457 Index start = k + m_shift;
458
459 using SubVectorsType = Block<internal::remove_all_t<VectorsType>, Dynamic, Dynamic>;
460 SubVectorsType sub_vecs1(m_vectors.const_cast_derived(), Side == OnTheRight ? k : start,
461 Side == OnTheRight ? start : k, Side == OnTheRight ? bs : m_vectors.rows() - start,
462 Side == OnTheRight ? m_vectors.cols() - start : bs);
463 std::conditional_t<Side == OnTheRight, Transpose<SubVectorsType>, SubVectorsType&> sub_vecs(sub_vecs1);
464
465 Index dstRows = rows() - m_shift - k;
466
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);
470 } else {
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);
473 }
474 }
475 } else {
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;
480
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());
484 } else {
485 auto sub_dst = dst.bottomRows(dstRows);
486 sub_dst.applyHouseholderOnTheLeft(essentialVector(actual_k), m_coeffs.coeff(actual_k), workspace.data());
487 }
488 }
489 }
490 }
491
492 public:
500 template <typename OtherDerived>
501 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type operator*(
502 const MatrixBase<OtherDerived>& other) const {
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());
506 return res;
507 }
508
514 template <typename OtherDerived>
515 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type operator*(
516 const DiagonalBase<OtherDerived>& other) const {
517 return applyToUpperTriangularOnTheLeft<
518 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type>(other, true);
519 }
520
526 template <typename OtherDerived>
527 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type operator*(
528 const TriangularBase<OtherDerived>& other) const {
529 constexpr bool kUpperTriangular =
530 (int(OtherDerived::Mode) & (int(Upper) | int(Lower) | int(SelfAdjoint))) == int(Upper);
531 return applyToUpperTriangularOnTheLeft<
532 typename internal::matrix_type_times_scalar_type<Scalar, OtherDerived>::Type>(other, kUpperTriangular);
533 }
534
540 template <typename OtherDerived>
541 typename internal::permutation_type_as_matrix_type<Scalar, OtherDerived>::Type operator*(
542 const PermutationBase<OtherDerived>& other) const {
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);
547 // The permutation product runs in place when its operand is the destination.
548 res.noalias() = res * other.derived();
549 return res;
550 }
551
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();
561 return res;
562 }
563
564 template <typename VectorsType_, typename CoeffsType_, int Side_>
565 friend struct internal::hseq_side_dependent_impl;
566
567 private:
568 // The identity path of applyThisOnTheLeft() skips the columns left of the rows each reflection acts on, which is
569 // valid for any square input that vanishes below the diagonal: a diagonal or upper triangular matrix as much as
570 // the identity. Other inputs take the full path.
571 template <typename ResultType, typename OtherDerived>
572 ResultType applyToUpperTriangularOnTheLeft(const EigenBase<OtherDerived>& other, bool upperTriangular) const {
573 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE(*this, other);
574 ResultType res;
575 internal::assign_householder_operand(res, other);
576 applyThisOnTheLeft(res, upperTriangular && res.rows() == res.cols());
577 return res;
578 }
579
580 public:
590 EIGEN_DEVICE_FUNC HouseholderSequence& setLength(Index length) {
591 m_length = length;
592 return *this;
593 }
594
606 EIGEN_DEVICE_FUNC HouseholderSequence& setShift(Index shift) {
607 m_shift = shift;
608 return *this;
609 }
610
611 EIGEN_DEVICE_FUNC Index length() const {
612 return m_length;
613 }
614
615 EIGEN_DEVICE_FUNC Index shift() const {
616 return m_shift;
617 }
618
619 /* Necessary for .adjoint() and .conjugate() */
620 template <typename VectorsType2, typename CoeffsType2, int Side2>
621 friend class HouseholderSequence;
622
623 protected:
634 HouseholderSequence& setReverseFlag(bool reverse) {
635 m_reverse = reverse;
636 return *this;
637 }
638
639 bool reverseFlag() const { return m_reverse; }
640
641 typename VectorsType::Nested m_vectors;
642 typename CoeffsType::Nested m_coeffs;
643 bool m_reverse;
644 Index m_length;
645 Index m_shift;
646 enum { BlockSize = 48 };
647};
648
657template <typename OtherDerived, typename VectorsType, typename CoeffsType, int Side>
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);
664 return res;
665}
666
671template <typename OtherDerived, typename VectorsType, typename CoeffsType, int Side>
672typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type operator*(
674 using ResultType =
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);
679 // The lazy diagonal product multiplies from the left, D(i,i) * H(i,j), as a noncommutative scalar requires, and
680 // reads each coefficient only to overwrite it, so it runs in place.
681 res = other.derived() * res;
682 return res;
683}
684
690template <typename OtherDerived, typename VectorsType, typename CoeffsType, int Side>
691typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type operator*(
693 using ResultType =
694 typename internal::matrix_type_times_scalar_type<typename VectorsType::Scalar, OtherDerived, false>::Type;
695 ResultType res;
696 internal::assign_householder_operand(res, other);
697 h.applyThisOnTheRight(res);
698 return res;
699}
700
706template <typename OtherDerived, typename VectorsType, typename CoeffsType, int Side>
707typename internal::permutation_type_as_matrix_type<typename VectorsType::Scalar, OtherDerived>::Type operator*(
709 using ResultType =
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);
714 // The permutation product runs in place when its operand is the destination.
715 res.noalias() = other.derived() * res;
716 return res;
717}
718
720template <typename OtherDerived, typename VectorsType, typename CoeffsType, int Side>
721typename internal::permutation_type_as_matrix_type<typename VectorsType::Scalar, Inverse<OtherDerived>>::Type operator*(
722 const InverseImpl<OtherDerived, PermutationStorage>& other,
724 using ResultType =
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;
730 return res;
731}
732
738template <typename VectorsType, typename CoeffsType>
742
750template <typename VectorsType, typename CoeffsType>
755
756} // end namespace Eigen
757
758#endif // EIGEN_HOUSEHOLDER_SEQUENCE_H
Base class for diagonal matrices and expressions.
Definition DiagonalMatrix.h:34
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition HouseholderSequence.h:155
AdjointReturnType inverse() const
Inverse of the Householder sequence (equals the adjoint).
Definition HouseholderSequence.h:287
HouseholderSequence & setLength(Index length)
Sets the length of the Householder sequence.
Definition HouseholderSequence.h:590
std::conditional_t< Cond, ConjugateReturnType, ConstHouseholderSequence > conjugateIf() const
Definition HouseholderSequence.h:273
internal::permutation_type_as_matrix_type< Scalar, OtherDerived >::Type operator*(const PermutationBase< OtherDerived > &other) const
Computes the product of a Householder sequence with a permutation matrix.
Definition HouseholderSequence.h:541
internal::permutation_type_as_matrix_type< Scalar, Inverse< OtherDerived > >::Type operator*(const InverseImpl< OtherDerived, PermutationStorage > &other) const
Computes the product of a Householder sequence with the inverse of a permutation matrix.
Definition HouseholderSequence.h:554
constexpr Index cols() const noexcept
Number of columns of transformation viewed as a matrix.
Definition HouseholderSequence.h:229
constexpr Index rows() const noexcept
Number of rows of transformation viewed as a matrix.
Definition HouseholderSequence.h:221
HouseholderSequence & setShift(Index shift)
Sets the shift of the Householder sequence.
Definition HouseholderSequence.h:606
HouseholderSequence(const HouseholderSequence &other)
Copy constructor.
Definition HouseholderSequence.h:210
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:501
internal::matrix_type_times_scalar_type< Scalar, OtherDerived >::Type operator*(const DiagonalBase< OtherDerived > &other) const
Computes the product of a Householder sequence with a diagonal matrix.
Definition HouseholderSequence.h:515
ConjugateReturnType conjugate() const
Complex conjugate of the Householder sequence.
Definition HouseholderSequence.h:259
const EssentialVectorType essentialVector(Index k) const
Essential part of a Householder vector.
Definition HouseholderSequence.h:245
TransposeReturnType transpose() const
Transpose of the Householder sequence.
Definition HouseholderSequence.h:251
AdjointReturnType adjoint() const
Adjoint (conjugate transpose) of the Householder sequence.
Definition HouseholderSequence.h:279
HouseholderSequence(const VectorsType &v, const CoeffsType &h)
Constructor.
Definition HouseholderSequence.h:206
internal::matrix_type_times_scalar_type< Scalar, OtherDerived >::Type operator*(const TriangularBase< OtherDerived > &other) const
Computes the product of a Householder sequence with a triangular or self-adjoint view.
Definition HouseholderSequence.h:527
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Base class for permutations.
Definition PermutationMatrix.h:92
Base class for triangular part in a matrix.
Definition TriangularMatrix.h:68
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition HouseholderSequence.h:739
HouseholderSequence< VectorsType, CoeffsType, OnTheRight > rightHouseholderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition HouseholderSequence.h:751
@ SelfAdjoint
Definition Constants.h:228
@ Lower
Definition Constants.h:212
@ Upper
Definition Constants.h:214
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
@ OnTheLeft
Definition Constants.h:332
@ OnTheRight
Definition Constants.h:334
Definition EigenBase.h:34
constexpr Derived & derived()
Definition EigenBase.h:50
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:44