457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
457
|
26 #endif |
|
27 |
|
28 #include "CmplxQR.h" |
|
29 #include "mx-inlines.cc" |
|
30 #include "lo-error.h" |
|
31 #include "f77-uscore.h" |
|
32 |
|
33 extern "C" |
|
34 { |
1251
|
35 int F77_FCN (zgeqrf) (const int&, const int&, Complex*, const int&, |
|
36 Complex*, Complex*, const int&, int&); |
457
|
37 |
1251
|
38 int F77_FCN (zungqr) (const int&, const int&, const int&, Complex*, |
|
39 const int&, Complex*, Complex*, const int&, int&); |
457
|
40 } |
|
41 |
539
|
42 ComplexQR::ComplexQR (const ComplexMatrix& a, QR::type qr_type) |
457
|
43 { |
|
44 int m = a.rows (); |
|
45 int n = a.cols (); |
|
46 |
|
47 if (m == 0 || n == 0) |
|
48 { |
|
49 (*current_liboctave_error_handler) |
|
50 ("ComplexQR must have non-empty matrix"); |
|
51 return; |
|
52 } |
|
53 |
|
54 Complex *tmp_data; |
|
55 int min_mn = m < n ? m : n; |
|
56 Complex *tau = new Complex[min_mn]; |
|
57 int lwork = 32*n; |
|
58 Complex *work = new Complex[lwork]; |
|
59 int info = 0; |
|
60 |
|
61 if (m > n) |
|
62 { |
|
63 tmp_data = new Complex [m*m]; |
|
64 copy (tmp_data, a.data (), a.length ()); |
|
65 } |
|
66 else |
|
67 tmp_data = dup (a.data (), a.length ()); |
|
68 |
1251
|
69 F77_FCN (zgeqrf) (m, n, tmp_data, m, tau, work, lwork, info); |
457
|
70 |
|
71 delete [] work; |
|
72 |
539
|
73 if (qr_type == QR::raw) |
|
74 { |
|
75 for (int j = 0; j < min_mn; j++) |
|
76 { |
|
77 int limit = j < min_mn - 1 ? j : min_mn - 1; |
|
78 for (int i = limit + 1; i < m; i++) |
|
79 tmp_data[m*j+i] *= tau[j]; |
|
80 } |
|
81 } |
|
82 else |
457
|
83 { |
1011
|
84 int n2; |
539
|
85 if (qr_type == QR::economy && m > n) |
|
86 { |
1011
|
87 n2 = n; |
539
|
88 r.resize (n, n, 0.0); |
|
89 } |
|
90 else |
|
91 { |
1011
|
92 n2 = m; |
539
|
93 r.resize (m, n, 0.0); |
|
94 } |
457
|
95 |
539
|
96 for (int j = 0; j < n; j++) |
|
97 { |
|
98 int limit = j < min_mn-1 ? j : min_mn-1; |
|
99 for (int i = 0; i <= limit; i++) |
|
100 r.elem (i, j) = tmp_data[m*j+i]; |
|
101 } |
457
|
102 |
539
|
103 lwork = 32*m; |
|
104 work = new Complex[lwork]; |
|
105 |
1251
|
106 F77_FCN (zungqr) (m, m, min_mn, tmp_data, m, tau, work, lwork, info); |
457
|
107 |
539
|
108 q = ComplexMatrix (tmp_data, m, m); |
1011
|
109 q.resize (m, n2); |
539
|
110 |
|
111 delete [] tau; |
|
112 delete [] work; |
|
113 } |
457
|
114 } |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; page-delimiter: "^/\\*" *** |
|
120 ;;; End: *** |
|
121 */ |