22 for (
int i = 0; i <
size; ++i) {
27 for (
int r = 0; r <
N - 1; ++r) {
29 double& alpha_re =
m_H[
re(r + 1, r)];
30 double& alpha_im =
m_H[
im(r + 1, r)];
45 for (
int i = r + 1; i <
N; ++i) {
55 nu = std::sqrt(nu) * ((alpha_re < 0) ? -1 : 1);
60 double inv_sigma_re = m_tau[
re(r)] / norm2_sigma;
61 double inv_sigma_im = -m_tau[
im(r)] / norm2_sigma;
70 for (
int i = r + 2; i <
N; ++i) {
71 double ir_re =
m_H[
re(i, r)];
72 double ir_im =
m_H[
im(i, r)];
74 m_H[
re(i, r)] = ir_re * inv_sigma_re - ir_im * inv_sigma_im;
75 m_H[
im(i, r)] = ir_im * inv_sigma_re + ir_re * inv_sigma_im;
79 for (
int j = r + 1; j <
N; ++j) {
81 double va_re =
m_H[
re(r + 1, j)];
82 double va_im =
m_H[
im(r + 1, j)];
83 for (
int i = r + 2; i <
N; ++i) {
85 va_im += m_H[
re(i, r)] * m_H[
im(i, j)] - m_H[
im(i, r)] * m_H[
re(i, j)];
89 double beta_re = m_tau[
re(r)] * va_re + m_tau[
im(r)] * va_im;
90 double beta_im = m_tau[
re(r)] * va_im - m_tau[
im(r)] * va_re;
91 m_H[
re(r + 1, j)] -= beta_re;
92 m_H[
im(r + 1, j)] -= beta_im;
93 for (
int i = r + 2; i <
N; ++i) {
94 double vi_re =
m_H[
re(i, r)];
95 double vi_im =
m_H[
im(i, r)];
97 m_H[
re(i, j)] -= beta_re * vi_re - beta_im * vi_im;
98 m_H[
im(i, j)] -= beta_re * vi_im + beta_im * vi_re;
103 for (
int i = 0; i <
N; ++i) {
105 double va_re =
m_H[
re(i, r + 1)];
106 double va_im = -
m_H[
im(i, r + 1)];
107 for (
int j = r + 2; j <
N; ++j) {
109 va_im -= m_H[
re(j, r)] * m_H[
im(i, j)] + m_H[
im(j, r)] * m_H[
re(i, j)];
113 double beta_re = m_tau[
re(r)] * va_re + m_tau[
im(r)] * va_im;
114 double beta_im = m_tau[
re(r)] * va_im - m_tau[
im(r)] * va_re;
115 m_H[
re(i, r + 1)] -= beta_re;
116 m_H[
im(i, r + 1)] += beta_im;
117 for (
int j = r + 2; j <
N; ++j) {
118 double vj_re =
m_H[
re(j, r)];
119 double vj_im =
m_H[
im(j, r)];
121 m_H[
re(i, j)] -= beta_re * vj_re - beta_im * vj_im;
122 m_H[
im(i, j)] += beta_re * vj_im + beta_im * vj_re;
132 for (
int i = 0; i <
size; ++i) {
135 for (
int i = 0; i <
N; ++i) {
136 for (
int j = 0; j < i - 1; ++j) {
137 mat[
re(i, j)] = mat[
im(i, j)] = 0;
146 for (
int i = 0; i <
size; ++i) {
149 for (
int i = 0; i <
N; ++i) {
160 for (
int r =
N - 2; r >= 0; --r) {
161 for (
int j = 0; j <
N; ++j) {
163 double vm_re = mat[
re(r + 1, j)];
164 double vm_im = mat[
im(r + 1, j)];
165 for (
int i = r + 2; i <
N; ++i) {
166 vm_re +=
m_H[
re(i, r)] * mat[
re(i, j)] +
m_H[
im(i, r)] * mat[
im(i, j)];
167 vm_im +=
m_H[
re(i, r)] * mat[
im(i, j)] -
m_H[
im(i, r)] * mat[
re(i, j)];
173 mat[
re(r + 1, j)] -= beta_re;
174 mat[
im(r + 1, j)] -= beta_im;
175 for (
int i = r + 2; i <
N; ++i) {
176 double vi_re =
m_H[
re(i, r)];
177 double vi_im =
m_H[
im(i, r)];
178 mat[
re(i, j)] -= beta_re * vi_re - beta_im * vi_im;
179 mat[
im(i, j)] -= beta_re * vi_im + beta_im * vi_re;
void get_Hessenberg(double *mat)
size_t re(const size_t i, const size_t j)
std::valarray< double > m_tau
size_t im(const size_t i, const size_t j)
std::valarray< double > m_H
void set_matrix(const double *mat)