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 (); |
1919
|
48 |
457
|
49 if (a_nr == 0 || a_nc == 0 || a_nr != a_nc) |
|
50 { |
|
51 (*current_liboctave_error_handler) ("ComplexLU requires square matrix"); |
|
52 return; |
|
53 } |
|
54 |
|
55 int n = a_nr; |
|
56 |
1926
|
57 Array<int> ipvt (n); |
|
58 |
|
59 int *pipvt = ipvt.fortran_vec (); |
1919
|
60 |
|
61 ComplexMatrix A_fact = a; |
|
62 Complex *tmp_data = A_fact.fortran_vec (); |
|
63 |
457
|
64 int info = 0; |
1365
|
65 Complex *dummy = 0; |
457
|
66 |
1926
|
67 F77_XFCN (zgesv, ZGESV, (n, 0, tmp_data, n, pipvt, dummy, n, info)); |
457
|
68 |
1919
|
69 if (f77_exception_encountered) |
|
70 (*current_liboctave_error_handler) ("unrecoverable error in zgesv"); |
|
71 else |
457
|
72 { |
1926
|
73 Array<int> pvt (n); |
|
74 |
1919
|
75 for (int i = 0; i < n; i++) |
|
76 { |
1926
|
77 ipvt.elem (i) -= 1; |
|
78 pvt.elem (i) = i; |
1919
|
79 } |
457
|
80 |
1919
|
81 for (int i = 0; i < n - 1; i++) |
457
|
82 { |
1926
|
83 int k = ipvt.elem (i); |
|
84 |
1919
|
85 if (k != i) |
|
86 { |
1926
|
87 int tmp = pvt.elem (k); |
|
88 pvt.elem (k) = pvt.elem (i); |
|
89 pvt.elem (i)= tmp; |
1919
|
90 } |
|
91 } |
|
92 |
|
93 l.resize (n, n, 0.0); |
|
94 u.resize (n, n, 0.0); |
|
95 p.resize (n, n, 0.0); |
|
96 |
|
97 for (int i = 0; i < n; i++) |
|
98 { |
1926
|
99 p.elem (i, pvt.elem (i)) = 1.0; |
1919
|
100 |
|
101 l.elem (i, i) = 1.0; |
|
102 for (int j = 0; j < i; j++) |
|
103 l.elem (i, j) = A_fact.elem (i, j); |
|
104 |
|
105 for (int j = i; j < n; j++) |
|
106 u.elem (i, j) = A_fact.elem (i, j); |
457
|
107 } |
|
108 } |
|
109 } |
|
110 |
|
111 /* |
|
112 ;;; Local Variables: *** |
|
113 ;;; mode: C++ *** |
|
114 ;;; page-delimiter: "^/\\*" *** |
|
115 ;;; End: *** |
|
116 */ |