26 #if defined (HAVE_CONFIG_H)
38 EIG::init (
const Matrix& a,
bool calc_rev,
bool calc_lev,
bool balance)
41 (*current_liboctave_error_handler)
42 (
"EIG: matrix contains Inf or NaN values");
45 return symmetric_init (a, calc_rev, calc_lev);
51 (*current_liboctave_error_handler) (
"EIG requires square matrix");
59 double *pwr = wr.fortran_vec ();
62 double *pwi = wi.fortran_vec ();
66 double *pvr = vr.fortran_vec ();
70 double *pvl = vl.fortran_vec ();
79 double *pscale =
scale.fortran_vec ();
84 double *prconde = rconde.fortran_vec ();
87 double *prcondv = rcondv.fortran_vec ();
91 F77_XFCN (dgeevx, DGEEVX, (F77_CONST_CHAR_ARG2 (balance ?
"B" :
"N", 1),
92 F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
93 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
94 F77_CONST_CHAR_ARG2 (
"N", 1),
95 n, tmp_data,
n, pwr, pwi, pvl,
96 n, pvr,
n, ilo, ihi, pscale,
97 abnrm, prconde, prcondv, &dummy_work,
98 lwork, &dummy_iwork, info
102 F77_CHAR_ARG_LEN (1)));
105 (*current_liboctave_error_handler) (
"dgeevx workspace query failed");
107 lwork =
static_cast<F77_INT> (dummy_work);
109 double *pwork = work.fortran_vec ();
111 F77_XFCN (dgeevx, DGEEVX, (F77_CONST_CHAR_ARG2 (balance ?
"B" :
"N", 1),
112 F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
113 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
114 F77_CONST_CHAR_ARG2 (
"N", 1),
115 n, tmp_data,
n, pwr, pwi, pvl,
116 n, pvr,
n, ilo, ihi, pscale,
117 abnrm, prconde, prcondv, pwork,
118 lwork, &dummy_iwork, info
122 F77_CHAR_ARG_LEN (1)));
125 (*current_liboctave_error_handler) (
"unrecoverable error in dgeevx");
128 (*current_liboctave_error_handler) (
"dgeevx failed to converge");
138 if (wi.elem (j) == 0.0)
141 for (
F77_INT i = 0; i < nvr; i++)
142 m_v.
elem (i, j) = vr.elem (i, j);
144 for (
F77_INT i = 0; i < nvl; i++)
145 m_w.
elem (i, j) = vl.elem (i, j);
150 (*current_liboctave_error_handler) (
"EIG: internal error");
152 m_lambda.
elem (j) =
Complex (wr.elem (j), wi.elem (j));
153 m_lambda.
elem (j+1) =
Complex (wr.elem (j+1), wi.elem (j+1));
155 for (
F77_INT i = 0; i < nvr; i++)
157 double real_part = vr.elem (i, j);
158 double imag_part = vr.elem (i, j+1);
160 m_v.
elem (i, j+1) =
Complex (real_part, -imag_part);
163 for (
F77_INT i = 0; i < nvl; i++)
165 double real_part = vl.elem (i, j);
166 double imag_part = vl.elem (i, j+1);
168 m_w.
elem (i, j+1) =
Complex (real_part, -imag_part);
178 EIG::symmetric_init (
const Matrix& a,
bool calc_rev,
bool calc_lev)
184 (*current_liboctave_error_handler) (
"EIG requires square matrix");
192 double *pwr = wr.fortran_vec ();
197 F77_XFCN (dsyev, DSYEV, (F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
198 F77_CONST_CHAR_ARG2 (
"U", 1),
199 n, tmp_data,
n, pwr, &dummy_work, lwork, info
201 F77_CHAR_ARG_LEN (1)));
204 (*current_liboctave_error_handler) (
"dsyev workspace query failed");
206 lwork =
static_cast<F77_INT> (dummy_work);
208 double *pwork = work.fortran_vec ();
210 F77_XFCN (dsyev, DSYEV, (F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
211 F77_CONST_CHAR_ARG2 (
"U", 1),
212 n, tmp_data,
n, pwr, pwork, lwork, info
214 F77_CHAR_ARG_LEN (1)));
217 (*current_liboctave_error_handler) (
"unrecoverable error in dsyev");
220 (*current_liboctave_error_handler) (
"dsyev failed to converge");
230 EIG::init (
const ComplexMatrix& a,
bool calc_rev,
bool calc_lev,
bool balance)
233 (*current_liboctave_error_handler)
234 (
"EIG: matrix contains Inf or NaN values");
237 return hermitian_init (a, calc_rev, calc_lev);
243 (*current_liboctave_error_handler) (
"EIG requires square matrix");
251 Complex *pw = wr.fortran_vec ();
255 Complex *pvr = vrtmp.fortran_vec ();
259 Complex *pvl = vltmp.fortran_vec ();
266 double *prwork = rwork.fortran_vec ();
272 double *pscale =
scale.fortran_vec ();
277 double *prconde = rconde.fortran_vec ();
280 double *prcondv = rcondv.fortran_vec ();
282 F77_XFCN (zgeevx, ZGEEVX, (F77_CONST_CHAR_ARG2 (balance ?
"B" :
"N", 1),
283 F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
284 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
285 F77_CONST_CHAR_ARG2 (
"N", 1),
289 pscale, abnrm, prconde, prcondv,
295 F77_CHAR_ARG_LEN (1)));
298 (*current_liboctave_error_handler) (
"zgeevx workspace query failed");
300 lwork =
static_cast<F77_INT> (dummy_work.real ());
302 Complex *pwork = work.fortran_vec ();
304 F77_XFCN (zgeevx, ZGEEVX, (F77_CONST_CHAR_ARG2 (balance ?
"B" :
"N", 1),
305 F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
306 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
307 F77_CONST_CHAR_ARG2 (
"N", 1),
311 pscale, abnrm, prconde, prcondv,
316 F77_CHAR_ARG_LEN (1)));
319 (*current_liboctave_error_handler) (
"unrecoverable error in zgeevx");
322 (*current_liboctave_error_handler) (
"zgeevx failed to converge");
332 EIG::hermitian_init (
const ComplexMatrix& a,
bool calc_rev,
bool calc_lev)
338 (*current_liboctave_error_handler) (
"EIG requires square matrix");
346 double *pwr = wr.fortran_vec ();
353 double *prwork = rwork.fortran_vec ();
355 F77_XFCN (zheev, ZHEEV, (F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
356 F77_CONST_CHAR_ARG2 (
"U", 1),
361 F77_CHAR_ARG_LEN (1)));
364 (*current_liboctave_error_handler) (
"zheev workspace query failed");
366 lwork =
static_cast<F77_INT> (dummy_work.real ());
368 Complex *pwork = work.fortran_vec ();
370 F77_XFCN (zheev, ZHEEV, (F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
371 F77_CONST_CHAR_ARG2 (
"U", 1),
375 F77_CHAR_ARG_LEN (1)));
378 (*current_liboctave_error_handler) (
"unrecoverable error in zheev");
381 (*current_liboctave_error_handler) (
"zheev failed to converge");
391 EIG::init (
const Matrix& a,
const Matrix& b,
bool calc_rev,
bool calc_lev,
395 (*current_liboctave_error_handler)
396 (
"EIG: matrix contains Inf or NaN values");
404 if (
n != a_nc || nb != b_nc)
405 (*current_liboctave_error_handler) (
"EIG requires square matrix");
408 (*current_liboctave_error_handler) (
"EIG requires same size matrices");
417 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
420 F77_CHAR_ARG_LEN (1)));
423 return symmetric_init (a, b, calc_rev, calc_lev);
433 double *par = ar.fortran_vec ();
436 double *pai = ai.fortran_vec ();
439 double *pbeta = beta.fortran_vec ();
443 double *pvr = vr.fortran_vec ();
447 double *pvl = vl.fortran_vec ();
452 F77_XFCN (dggev, DGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
453 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
454 n, atmp_data,
n, btmp_data,
n,
457 &dummy_work, lwork, info
459 F77_CHAR_ARG_LEN (1)));
462 (*current_liboctave_error_handler) (
"dggev workspace query failed");
464 lwork =
static_cast<F77_INT> (dummy_work);
466 double *pwork = work.fortran_vec ();
468 F77_XFCN (dggev, DGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
469 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
470 n, atmp_data,
n, btmp_data,
n,
475 F77_CHAR_ARG_LEN (1)));
478 (*current_liboctave_error_handler) (
"unrecoverable error in dggev");
481 (*current_liboctave_error_handler) (
"dggev failed to converge");
492 if (ai.elem (j) == 0.0)
494 m_lambda.elem (j) =
Complex (ar.elem (j) / beta.elem (j));
495 for (
F77_INT i = 0; i < nvr; i++)
496 m_v.
elem (i, j) = vr.elem (i, j);
497 for (
F77_INT i = 0; i < nvl; i++)
498 m_w.
elem (i, j) = vl.elem (i, j);
503 (*current_liboctave_error_handler) (
"EIG: internal error");
505 m_lambda.elem (j) =
Complex (ar.elem (j) / beta.elem (j),
506 ai.elem (j) / beta.elem (j));
507 m_lambda.elem (j+1) =
Complex (ar.elem (j+1) / beta.elem (j+1),
508 ai.elem (j+1) / beta.elem (j+1));
510 for (
F77_INT i = 0; i < nvr; i++)
512 double real_part = vr.elem (i, j);
513 double imag_part = vr.elem (i, j+1);
515 m_v.
elem (i, j+1) =
Complex (real_part, -imag_part);
517 for (
F77_INT i = 0; i < nvl; i++)
519 double real_part = vl.elem (i, j);
520 double imag_part = vl.elem (i, j+1);
522 m_w.
elem (i, j+1) =
Complex (real_part, -imag_part);
532 EIG::symmetric_init (
const Matrix& a,
const Matrix& b,
bool calc_rev,
541 if (
n != a_nc || nb != b_nc)
542 (*current_liboctave_error_handler) (
"EIG requires square matrix");
545 (*current_liboctave_error_handler) (
"EIG requires same size matrices");
556 double *pwr = wr.fortran_vec ();
561 F77_XFCN (dsygv, DSYGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
562 F77_CONST_CHAR_ARG2 (
"U", 1),
565 pwr, &dummy_work, lwork, info
567 F77_CHAR_ARG_LEN (1)));
570 (*current_liboctave_error_handler) (
"dsygv workspace query failed");
572 lwork =
static_cast<F77_INT> (dummy_work);
574 double *pwork = work.fortran_vec ();
576 F77_XFCN (dsygv, DSYGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
577 F77_CONST_CHAR_ARG2 (
"U", 1),
580 pwr, pwork, lwork, info
582 F77_CHAR_ARG_LEN (1)));
585 (*current_liboctave_error_handler) (
"unrecoverable error in dsygv");
588 (*current_liboctave_error_handler) (
"dsygv failed to converge");
599 bool calc_lev,
bool force_qz)
602 (*current_liboctave_error_handler)
603 (
"EIG: matrix contains Inf or NaN values");
611 if (
n != a_nc || nb != b_nc)
612 (*current_liboctave_error_handler) (
"EIG requires square matrix");
615 (*current_liboctave_error_handler) (
"EIG requires same size matrices");
624 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
627 F77_CHAR_ARG_LEN (1)));
630 return hermitian_init (a, b, calc_rev, calc_lev);
640 Complex *palpha = alpha.fortran_vec ();
643 Complex *pbeta = beta.fortran_vec ();
647 Complex *pvr = vrtmp.fortran_vec ();
651 Complex *pvl = vltmp.fortran_vec ();
658 double *prwork = rwork.fortran_vec ();
660 F77_XFCN (zggev, ZGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
661 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
671 F77_CHAR_ARG_LEN (1)));
674 (*current_liboctave_error_handler) (
"zggev workspace query failed");
676 lwork =
static_cast<F77_INT> (dummy_work.real ());
678 Complex *pwork = work.fortran_vec ();
680 F77_XFCN (zggev, ZGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ?
"V" :
"N", 1),
681 F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
690 F77_CHAR_ARG_LEN (1)));
693 (*current_liboctave_error_handler) (
"unrecoverable error in zggev");
696 (*current_liboctave_error_handler) (
"zggev failed to converge");
701 m_lambda.elem (j) = alpha.elem (j) / beta.elem (j);
711 bool calc_rev,
bool calc_lev)
719 if (
n != a_nc || nb != b_nc)
720 (*current_liboctave_error_handler) (
"EIG requires square matrix");
723 (*current_liboctave_error_handler) (
"EIG requires same size matrices");
734 double *pwr = wr.fortran_vec ();
741 double *prwork = rwork.fortran_vec ();
743 F77_XFCN (zhegv, ZHEGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
744 F77_CONST_CHAR_ARG2 (
"U", 1),
750 F77_CHAR_ARG_LEN (1)));
753 (*current_liboctave_error_handler) (
"zhegv workspace query failed");
755 lwork =
static_cast<F77_INT> (dummy_work.real ());
757 Complex *pwork = work.fortran_vec ();
759 F77_XFCN (zhegv, ZHEGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ?
"V" :
"N", 1),
760 F77_CONST_CHAR_ARG2 (
"U", 1),
765 F77_CHAR_ARG_LEN (1)));
768 (*current_liboctave_error_handler) (
"unrecoverable error in zhegv");
771 (*current_liboctave_error_handler) (
"zhegv failed to converge");
T & elem(octave_idx_type n)
Size of the specified dimension.
T * fortran_vec()
Size of the specified dimension.
octave_idx_type rows() const
octave_idx_type cols() const
void resize(octave_idx_type n, const Complex &rfv=Complex(0))
void resize(octave_idx_type nr, octave_idx_type nc, const Complex &rfv=Complex(0))
bool any_element_is_inf_or_nan() const
friend class ComplexMatrix
bool any_element_is_inf_or_nan() const
Vector representing the dimensions (size) of an Array.
#define F77_DBLE_CMPLX_ARG(x)
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_INT
void scale(Matrix &m, double x, double y, double z)
std::complex< double > Complex