<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
hessenberg_rq.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_HESSENBERG_RQ_HH
11#define TLAPACK_HESSENBERG_RQ_HH
12
14#include "tlapack/blas/rot.hpp"
15#include "tlapack/blas/rotg.hpp"
16
17namespace tlapack {
18
44template <TLAPACK_SMATRIX T_t,
45 TLAPACK_SVECTOR CL_t,
46 TLAPACK_SVECTOR SL_t,
47 TLAPACK_SVECTOR CR_t,
48 TLAPACK_SVECTOR SR_t>
49inline void hessenberg_rq(T_t& T, CL_t& cl, SL_t& sl, CR_t& cr, SR_t& sr)
50{
51 using TA = type_t<T_t>;
52 using idx_t = size_type<T_t>;
54
55 // constants
56 const idx_t n = ncols(T);
57 const idx_t k = n - 1;
58
59 // quick return
60 if (k < 1) return;
61
62 // Apply rotations to last column
63 for (idx_t j = n - 2; j != (idx_t)-1; --j) {
64 TA temp = cl[j] * T(j, n - 1) + sl[j] * T(j + 1, n - 1);
65 T(j + 1, n - 1) = -conj(sl[j]) * T(j, n - 1) + cl[j] * T(j + 1, n - 1);
66 T(j, n - 1) = temp;
67 }
68
69 for (idx_t i = n - 1; i > 0; --i) {
70 // Apply rotations from the left to the next column
71 for (idx_t j = i - 1; j != (idx_t)-1; --j) {
72 TA temp = cl[j] * T(j, i - 1) + sl[j] * T(j + 1, i - 1);
73 T(j + 1, i - 1) =
74 -conj(sl[j]) * T(j, i - 1) + cl[j] * T(j + 1, i - 1);
75 T(j, i - 1) = temp;
76 }
77
78 // Generate rotation to reduce T(i, i-1)
79 rotg(T(i, i), T(i, i - 1), cr[i - 1], sr[i - 1]);
80 sr[i - 1] = -sr[i - 1];
81 T(i, i - 1) = (TA)0;
82
83 // Apply rotation from the right
84 auto t1 = slice(T, range(0, i), i - 1);
85 auto t2 = slice(T, range(0, i), i);
86 rot(t1, t2, cr[i - 1], conj(sr[i - 1]));
87 }
88}
89
90} // namespace tlapack
91
92#endif // TLAPACK_HESSENBERG_RQ_HH
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
#define TLAPACK_SVECTOR
Macro for tlapack::concepts::SliceableVector compatible with C++17.
Definition concepts.hpp:909
#define TLAPACK_SMATRIX
Macro for tlapack::concepts::SliceableMatrix compatible with C++17.
Definition concepts.hpp:899
void rotg(T &a, T &b, T &c, T &s)
Construct plane rotation that eliminates b, such that:
Definition rotg.hpp:39
void rot(vectorX_t &x, vectorY_t &y, const c_type &c, const s_type &s)
Apply plane rotation:
Definition rot.hpp:44
void hessenberg_rq(T_t &T, CL_t &cl, SL_t &sl, CR_t &cr, SR_t &sr)
Applies a sequence of rotations to an upper triangular matrix T from the left (making it an upper Hes...
Definition hessenberg_rq.hpp:49
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113