30 # include <itpp/config.h>
32 # include <itpp/config_msvc.h>
35 #if defined(HAVE_LAPACK)
36 # include <itpp/base/algebra/lapack.h>
45 #if defined(HAVE_LAPACK)
47 bool svd(
const mat &A, vec &S)
49 char jobu =
'N', jobvt =
'N';
50 int m, n, lda, ldu, ldvt, lwork, info;
51 m = lda = ldu = A.rows();
66 dgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
67 V._data(), &ldvt, work._data(), &lwork_tmp, &info);
69 lwork =
static_cast<int>(work(0));
70 work.set_size(lwork,
false);
73 dgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
74 V._data(), &ldvt, work._data(), &lwork, &info);
79 bool svd(
const cmat &A, vec &S)
81 char jobu =
'N', jobvt =
'N';
82 int m, n, lda, ldu, ldvt, lwork, info;
83 m = lda = ldu = A.rows();
99 zgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
100 V._data(), &ldvt, work._data(), &lwork_tmp, rwork._data(), &info);
102 lwork =
static_cast<int>(
real(work(0)));
103 work.set_size(lwork,
false);
106 zgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
107 V._data(), &ldvt, work._data(), &lwork, rwork._data(), &info);
112 bool svd(
const mat &A, mat &U, vec &S, mat &V)
114 char jobu =
'A', jobvt =
'A';
115 int m, n, lda, ldu, ldvt, lwork, info;
116 m = lda = ldu = A.rows();
120 U.set_size(m, m,
false);
121 V.set_size(n, n,
false);
132 dgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
133 V._data(), &ldvt, work._data(), &lwork_tmp, &info);
135 lwork =
static_cast<int>(work(0));
136 work.set_size(lwork,
false);
139 dgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
140 V._data(), &ldvt, work._data(), &lwork, &info);
147 bool svd(
const cmat &A, cmat &U, vec &S, cmat &V)
149 char jobu =
'A', jobvt =
'A';
150 int m, n, lda, ldu, ldvt, lwork, info;
151 m = lda = ldu = A.rows();
155 U.set_size(m, m,
false);
156 V.set_size(n, n,
false);
168 zgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
169 V._data(), &ldvt, work._data(), &lwork_tmp, rwork._data(), &info);
171 lwork =
static_cast<int>(
real(work(0)));
172 work.set_size(lwork,
false);
175 zgesvd_(&jobu, &jobvt, &m, &n, B._data(), &lda, S._data(), U._data(), &ldu,
176 V._data(), &ldvt, work._data(), &lwork, rwork._data(), &info);
185 bool svd(
const mat &A, vec &S)
187 it_error(
"LAPACK library is needed to use svd() function");
191 bool svd(
const cmat &A, vec &S)
193 it_error(
"LAPACK library is needed to use svd() function");
197 bool svd(
const mat &A, mat &U, vec &S, mat &V)
199 it_error(
"LAPACK library is needed to use svd() function");
203 bool svd(
const cmat &A, cmat &U, vec &S, cmat &V)
205 it_error(
"LAPACK library is needed to use svd() function");
209 #endif // HAVE_LAPACK