Mercurial > hg > octave-lyh
annotate liboctave/base-lu.cc @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 445d27d79f4e |
children | 50db3c5175b5 |
rev | line source |
---|---|
1991 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2002, 2003, 2004, 2005, 2007, 2008 John W. Eaton |
1991 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1991 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1991 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "base-lu.h" | |
28 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
29 template <class lu_type> |
1991 | 30 lu_type |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
31 base_lu <lu_type> :: L (void) const |
1991 | 32 { |
5275 | 33 octave_idx_type a_nr = a_fact.rows (); |
34 octave_idx_type a_nc = a_fact.cols (); | |
35 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); | |
1991 | 36 |
4329 | 37 lu_type l (a_nr, mn, lu_elt_type (0.0)); |
1991 | 38 |
5275 | 39 for (octave_idx_type i = 0; i < a_nr; i++) |
1991 | 40 { |
4811 | 41 if (i < a_nc) |
42 l.xelem (i, i) = 1.0; | |
43 | |
5275 | 44 for (octave_idx_type j = 0; j < (i < a_nc ? i : a_nc); j++) |
1991 | 45 l.xelem (i, j) = a_fact.xelem (i, j); |
46 } | |
47 | |
48 return l; | |
49 } | |
50 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
51 template <class lu_type> |
1991 | 52 lu_type |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
53 base_lu <lu_type> :: U (void) const |
1991 | 54 { |
5275 | 55 octave_idx_type a_nr = a_fact.rows (); |
56 octave_idx_type a_nc = a_fact.cols (); | |
57 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); | |
1991 | 58 |
4329 | 59 lu_type u (mn, a_nc, lu_elt_type (0.0)); |
60 | |
5275 | 61 for (octave_idx_type i = 0; i < mn; i++) |
1991 | 62 { |
5275 | 63 for (octave_idx_type j = i; j < a_nc; j++) |
1991 | 64 u.xelem (i, j) = a_fact.xelem (i, j); |
65 } | |
66 | |
67 return u; | |
68 } | |
69 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
70 template <class lu_type> |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
71 Array<octave_idx_type> |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
72 base_lu <lu_type> :: getp (void) const |
1991 | 73 { |
5275 | 74 octave_idx_type a_nr = a_fact.rows (); |
1991 | 75 |
5275 | 76 Array<octave_idx_type> pvt (a_nr); |
1991 | 77 |
5275 | 78 for (octave_idx_type i = 0; i < a_nr; i++) |
1991 | 79 pvt.xelem (i) = i; |
80 | |
5275 | 81 for (octave_idx_type i = 0; i < ipvt.length(); i++) |
1991 | 82 { |
5275 | 83 octave_idx_type k = ipvt.xelem (i); |
1991 | 84 |
85 if (k != i) | |
86 { | |
5275 | 87 octave_idx_type tmp = pvt.xelem (k); |
1991 | 88 pvt.xelem (k) = pvt.xelem (i); |
89 pvt.xelem (i) = tmp; | |
90 } | |
91 } | |
92 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
93 return pvt; |
1991 | 94 } |
95 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
96 template <class lu_type> |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
97 PermMatrix |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
98 base_lu <lu_type> :: P (void) const |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
99 { |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
100 return PermMatrix (getp (), false); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
101 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
102 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
103 template <class lu_type> |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
104 ColumnVector |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
105 base_lu <lu_type> :: P_vec (void) const |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
106 { |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
107 octave_idx_type a_nr = a_fact.rows (); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
108 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
109 ColumnVector p (a_nr); |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
110 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
111 Array<octave_idx_type> pvt = getp (); |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
112 |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 for (octave_idx_type i = 0; i < a_nr; i++) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 p.xelem (i) = static_cast<double> (pvt.xelem (i) + 1); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 return p; |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 } |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 |
1991 | 119 /* |
120 ;;; Local Variables: *** | |
121 ;;; mode: C++ *** | |
122 ;;; End: *** | |
123 */ |