Mercurial > octave
annotate liboctave/CmplxQRP.cc @ 8368:c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 04 Dec 2008 09:15:17 +0100 |
parents | 445d27d79f4e |
children | e3c9102431a9 |
rev | line source |
---|---|
538 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007 |
4 John W. Eaton | |
538 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
538 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
538 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
1192 | 25 #include <config.h> |
538 | 26 #endif |
27 | |
1367 | 28 #include <cassert> |
538 | 29 |
30 #include "CmplxQRP.h" | |
1847 | 31 #include "f77-fcn.h" |
538 | 32 #include "lo-error.h" |
33 | |
34 extern "C" | |
35 { | |
4552 | 36 F77_RET_T |
8368
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
37 F77_FUNC (zgeqp3, ZGEQP3) (const octave_idx_type&, const octave_idx_type&, Complex*, |
5275 | 38 const octave_idx_type&, octave_idx_type*, Complex*, Complex*, |
8368
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
39 const octave_idx_type&, double*, octave_idx_type&); |
567 | 40 |
4552 | 41 F77_RET_T |
5275 | 42 F77_FUNC (zungqr, ZUNGQR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
43 Complex*, const octave_idx_type&, Complex*, | |
44 Complex*, const octave_idx_type&, octave_idx_type&); | |
538 | 45 } |
46 | |
47 // It would be best to share some of this code with ComplexQR class... | |
48 | |
49 ComplexQRP::ComplexQRP (const ComplexMatrix& a, QR::type qr_type) | |
2763 | 50 : ComplexQR (), p () |
51 { | |
52 init (a, qr_type); | |
53 } | |
54 | |
55 void | |
56 ComplexQRP::init (const ComplexMatrix& a, QR::type qr_type) | |
538 | 57 { |
58 assert (qr_type != QR::raw); | |
59 | |
5275 | 60 octave_idx_type m = a.rows (); |
61 octave_idx_type n = a.cols (); | |
538 | 62 |
63 if (m == 0 || n == 0) | |
64 { | |
65 (*current_liboctave_error_handler) | |
66 ("ComplexQR must have non-empty matrix"); | |
67 return; | |
68 } | |
69 | |
5275 | 70 octave_idx_type min_mn = m < n ? m : n; |
3883 | 71 Array<Complex> tau (min_mn); |
1928 | 72 Complex *ptau = tau.fortran_vec (); |
1922 | 73 |
5275 | 74 octave_idx_type info = 0; |
538 | 75 |
2763 | 76 ComplexMatrix A_fact = a; |
3883 | 77 if (m > n && qr_type != QR::economy) |
2763 | 78 A_fact.resize (m, m, 0.0); |
538 | 79 |
1928 | 80 Complex *tmp_data = A_fact.fortran_vec (); |
538 | 81 |
1928 | 82 Array<double> rwork (2*n); |
83 double *prwork = rwork.fortran_vec (); | |
538 | 84 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
85 MArray<octave_idx_type> jpvt (n, 0); |
5275 | 86 octave_idx_type *pjpvt = jpvt.fortran_vec (); |
538 | 87 |
8368
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
88 Complex rlwork = 0; |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
89 // Workspace query... |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
90 F77_XFCN (zgeqp3, ZGEQP3, (m, n, tmp_data, m, pjpvt, ptau, &rlwork, |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
91 -1, prwork, info)); |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
92 |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
93 octave_idx_type lwork = rlwork.real (); |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
94 Array<Complex> work (lwork); |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
95 Complex *pwork = work.fortran_vec (); |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
96 |
1928 | 97 // Code to enforce a certain permutation could go here... |
538 | 98 |
8368
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
99 F77_XFCN (zgeqp3, ZGEQP3, (m, n, tmp_data, m, pjpvt, ptau, pwork, |
c72c1c9bccdc
call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
100 lwork, prwork, info)); |
1922 | 101 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
102 // Form Permutation matrix (if economy is requested, return the |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 // indices only!) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
105 jpvt -= 1; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
106 p = PermMatrix (jpvt, true); |
1922 | 107 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
108 octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m; |
1922 | 109 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
110 if (qr_type == QR::economy && m > n) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
111 r.resize (n, n, 0.0); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
112 else |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
113 r.resize (m, n, 0.0); |
3883 | 114 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
115 for (octave_idx_type j = 0; j < n; j++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
116 { |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
117 octave_idx_type limit = j < min_mn-1 ? j : min_mn-1; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
118 for (octave_idx_type i = 0; i <= limit; i++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
119 r.elem (i, j) = A_fact.elem (i, j); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
120 } |
1922 | 121 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
122 F77_XFCN (zungqr, ZUNGQR, (m, n2, min_mn, tmp_data, m, ptau, |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
123 pwork, lwork, info)); |
1922 | 124 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
125 q = A_fact; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
126 q.resize (m, n2); |
538 | 127 } |
128 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
129 ColumnVector |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
130 ComplexQRP::Pvec (void) const |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
131 { |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
132 Array<double> pa (p); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
133 ColumnVector pv (MArray<double> (pa) + 1.0); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
134 return pv; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
135 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
136 |
538 | 137 /* |
138 ;;; Local Variables: *** | |
139 ;;; mode: C++ *** | |
140 ;;; End: *** | |
141 */ |