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 |
|
46 ComplexQR::ComplexQR (const ComplexMatrix& a) |
|
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 |
|
77 r.resize (m, n, 0.0); |
|
78 for (int j = 0; j < n; j++) |
|
79 { |
|
80 int limit = j < min_mn-1 ? j : min_mn-1; |
|
81 for (int i = 0; i <= limit; i++) |
|
82 r.elem (i, j) = tmp_data[m*j+i]; |
|
83 } |
|
84 |
|
85 lwork = 32*m; |
|
86 work = new Complex[lwork]; |
|
87 |
|
88 F77_FCN (zungqr) (&m, &m, &min_mn, tmp_data, &m, tau, work, &lwork, &info); |
|
89 |
|
90 q = ComplexMatrix (tmp_data, m, m); |
|
91 |
|
92 delete [] tau; |
|
93 delete [] work; |
|
94 } |
|
95 |
|
96 /* |
|
97 ;;; Local Variables: *** |
|
98 ;;; mode: C++ *** |
|
99 ;;; page-delimiter: "^/\\*" *** |
|
100 ;;; End: *** |
|
101 */ |