22 for (
int i = 0; i <
size; ++i) {
27 for (
int r = 0; r <
N; ++r) {
29 double& alpha_re =
m_qr[
re(r, r)];
30 double& alpha_im =
m_qr[
im(r, r)];
45 for (
int i = r; 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 + 1; i <
N; ++i) {
71 double ir_re =
m_qr[
re(i, r)];
72 double ir_im =
m_qr[
im(i, r)];
74 m_qr[
re(i, r)] = ir_re * inv_sigma_re - ir_im * inv_sigma_im;
75 m_qr[
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_qr[
re(r, j)];
82 double va_im =
m_qr[
im(r, j)];
83 for (
int i = r + 1; i <
N; ++i) {
85 va_im += m_qr[
re(i, r)] * m_qr[
im(i, j)] - m_qr[
im(i, r)] * m_qr[
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;
93 for (
int i = r + 1; i <
N; ++i) {
94 double vi_re =
m_qr[
re(i, r)];
95 double vi_im =
m_qr[
im(i, r)];
97 m_qr[
re(i, j)] -= beta_re * vi_re - beta_im * vi_im;
98 m_qr[
im(i, j)] -= beta_re * vi_im + beta_im * vi_re;
108 for (
int i = 0; i <
size; ++i) {
111 for (
int i = 0; i <
N; ++i) {
112 for (
int j = 0; j < i; ++j) {
113 mat[
re(i, j)] = mat[
im(i, j)] = 0;
123 for (
int r = 0; r <
N; ++r) {
125 double va_re = vec[
re(r)];
126 double va_im = vec[
im(r)];
127 for (
int i = r + 1; i <
N; ++i) {
136 vec[
re(r)] -= beta_re;
137 vec[
im(r)] -= beta_im;
138 for (
int i = r + 1; i <
N; ++i) {
139 double vi_re =
m_qr[
re(i, r)];
140 double vi_im =
m_qr[
im(i, r)];
142 vec[
re(i)] -= beta_re * vi_re - beta_im * vi_im;
143 vec[
im(i)] -= beta_re * vi_im + beta_im * vi_re;
149 for (
int i = N - 1; i >= 0; --i) {
150 for (
int j = i + 1; j <
N; ++j) {
154 double inv = 1 /
m_qr[
re(i, i)];
165 for (
int i = 0; i <
size; ++i) {
168 for (
int i = 0; i <
N; ++i) {
180 for (
int r = 0; r <
N; ++r) {
181 for (
int j = 0; j <
N; ++j) {
183 double va_re = mat[
re(r, j)];
184 double va_im = mat[
im(r, j)];
185 for (
int i = r + 1; i <
N; ++i) {
194 mat[
re(r, j)] -= beta_re;
195 mat[
im(r, j)] -= beta_im;
196 for (
int i = r + 1; i <
N; ++i) {
197 double vi_re =
m_qr[
re(i, r)];
198 double vi_im =
m_qr[
im(i, r)];
200 mat[
re(i, j)] -= beta_re * vi_re - beta_im * vi_im;
201 mat[
im(i, j)] -= beta_re * vi_im + beta_im * vi_re;
207 for (
int i = N - 1; i >= 0; --i) {
208 for (
int r = i + 1; r <
N; ++r) {
209 double& qrir_re =
m_qr[
re(i, r)];
210 double& qrir_im =
m_qr[
im(i, r)];
211 for (
int j = 0; j <
N; ++j) {
212 mat[
re(i, j)] -= qrir_re * mat[
re(r, j)] - qrir_im * mat[
im(r, j)];
213 mat[
im(i, j)] -= qrir_re * mat[
im(r, j)] + qrir_im * mat[
re(r, j)];
216 for (
int j = 0; j <
N; ++j) {
217 double inv = 1 /
m_qr[
re(i, i)];
219 mat[
re(i, j)] *= inv;
220 mat[
im(i, j)] *= inv;
229 for (
int i = 0; i <
size; ++i) {
232 for (
int i = 0; i <
N; ++i) {
244 std::valarray<double> sign(
N);
245 for (
int i = 0; i <
N; ++i) {
246 sign[i] = (
m_qr[
re(i, i)] < 0) ? -1 : 1;
248 for (
int i = 0; i <
N; ++i) {
249 for (
int j = 0; j <
N; ++j) {
250 mat[
re(i, j)] *= sign[j];
251 mat[
im(i, j)] *= sign[j];
260 for (
int r =
N - 1; r >= 0; --r) {
261 for (
int j = 0; j <
N; ++j) {
263 double vm_re = mat[
re(r, j)];
264 double vm_im = mat[
im(r, j)];
265 for (
int i = r + 1; i <
N; ++i) {
274 mat[
re(r, j)] -= beta_re;
275 mat[
im(r, j)] -= beta_im;
276 for (
int i = r + 1; i <
N; ++i) {
277 double vi_re =
m_qr[
re(i, r)];
278 double vi_im =
m_qr[
im(i, r)];
279 mat[
re(i, j)] -= beta_re * vi_re - beta_im * vi_im;
280 mat[
im(i, j)] -= beta_re * vi_im + beta_im * vi_re;
size_t re(const size_t i, const size_t j)
std::valarray< double > m_tau
void mult_inverse(double *mat)
size_t im(const size_t i, const size_t j)
void set_matrix(const double *mat)
std::valarray< double > m_qr
void get_inverse(double *mat)