457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
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 |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #if defined (__GNUG__) |
|
29 #pragma implementation |
|
30 #endif |
|
31 |
|
32 #include "CmplxQR.h" |
|
33 #include "mx-inlines.cc" |
|
34 #include "lo-error.h" |
|
35 #include "f77-uscore.h" |
|
36 |
|
37 extern "C" |
|
38 { |
|
39 int F77_FCN (zgeqrf) (const int*, const int*, Complex*, const int*, |
|
40 Complex*, Complex*, const int*, int*); |
|
41 |
|
42 int F77_FCN (zungqr) (const int*, const int*, const int*, Complex*, |
|
43 const int*, Complex*, Complex*, const int*, int*); |
|
44 } |
|
45 |
539
|
46 ComplexQR::ComplexQR (const ComplexMatrix& a, QR::type qr_type) |
457
|
47 { |
|
48 int m = a.rows (); |
|
49 int n = a.cols (); |
|
50 |
|
51 if (m == 0 || n == 0) |
|
52 { |
|
53 (*current_liboctave_error_handler) |
|
54 ("ComplexQR must have non-empty matrix"); |
|
55 return; |
|
56 } |
|
57 |
|
58 Complex *tmp_data; |
|
59 int min_mn = m < n ? m : n; |
|
60 Complex *tau = new Complex[min_mn]; |
|
61 int lwork = 32*n; |
|
62 Complex *work = new Complex[lwork]; |
|
63 int info = 0; |
|
64 |
|
65 if (m > n) |
|
66 { |
|
67 tmp_data = new Complex [m*m]; |
|
68 copy (tmp_data, a.data (), a.length ()); |
|
69 } |
|
70 else |
|
71 tmp_data = dup (a.data (), a.length ()); |
|
72 |
|
73 F77_FCN (zgeqrf) (&m, &n, tmp_data, &m, tau, work, &lwork, &info); |
|
74 |
|
75 delete [] work; |
|
76 |
539
|
77 if (qr_type == QR::raw) |
|
78 { |
|
79 for (int j = 0; j < min_mn; j++) |
|
80 { |
|
81 int limit = j < min_mn - 1 ? j : min_mn - 1; |
|
82 for (int i = limit + 1; i < m; i++) |
|
83 tmp_data[m*j+i] *= tau[j]; |
|
84 } |
|
85 } |
|
86 else |
457
|
87 { |
539
|
88 int m2; |
|
89 if (qr_type == QR::economy && m > n) |
|
90 { |
|
91 m2 = n; |
|
92 r.resize (n, n, 0.0); |
|
93 } |
|
94 else |
|
95 { |
|
96 m2 = m; |
|
97 r.resize (m, n, 0.0); |
|
98 } |
457
|
99 |
539
|
100 for (int j = 0; j < n; j++) |
|
101 { |
|
102 int limit = j < min_mn-1 ? j : min_mn-1; |
|
103 for (int i = 0; i <= limit; i++) |
|
104 r.elem (i, j) = tmp_data[m*j+i]; |
|
105 } |
457
|
106 |
539
|
107 lwork = 32*m; |
|
108 work = new Complex[lwork]; |
|
109 |
|
110 F77_FCN (zungqr) (&m, &m, &min_mn, tmp_data, &m, tau, work, |
|
111 &lwork, &info); |
457
|
112 |
539
|
113 q = ComplexMatrix (tmp_data, m, m); |
|
114 |
|
115 delete [] tau; |
|
116 delete [] work; |
|
117 } |
457
|
118 } |
|
119 |
|
120 /* |
|
121 ;;; Local Variables: *** |
|
122 ;;; mode: C++ *** |
|
123 ;;; page-delimiter: "^/\\*" *** |
|
124 ;;; End: *** |
|
125 */ |