Mercurial > hg > octave-nkf
diff liboctave/CmplxHESS.cc @ 1932:682f31b20894
[project @ 1996-02-12 02:26:07 by jwe]
author | jwe |
---|---|
date | Mon, 12 Feb 1996 02:26:07 +0000 |
parents | 1281a23a34dd |
children | 1b57120c997b |
line wrap: on
line diff
--- a/liboctave/CmplxHESS.cc +++ b/liboctave/CmplxHESS.cc @@ -60,59 +60,82 @@ { int a_nr = a.rows (); int a_nc = a.cols (); - if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("ComplexHESS requires square matrix"); - return -1; - } + + if (a_nr != a_nc) + { + (*current_liboctave_error_handler) + ("ComplexHESS requires square matrix"); + return -1; + } - char *job = "N"; - char *side = "R"; + char job = 'N'; + char side = 'R'; + + int n = a_nc; + int lwork = 32 * n; + int info; + int ilo; + int ihi; - int n = a_nc; - int lwork = 32 * n; - int info; - int ilo; - int ihi; + hess_mat = a; + Complex *h = hess_mat.fortran_vec (); - Complex *h = dup (a.data (), a.length ()); + Array<double> scale (n); + double *pscale = scale.fortran_vec (); + + F77_XFCN (zgebal, ZGEBAL, (&job, n, h, n, ilo, ihi, pscale, info, + 1L, 1L)); - double *scale = new double [n]; - Complex *tau = new Complex [n-1]; - Complex *work = new Complex [lwork]; - Complex *z = new Complex [n*n]; + if (f77_exception_encountered) + (*current_liboctave_error_handler) ("unrecoverable error in zgebal"); + else + { + Array<Complex> tau (n-1); + Complex *ptau = tau.fortran_vec (); - F77_FCN (zgebal, ZGEBAL) (job, n, h, n, ilo, ihi, scale, info, 1L, - 1L); + Array<Complex> work (lwork); + Complex *pwork = work.fortran_vec (); - F77_FCN (zgehrd, ZGEHRD) (n, ilo, ihi, h, n, tau, work, lwork, - info, 1L, 1L); - - copy (z, h, n*n); + F77_XFCN (zgehrd, ZGEHRD, (n, ilo, ihi, h, n, ptau, pwork, lwork, + info, 1L, 1L)); - F77_FCN (zunghr, ZUNGHR) (n, ilo, ihi, z, n, tau, work, lwork, - info, 1L, 1L); + if (f77_exception_encountered) + (*current_liboctave_error_handler) ("unrecoverable error in zgehrd"); + else + { + unitary_hess_mat = hess_mat; + Complex *z = unitary_hess_mat.fortran_vec (); - F77_FCN (zgebak, ZGEBAK) (job, side, n, ilo, ihi, scale, n, z, n, - info, 1L, 1L); - - hess_mat = ComplexMatrix (h, n, n); - unitary_hess_mat = ComplexMatrix (z, n, n); + F77_XFCN (zunghr, ZUNGHR, (n, ilo, ihi, z, n, ptau, pwork, + lwork, info, 1L, 1L)); - // If someone thinks of a more graceful way of doing this (or faster - // for that matter :-)), please let me know! + if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("unrecoverable error in zunghr"); + else + { + F77_XFCN (zgebak, ZGEBAK, (&job, &side, n, ilo, ihi, + pscale, n, z, n, info, 1L, 1L)); - if (n > 2) - for (int j = 0; j < a_nc; j++) - for (int i = j+2; i < a_nr; i++) - hess_mat.elem (i, j) = 0; + if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("unrecoverable error in zgebak"); + else + { + // If someone thinks of a more graceful way of + // doing this (or faster for that matter :-)), + // please let me know! - delete [] work; - delete [] tau; - delete [] scale; + if (n > 2) + for (int j = 0; j < a_nc; j++) + for (int i = j+2; i < a_nr; i++) + hess_mat.elem (i, j) = 0; + } + } + } + } - return info; + return info; } /*