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 "CmplxLU.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 (zgesv, ZGESV) (const int&, const int&, Complex*, |
|
40 const int&, int*, Complex*, const int&, |
|
41 int&); |
457
|
42 } |
|
43 |
|
44 ComplexLU::ComplexLU (const ComplexMatrix& a) |
|
45 { |
|
46 int a_nr = a.rows (); |
|
47 int a_nc = a.cols (); |
|
48 if (a_nr == 0 || a_nc == 0 || a_nr != a_nc) |
|
49 { |
|
50 (*current_liboctave_error_handler) ("ComplexLU requires square matrix"); |
|
51 return; |
|
52 } |
|
53 |
|
54 int n = a_nr; |
|
55 |
|
56 int *ipvt = new int [n]; |
|
57 int *pvt = new int [n]; |
|
58 Complex *tmp_data = dup (a.data (), a.length ()); |
|
59 int info = 0; |
1365
|
60 Complex *dummy = 0; |
457
|
61 |
1365
|
62 F77_FCN (zgesv, ZGESV) (n, 0, tmp_data, n, ipvt, dummy, n, info); |
457
|
63 |
|
64 ComplexMatrix A_fact (tmp_data, n, n); |
|
65 |
1321
|
66 for (int i = 0; i < n; i++) |
457
|
67 { |
|
68 ipvt[i] -= 1; |
|
69 pvt[i] = i; |
|
70 } |
|
71 |
1321
|
72 for (int i = 0; i < n - 1; i++) |
457
|
73 { |
|
74 int k = ipvt[i]; |
|
75 if (k != i) |
|
76 { |
|
77 int tmp = pvt[k]; |
|
78 pvt[k] = pvt[i]; |
|
79 pvt[i] = tmp; |
|
80 } |
|
81 } |
|
82 |
|
83 l.resize (n, n, 0.0); |
|
84 u.resize (n, n, 0.0); |
|
85 p.resize (n, n, 0.0); |
|
86 |
1321
|
87 for (int i = 0; i < n; i++) |
457
|
88 { |
|
89 p.elem (i, pvt[i]) = 1.0; |
|
90 |
|
91 l.elem (i, i) = 1.0; |
1321
|
92 for (int j = 0; j < i; j++) |
457
|
93 l.elem (i, j) = A_fact.elem (i, j); |
|
94 |
1321
|
95 for (int j = i; j < n; j++) |
457
|
96 u.elem (i, j) = A_fact.elem (i, j); |
|
97 } |
|
98 |
|
99 delete [] ipvt; |
|
100 delete [] pvt; |
|
101 } |
|
102 |
|
103 /* |
|
104 ;;; Local Variables: *** |
|
105 ;;; mode: C++ *** |
|
106 ;;; page-delimiter: "^/\\*" *** |
|
107 ;;; End: *** |
|
108 */ |