Mercurial > octave-nkf
annotate liboctave/CmplxQR.cc @ 7482:29980c6b8604
don't check f77_exception_encountered
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 14 Feb 2008 21:57:50 -0500 |
parents | a1dbe9d80eee |
children | 56be6f31dd4e |
rev | line source |
---|---|
457 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007 |
4 John W. Eaton | |
457 | 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. | |
457 | 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/>. | |
457 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
1192 | 25 #include <config.h> |
457 | 26 #endif |
27 | |
28 #include "CmplxQR.h" | |
1847 | 29 #include "f77-fcn.h" |
457 | 30 #include "lo-error.h" |
31 | |
32 extern "C" | |
33 { | |
4552 | 34 F77_RET_T |
5275 | 35 F77_FUNC (zgeqrf, ZGEQRF) (const octave_idx_type&, const octave_idx_type&, Complex*, |
36 const octave_idx_type&, Complex*, Complex*, | |
37 const octave_idx_type&, octave_idx_type&); | |
457 | 38 |
4552 | 39 F77_RET_T |
5275 | 40 F77_FUNC (zungqr, ZUNGQR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
41 Complex*, const octave_idx_type&, Complex*, | |
42 Complex*, const octave_idx_type&, octave_idx_type&); | |
457 | 43 } |
44 | |
539 | 45 ComplexQR::ComplexQR (const ComplexMatrix& a, QR::type qr_type) |
2763 | 46 : q (), r () |
47 { | |
48 init (a, qr_type); | |
49 } | |
50 | |
51 void | |
52 ComplexQR::init (const ComplexMatrix& a, QR::type qr_type) | |
457 | 53 { |
5275 | 54 octave_idx_type m = a.rows (); |
55 octave_idx_type n = a.cols (); | |
457 | 56 |
57 if (m == 0 || n == 0) | |
58 { | |
59 (*current_liboctave_error_handler) | |
60 ("ComplexQR must have non-empty matrix"); | |
61 return; | |
62 } | |
63 | |
5275 | 64 octave_idx_type min_mn = m < n ? m : n; |
1927 | 65 |
66 Array<Complex> tau (min_mn); | |
67 Complex *ptau = tau.fortran_vec (); | |
1921 | 68 |
5275 | 69 octave_idx_type lwork = 32*n; |
1927 | 70 Array<Complex> work (lwork); |
71 Complex *pwork = work.fortran_vec (); | |
1921 | 72 |
5275 | 73 octave_idx_type info = 0; |
457 | 74 |
1927 | 75 ComplexMatrix A_fact; |
3883 | 76 if (m > n && qr_type != QR::economy) |
457 | 77 { |
1927 | 78 A_fact.resize (m, m); |
79 A_fact.insert (a, 0, 0); | |
457 | 80 } |
81 else | |
1927 | 82 A_fact = a; |
457 | 83 |
1927 | 84 Complex *tmp_data = A_fact.fortran_vec (); |
457 | 85 |
1927 | 86 F77_XFCN (zgeqrf, ZGEQRF, (m, n, tmp_data, m, ptau, pwork, lwork, info)); |
457 | 87 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
88 if (qr_type == QR::raw) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
89 { |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
90 for (octave_idx_type j = 0; j < min_mn; j++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 { |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
92 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
|
93 for (octave_idx_type i = limit + 1; i < m; i++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
94 A_fact.elem (i, j) *= tau.elem (j); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
95 } |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
97 r = A_fact; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
98 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 if (m > n) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
100 r.resize (m, n); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
101 } |
539 | 102 else |
457 | 103 { |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m; |
3069 | 105 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 if (qr_type == QR::economy && m > n) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
107 r.resize (n, n, 0.0); |
539 | 108 else |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
109 r.resize (m, n, 0.0); |
1921 | 110 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
111 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
|
112 { |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 } |
457 | 117 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
118 lwork = 32 * n2; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
119 work.resize (lwork); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
120 Complex *pwork2 = work.fortran_vec (); |
457 | 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 pwork2, lwork, info)); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
124 |
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); |
1921 | 127 } |
457 | 128 } |
129 | |
130 /* | |
131 ;;; Local Variables: *** | |
132 ;;; mode: C++ *** | |
133 ;;; End: *** | |
134 */ |