18 #include <boost/numeric/ublas/io.hpp>
19 #include <boost/numeric/ublas/matrix_proxy.hpp>
22 typedef double LPKdoublereal;
24 extern "C" int zheevr_(
char *jobz,
char *range,
char *uplo, LPKint *n,
26 LPKint *il, LPKint *iu, LPKdoublereal *abstol, LPKint *m, LPKdoublereal *
28 work, LPKint *lwork, LPKdoublereal *rwork, LPKint *lrwork, LPKint *
29 iwork, LPKint *liwork, LPKint *info);
31 template <
typename T,
typename A>
33 subst(T &y,
const A &x) {
43 y = std::complex<double>(x.r, x.i);
46 template <
typename T,
typename LPKT>
47 void cmat2lpk(
const ublas::matrix<T> &a, ublas::vector<LPKT>& lpk) {
48 lpk.resize(a.size1() * a.size2());
50 for(
int i = 0; i < a.size2(); i++) {
51 ublas::matrix_column<const ublas::matrix<T> > acol(a, i);
52 for(
int j = 0; j < acol.size(); j++)
53 subst(*plpk++, acol(j));
56 template <
typename T,
typename LPKT>
57 void lpk2cmat(
const ublas::vector<LPKT>& lpk, ublas::matrix<T> &a) {
58 assert(a.size1() * a.size2() == lpk.size());
59 const LPKT *plpk = &lpk[0];
60 for(
int i = 0; i < a.size2(); i++) {
61 ublas::matrix_column<ublas::matrix<std::complex<double> > > acol(a, i);
62 for(
int j = 0; j < acol.size(); j++)
63 subst(acol(j), *plpk++);
66 template <
typename T,
typename LPKT>
67 void lpk2cvec(
const ublas::vector<LPKT>& lpk, ublas::vector<T> &a) {
69 const LPKT *plpk = &lpk[0];
70 for(
int i = 0; i < a.size(); i++) {
75 void eigHermiteRRR(
const ublas::matrix<std::complex<double> > &a_org,
76 ublas::vector<double> &lambda, ublas::matrix<std::complex<double> > &v,
78 LPKint n = a_org.size2();
79 LPKint lda = a_org.size1();
82 ublas::vector<LPKdoublecomplex> a(n*lda), z(n*ldz);
83 ublas::vector<LPKdoublereal> w(n);
84 ublas::vector<LPKint> isuppz(2*n);
88 LPKint lwork = -1, liwork = -1, lrwork = -1;
89 ublas::vector<LPKdoublecomplex> work(1);
90 ublas::vector<LPKdoublereal> rwork(1);
91 ublas::vector<LPKint> iwork(1);
93 LPKint info = 0, numret;
96 char cv =
'V', ca =
'A', cu =
'U';
97 int ret = zheevr_(&cv, &ca, &cu, &n, &a[0], &lda,
98 &vl, &vu, &il, &iu, &tol, &numret, &w[0], &z[0], &ldz,
99 &isuppz[0], &work[0], &lwork, &rwork[0], &lrwork, &iwork[0], &liwork, &info);
101 lwork = lrint(work[0].r);
103 lrwork = lrint(rwork[0]);
104 rwork.resize(lrwork);
106 iwork.resize(liwork);
107 ret = zheevr_(&cv, &ca, &cu, &n, &a[0], &lda,
108 &vl, &vu, &il, &iu, &tol, &numret, &w[0], &z[0], &ldz,
109 &isuppz[0], &work[0], &lwork, &rwork[0], &lrwork, &iwork[0], &liwork, &info);