Mercurial > hg > octave-lojdl
changeset 1927:e379c781ae7e
[project @ 1996-02-11 21:39:27 by jwe]
author | jwe |
---|---|
date | Sun, 11 Feb 1996 21:39:27 +0000 |
parents | 3ce2c289c978 |
children | 20353fa5f83d |
files | liboctave/CmplxQR.cc liboctave/CmplxQR.h liboctave/dbleQR.cc liboctave/dbleQR.h |
diffstat | 4 files changed, 36 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CmplxQR.cc +++ b/liboctave/CmplxQR.cc @@ -47,10 +47,6 @@ ComplexQR::ComplexQR (const ComplexMatrix& a, QR::type qr_type) { - tau = 0; - work = 0; - tmp_data = 0; - int m = a.rows (); int n = a.cols (); @@ -62,25 +58,28 @@ } int min_mn = m < n ? m : n; - tau = new Complex[min_mn]; + + Array<Complex> tau (min_mn); + Complex *ptau = tau.fortran_vec (); int lwork = 32*n; - work = new Complex[lwork]; + Array<Complex> work (lwork); + Complex *pwork = work.fortran_vec (); int info = 0; + ComplexMatrix A_fact; if (m > n) { - tmp_data = new Complex [m*m]; - copy (tmp_data, a.data (), a.length ()); + A_fact.resize (m, m); + A_fact.insert (a, 0, 0); } else - tmp_data = dup (a.data (), a.length ()); + A_fact = a; - F77_XFCN (zgeqrf, ZGEQRF, (m, n, tmp_data, m, tau, work, lwork, info)); + Complex *tmp_data = A_fact.fortran_vec (); - delete [] work; - work = 0; + F77_XFCN (zgeqrf, ZGEQRF, (m, n, tmp_data, m, ptau, pwork, lwork, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in zgeqrf"); @@ -92,7 +91,7 @@ { int limit = j < min_mn - 1 ? j : min_mn - 1; for (int i = limit + 1; i < m; i++) - tmp_data[m*j+i] *= tau[j]; + A_fact.elem (i, j) *= tau.elem (j); } } else @@ -114,17 +113,15 @@ { int limit = j < min_mn-1 ? j : min_mn-1; for (int i = 0; i <= limit; i++) - r.elem (i, j) = tmp_data[m*j+i]; + r.elem (i, j) = A_fact.elem (i, j); } lwork = 32*m; - work = new Complex[lwork]; + work.resize (lwork); + Complex *pwork = work.fortran_vec (); - F77_XFCN (zungqr, ZUNGQR, (m, m, min_mn, tmp_data, m, tau, work, - lwork, info)); - - delete [] work; - work = 0; + F77_XFCN (zungqr, ZUNGQR, (m, m, min_mn, tmp_data, m, ptau, + pwork, lwork, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) @@ -132,17 +129,10 @@ else { q = ComplexMatrix (tmp_data, m, m); - tmp_data = 0; q.resize (m, n2); } } } - - delete [] tau; - tau = 0; - - delete [] tmp_data; - tmp_data = 0; } /*
--- a/liboctave/CmplxQR.h +++ b/liboctave/CmplxQR.h @@ -38,7 +38,7 @@ { public: - ComplexQR (void) : q (), r (), tau (0), work (0), tmp_data (0) { } + ComplexQR (void) : q (), r () { } ComplexQR (const ComplexMatrix& A, QR::type qr_type = QR::std); @@ -54,12 +54,7 @@ return *this; } - ~ComplexQR (void) - { - delete [] tau; - delete [] work; - delete [] tmp_data; - } + ~ComplexQR (void) { } ComplexMatrix Q (void) const { return q; } ComplexMatrix R (void) const { return r; } @@ -70,10 +65,6 @@ ComplexMatrix q; ComplexMatrix r; - - Complex *tau; - Complex *work; - Complex *tmp_data; }; #endif
--- a/liboctave/dbleQR.cc +++ b/liboctave/dbleQR.cc @@ -47,10 +47,6 @@ QR::QR (const Matrix& a, QR::type qr_type) { - tau = 0; - work = 0; - tmp_data = 0; - int m = a.rows (); int n = a.cols (); @@ -61,25 +57,27 @@ } int min_mn = m < n ? m : n; - tau = new double[min_mn]; + Array<double> tau (min_mn); + double *ptau = tau.fortran_vec (); int lwork = 32*n; - work = new double[lwork]; + Array<double> work (lwork); + double *pwork = work.fortran_vec (); int info = 0; + Matrix A_fact; if (m > n) { - tmp_data = new double [m*m]; - copy (tmp_data, a.data (), a.length ()); + A_fact.resize (m, m); + A_fact.insert (a, 0, 0); } else - tmp_data = dup (a.data (), a.length ()); + A_fact = a; - F77_XFCN (dgeqrf, DGEQRF, (m, n, tmp_data, m, tau, work, lwork, info)); + double *tmp_data = A_fact.fortran_vec (); - delete [] work; - work = 0; + F77_XFCN (dgeqrf, DGEQRF, (m, n, tmp_data, m, ptau, pwork, lwork, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in dgeqrf"); @@ -91,7 +89,7 @@ { int limit = j < min_mn - 1 ? j : min_mn - 1; for (int i = limit + 1; i < m; i++) - tmp_data[m*j+i] *= tau[j]; + A_fact.elem (i, j) *= tau.elem (j); } } else @@ -117,13 +115,11 @@ } lwork = 32*m; - work = new double[lwork]; + work.resize (lwork); + double *pwork = work.fortran_vec (); - F77_XFCN (dorgqr, DORGQR, (m, m, min_mn, tmp_data, m, tau, work, - lwork, info)); - - delete [] work; - work = 0; + F77_XFCN (dorgqr, DORGQR, (m, m, min_mn, tmp_data, m, ptau, + pwork, lwork, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) @@ -131,17 +127,10 @@ else { q = Matrix (tmp_data, m, m); - tmp_data = 0; q.resize (m, n2); } } } - - delete [] tau; - tau = 0; - - delete [] tmp_data; - tmp_data = 0; } /*
--- a/liboctave/dbleQR.h +++ b/liboctave/dbleQR.h @@ -44,7 +44,7 @@ economy, }; - QR (void) : q (), r (), tau (0), work (0), tmp_data (0) { } + QR (void) : q (), r () { } QR (const Matrix& A, type qr_type = QR::std); @@ -60,12 +60,7 @@ return *this; } - ~QR (void) - { - delete [] tau; - delete [] work; - delete [] tmp_data; - } + ~QR (void) { } Matrix Q (void) const { return q; } @@ -77,10 +72,6 @@ Matrix q; Matrix r; - - double *tau; - double *work; - double *tmp_data; }; #endif