30 # include <itpp/config.h>
32 # include <itpp/config_msvc.h>
35 #if defined(HAVE_LAPACK)
36 # include <itpp/base/algebra/lapack.h>
46 #if defined(HAVE_LAPACK)
48 bool qr(
const mat &A, mat &Q, mat &R)
62 dgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork_tmp,
65 lwork =
static_cast<int>(work(0));
66 work.set_size(lwork,
false);
68 dgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork, &info);
70 Q.set_size(m, m,
true);
73 for (
int i = 0; i < m; i++)
74 for (
int j = 0; j <
std::min(i, n); j++)
79 dorgqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork_tmp,
82 lwork =
static_cast<int>(work(0));
83 work.set_size(lwork,
false);
85 dorgqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork,
91 bool qr(
const mat &A, mat &R)
105 dgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork_tmp,
108 lwork =
static_cast<int>(work(0));
109 work.set_size(lwork,
false);
111 dgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork, &info);
114 for (
int i = 0; i < m; i++)
115 for (
int j = 0; j <
std::min(i, n); j++)
121 bool qr(
const mat &A, mat &Q, mat &R,
bmat &P)
137 dgeqp3_(&m, &n, R._data(), &m, jpvt._data(), tau._data(), work._data(),
140 lwork =
static_cast<int>(work(0));
141 work.set_size(lwork,
false);
143 dgeqp3_(&m, &n, R._data(), &m, jpvt._data(), tau._data(), work._data(),
146 Q.set_size(m, m,
true);
150 for (
int j = 0; j < n; j++)
151 P(jpvt(j) - 1, j) = 1;
154 for (
int i = 0; i < m; i++)
155 for (
int j = 0; j <
std::min(i, n); j++)
160 dorgqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork_tmp,
163 lwork =
static_cast<int>(work(0));
164 work.set_size(lwork,
false);
166 dorgqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork,
174 bool qr(
const cmat &A, cmat &Q, cmat &R)
188 zgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork_tmp,
191 lwork =
static_cast<int>(
real(work(0)));
192 work.set_size(lwork,
false);
194 zgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork, &info);
197 Q.set_size(m, m,
true);
200 for (
int i = 0; i < m; i++)
201 for (
int j = 0; j <
std::min(i, n); j++)
206 zungqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork_tmp,
209 lwork =
static_cast<int>(
real(work(0)));
210 work.set_size(lwork,
false);
212 zungqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork,
218 bool qr(
const cmat &A, cmat &R)
232 zgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork_tmp,
235 lwork =
static_cast<int>(
real(work(0)));
236 work.set_size(lwork,
false);
238 zgeqrf_(&m, &n, R._data(), &m, tau._data(), work._data(), &lwork, &info);
241 for (
int i = 0; i < m; i++)
242 for (
int j = 0; j <
std::min(i, n); j++)
248 bool qr(
const cmat &A, cmat &Q, cmat &R,
bmat &P)
265 zgeqp3_(&m, &n, R._data(), &m, jpvt._data(), tau._data(), work._data(),
266 &lwork_tmp, rwork._data(), &info);
268 lwork =
static_cast<int>(
real(work(0)));
269 work.set_size(lwork,
false);
271 zgeqp3_(&m, &n, R._data(), &m, jpvt._data(), tau._data(), work._data(),
272 &lwork, rwork._data(), &info);
275 Q.set_size(m, m,
true);
279 for (
int j = 0; j < n; j++)
280 P(jpvt(j) - 1, j) = 1;
283 for (
int i = 0; i < m; i++)
284 for (
int j = 0; j <
std::min(i, n); j++)
289 zungqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork_tmp,
292 lwork =
static_cast<int>(
real(work(0)));
293 work.set_size(lwork,
false);
295 zungqr_(&m, &m, &k, Q._data(), &m, tau._data(), work._data(), &lwork,
303 bool qr(
const mat &A, mat &Q, mat &R)
305 it_error(
"LAPACK library is needed to use qr() function");
309 bool qr(
const mat &A, mat &R)
311 it_error(
"LAPACK library is needed to use qr() function");
315 bool qr(
const mat &A, mat &Q, mat &R,
bmat &P)
317 it_error(
"LAPACK library is needed to use qr() function");
321 bool qr(
const cmat &A, cmat &Q, cmat &R)
323 it_error(
"LAPACK library is needed to use qr() function");
327 bool qr(
const cmat &A, cmat &R)
329 it_error(
"LAPACK library is needed to use qr() function");
333 bool qr(
const cmat &A, cmat &Q, cmat &R,
bmat &P)
335 it_error(
"LAPACK library is needed to use qr() function");
339 #endif // HAVE_LAPACK