<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lahqr_shiftcolumn.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
7//
8// This file is part of <T>LAPACK.
9// <T>LAPACK is free software: you can redistribute it and/or modify it under
10// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
11
12#ifndef TLAPACK_LAHQR_SHIFTCOLUMN_HH
13#define TLAPACK_LAHQR_SHIFTCOLUMN_HH
14
16
17namespace tlapack {
18
38template <TLAPACK_MATRIX matrix_t,
39 TLAPACK_VECTOR vector_t,
40 enable_if_t<is_real<type_t<matrix_t>>, bool> = true>
42 vector_t& v,
45{
46 // Using
47 using idx_t = size_type<matrix_t>;
48 using TH = type_t<matrix_t>;
49
50 // Constants
51 const idx_t n = ncols(H);
52 const TH zero(0);
53
54 // Check arguments
55 tlapack_check_false((n != 2 and n != 3));
56 tlapack_check_false(n != nrows(H));
57 tlapack_check_false((idx_t)size(v) != n);
58
59 if (n == 2) {
60 const TH s = abs(H(0, 0) - real(s2)) + abs(imag(s2)) + abs(H(1, 0));
61 if (s == zero) {
62 v[0] = zero;
63 v[1] = zero;
64 }
65 else {
66 const TH h10s = H(1, 0) / s;
67 v[0] = h10s * H(0, 1) +
68 (H(0, 0) - real(s1)) * ((H(0, 0) - real(s2)) / s) -
69 imag(s1) * (imag(s2) / s);
70 v[1] = h10s * (H(0, 0) + H(1, 1) - real(s1) - real(s2));
71 }
72 }
73 else {
74 const TH s = abs(H(0, 0) - real(s2)) + abs(imag(s2)) + abs(H(1, 0)) +
75 abs(H(2, 0));
76 if (s == zero) {
77 v[0] = zero;
78 v[1] = zero;
79 v[2] = zero;
80 }
81 else {
82 const TH h10s = H(1, 0) / s;
83 const TH h20s = H(2, 0) / s;
84 v[0] = (H(0, 0) - real(s1)) * ((H(0, 0) - real(s2)) / s) -
85 imag(s1) * (imag(s2) / s) + H(0, 1) * h10s + H(0, 2) * h20s;
86 v[1] = h10s * (H(0, 0) + H(1, 1) - real(s1) - real(s2)) +
87 H(1, 2) * h20s;
88 v[2] = h20s * (H(0, 0) + H(2, 2) - real(s1) - real(s2)) +
89 h10s * H(2, 1);
90 }
91 }
92 return 0;
93}
94
114template <TLAPACK_MATRIX matrix_t,
115 TLAPACK_VECTOR vector_t,
116 enable_if_t<is_complex<type_t<matrix_t>>, bool> = true>
118 vector_t& v,
121{
122 // Using
123 using idx_t = size_type<matrix_t>;
124 using TH = type_t<matrix_t>;
125 using real_t = real_type<TH>;
126
127 // Constants
128 const idx_t n = ncols(H);
129 const real_t zero(0);
130
131 // Check arguments
132 tlapack_check_false((n != 2 and n != 3));
133 tlapack_check_false(n != nrows(H));
134 tlapack_check_false((idx_t)size(v) != n);
135
136 if (n == 2) {
137 const TH s = abs1(H(0, 0) - s2) + abs1(H(1, 0));
138 if (s == zero) {
139 v[0] = zero;
140 v[1] = zero;
141 }
142 else {
143 const TH h10s = H(1, 0) / s;
144 v[0] = h10s * H(0, 1) + (H(0, 0) - s1) * ((H(0, 0) - s2) / s);
145 v[1] = h10s * (H(0, 0) + H(1, 1) - s1 - s2);
146 }
147 }
148 else {
149 const TH s = abs1(H(0, 0) - s2) + abs1(H(1, 0)) + abs1(H(2, 0));
150 if (s == zero) {
151 v[0] = zero;
152 v[1] = zero;
153 v[2] = zero;
154 }
155 else {
156 const TH h10s = H(1, 0) / s;
157 const TH h20s = H(2, 0) / s;
158 v[0] = (H(0, 0) - s1) * ((H(0, 0) - s2) / s) + H(0, 1) * h10s +
159 H(0, 2) * h20s;
160 v[1] = h10s * (H(0, 0) + H(1, 1) - s1 - s2) + H(1, 2) * h20s;
161 v[2] = h20s * (H(0, 0) + H(2, 2) - s1 - s2) + h10s * H(2, 1);
162 }
163 }
164 return 0;
165}
166
167} // namespace tlapack
168
169#endif // TLAPACK_LAHQR_SHIFTCOLUMN_HH
constexpr real_type< T > real(const T &x) noexcept
Extends std::real() to real datatypes.
Definition utils.hpp:71
constexpr real_type< T > abs1(const T &x)
1-norm absolute value, |Re(x)| + |Im(x)|
Definition utils.hpp:133
constexpr real_type< T > imag(const T &x) noexcept
Extends std::imag() to real datatypes.
Definition utils.hpp:86
#define TLAPACK_VECTOR
Macro for tlapack::concepts::Vector compatible with C++17.
Definition concepts.hpp:906
#define TLAPACK_MATRIX
Macro for tlapack::concepts::Matrix compatible with C++17.
Definition concepts.hpp:896
int lahqr_shiftcolumn(const matrix_t &H, vector_t &v, complex_type< type_t< matrix_t > > s1, complex_type< type_t< matrix_t > > s2)
Given a 2-by-2 or 3-by-3 matrix H, lahqr_shiftcolumn calculates a multiple of the product: (H - s1*I)...
Definition lahqr_shiftcolumn.hpp:41
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
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
typename traits::complex_type_traits< Types..., int >::type complex_type
The common complex type of the list of types.
Definition scalar_type_traits.hpp:188