457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 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 |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
457
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
457
|
30 #endif |
|
31 |
|
32 #include "dbleLU.h" |
1847
|
33 #include "f77-fcn.h" |
457
|
34 #include "lo-error.h" |
1368
|
35 #include "mx-inlines.cc" |
457
|
36 |
|
37 extern "C" |
|
38 { |
1253
|
39 int F77_FCN (dgesv, DGESV) (const int&, const int&, double*, |
|
40 const int&, int*, double&, const int&, |
|
41 int&); |
457
|
42 } |
|
43 |
|
44 LU::LU (const Matrix& a) |
|
45 { |
|
46 int a_nr = a.rows (); |
|
47 int a_nc = a.cols (); |
1919
|
48 |
457
|
49 if (a_nr == 0 || a_nc == 0 || a_nr != a_nc) |
|
50 { |
|
51 (*current_liboctave_error_handler) ("LU requires square matrix"); |
|
52 return; |
|
53 } |
|
54 |
|
55 int n = a_nr; |
|
56 |
1926
|
57 Array<int> ipvt (n); |
|
58 int *pipvt = ipvt.fortran_vec (); |
1919
|
59 |
|
60 Matrix A_fact = a; |
|
61 double *tmp_data = A_fact.fortran_vec (); |
|
62 |
457
|
63 int info = 0; |
1365
|
64 double dummy = 0; |
457
|
65 |
1926
|
66 F77_XFCN (dgesv, DGESV, (n, 0, tmp_data, n, pipvt, dummy, n, info)); |
457
|
67 |
1919
|
68 if (f77_exception_encountered) |
|
69 (*current_liboctave_error_handler) ("unrecoverable error in dgesv"); |
|
70 else |
457
|
71 { |
1926
|
72 Array<int> pvt (n); |
|
73 |
1919
|
74 for (int i = 0; i < n; i++) |
|
75 { |
1926
|
76 ipvt.elem (i) -= 1; |
|
77 pvt.elem (i) = i; |
1919
|
78 } |
457
|
79 |
1919
|
80 for (int i = 0; i < n - 1; i++) |
457
|
81 { |
1926
|
82 int k = ipvt.elem (i); |
1919
|
83 if (k != i) |
|
84 { |
1926
|
85 int tmp = pvt.elem (k); |
|
86 pvt.elem (k) = pvt.elem (i); |
|
87 pvt.elem (i) = tmp; |
1919
|
88 } |
|
89 } |
|
90 |
|
91 l.resize (n, n, 0.0); |
|
92 u.resize (n, n, 0.0); |
|
93 p.resize (n, n, 0.0); |
|
94 |
|
95 for (int i = 0; i < n; i++) |
|
96 { |
1926
|
97 p.elem (i, pvt.elem (i)) = 1.0; |
1919
|
98 |
|
99 l.elem (i, i) = 1.0; |
|
100 for (int j = 0; j < i; j++) |
|
101 l.elem (i, j) = A_fact.elem (i, j); |
|
102 |
|
103 for (int j = i; j < n; j++) |
|
104 u.elem (i, j) = A_fact.elem (i, j); |
457
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 /* |
|
110 ;;; Local Variables: *** |
|
111 ;;; mode: C++ *** |
|
112 ;;; page-delimiter: "^/\\*" *** |
|
113 ;;; End: *** |
|
114 */ |