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 "dbleQR.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 (dgeqrf) (const int*, const int*, double*, const int*, |
|
40 double*, double*, const int*, int*); |
|
41 |
|
42 int F77_FCN (dorgqr) (const int*, const int*, const int*, double*, |
|
43 const int*, double*, double*, const int*, int*); |
|
44 } |
|
45 |
|
46 QR::QR (const Matrix& 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) ("QR must have non-empty matrix"); |
|
54 return; |
|
55 } |
|
56 |
|
57 double *tmp_data; |
|
58 int min_mn = m < n ? m : n; |
|
59 double *tau = new double[min_mn]; |
|
60 int lwork = 32*n; |
|
61 double *work = new double[lwork]; |
|
62 int info = 0; |
|
63 |
|
64 if (m > n) |
|
65 { |
|
66 tmp_data = new double [m*m]; |
|
67 copy (tmp_data, a.data (), a.length ()); |
|
68 } |
|
69 else |
|
70 tmp_data = dup (a.data (), a.length ()); |
|
71 |
|
72 F77_FCN (dgeqrf) (&m, &n, tmp_data, &m, tau, work, &lwork, &info); |
|
73 |
|
74 delete [] work; |
|
75 |
|
76 r.resize (m, n, 0.0); |
|
77 for (int j = 0; j < n; j++) |
|
78 { |
|
79 int limit = j < min_mn-1 ? j : min_mn-1; |
|
80 for (int i = 0; i <= limit; i++) |
|
81 r.elem (i, j) = tmp_data[m*j+i]; |
|
82 } |
|
83 |
|
84 lwork = 32*m; |
|
85 work = new double[lwork]; |
|
86 |
|
87 F77_FCN (dorgqr) (&m, &m, &min_mn, tmp_data, &m, tau, work, &lwork, &info); |
|
88 |
|
89 q = Matrix (tmp_data, m, m); |
|
90 |
|
91 delete [] tau; |
|
92 delete [] work; |
|
93 } |
|
94 |
|
95 /* |
|
96 ;;; Local Variables: *** |
|
97 ;;; mode: C++ *** |
|
98 ;;; page-delimiter: "^/\\*" *** |
|
99 ;;; End: *** |
|
100 */ |