Mercurial > octave-antonio
annotate liboctave/sparse-base-chol.h @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 9a308e96194e |
children | 12df7854fa7c |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2005-2011 David Bateman |
4 Copyright (C) 1998-2005 Andy Adler | |
7016 | 5 |
6 This file is part of Octave. | |
5506 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5506 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5506 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_sparse_base_chol_h) | |
25 #define octave_sparse_base_chol_h 1 | |
26 | |
27 #include "oct-sparse.h" | |
28 #include "dColVector.h" | |
29 | |
30 template <class chol_type, class chol_elt, class p_type> | |
31 class | |
32 sparse_base_chol | |
33 { | |
34 protected: | |
5512 | 35 #ifdef HAVE_CHOLMOD |
5506 | 36 class sparse_base_chol_rep |
37 { | |
38 public: | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
39 sparse_base_chol_rep (void) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
40 : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0), |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
41 perms (), cond (0) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
42 { } |
5512 | 43 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
44 sparse_base_chol_rep (const chol_type& a, const bool natural) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
45 : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0), |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
46 perms (), cond (0) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
47 { |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
48 init (a, natural); |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
49 } |
5506 | 50 |
51 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
52 const bool natural) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
53 : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0), |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
54 perms (), cond (0) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
55 { |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
56 info = init (a, natural); |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
57 } |
5506 | 58 |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7520
diff
changeset
|
59 ~sparse_base_chol_rep (void) |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
60 { |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
61 if (is_pd) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
62 CHOLMOD_NAME (free_sparse) (&Lsparse, &Common); |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
63 } |
5506 | 64 |
65 cholmod_sparse * L (void) const { return Lsparse; } | |
5512 | 66 |
5506 | 67 octave_idx_type P (void) const |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
68 { |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
69 return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
70 0 : minor_p + 1); |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
71 } |
5506 | 72 |
73 ColumnVector perm (void) const { return perms + 1; } | |
74 | |
75 p_type Q (void) const; | |
76 | |
77 bool is_positive_definite (void) const { return is_pd; } | |
78 | |
79 double rcond (void) const { return cond; } | |
80 | |
81 int count; | |
82 | |
83 private: | |
84 cholmod_sparse *Lsparse; | |
85 | |
86 cholmod_common Common; | |
5512 | 87 |
5506 | 88 bool is_pd; |
89 | |
90 octave_idx_type minor_p; | |
91 | |
92 ColumnVector perms; | |
93 | |
94 double cond; | |
95 | |
96 octave_idx_type init (const chol_type& a, bool natural = true); | |
97 | |
98 void drop_zeros (const cholmod_sparse* S); | |
99 | |
100 // No assignment | |
101 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); | |
102 }; | |
5512 | 103 #else |
104 class sparse_base_chol_rep | |
105 { | |
106 public: | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
107 sparse_base_chol_rep (void) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
108 : count (1), is_pd (false), minor_p (0), perms (), cond (0) { } |
5512 | 109 |
110 sparse_base_chol_rep (const chol_type& a, | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
111 const bool natural) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
112 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
5512 | 113 { init (a, natural); } |
114 | |
115 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
116 const bool natural) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
117 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
5512 | 118 { info = init (a, natural); } |
119 | |
120 ~sparse_base_chol_rep (void) { } | |
121 | |
122 octave_idx_type P (void) const { return 0; } | |
123 | |
124 ColumnVector perm (void) const { return perms + 1; } | |
125 | |
126 p_type Q (void) const; | |
127 | |
128 bool is_positive_definite (void) const { return is_pd; } | |
129 | |
130 double rcond (void) const { return cond; } | |
131 | |
132 int count; | |
133 | |
134 private: | |
135 bool is_pd; | |
136 | |
137 octave_idx_type minor_p; | |
138 | |
139 ColumnVector perms; | |
140 | |
141 double cond; | |
142 | |
143 octave_idx_type init (const chol_type& a, bool natural = true); | |
144 | |
145 // No assignment | |
146 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); | |
147 }; | |
148 #endif | |
5506 | 149 |
150 private: | |
151 sparse_base_chol_rep *rep; | |
152 | |
153 public: | |
154 | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
155 sparse_base_chol (void) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
156 : rep (new typename |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
157 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep ()) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
158 { } |
5506 | 159 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
160 sparse_base_chol (const chol_type& a, const bool n) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
161 : rep (new typename |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
162 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep (a, n)) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
163 { } |
5506 | 164 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
165 sparse_base_chol (const chol_type& a, octave_idx_type& info, const bool n) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
166 : rep (new typename sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep (a, info, n)) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
167 { } |
5506 | 168 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
169 sparse_base_chol (const sparse_base_chol<chol_type, chol_elt, p_type>& a) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
170 : rep (a.rep) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
171 { rep->count++; } |
5506 | 172 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
173 virtual ~sparse_base_chol (void) |
5506 | 174 { |
175 if (--rep->count <= 0) | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
176 delete rep; |
5506 | 177 } |
178 | |
179 sparse_base_chol& operator = (const sparse_base_chol& a) | |
180 { | |
181 if (this != &a) | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
182 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 if (--rep->count <= 0) |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
184 delete rep; |
5506 | 185 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 rep = a.rep; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
187 rep->count++; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 } |
5506 | 189 |
190 return *this; | |
191 } | |
192 | |
193 chol_type L (void) const; | |
194 | |
195 chol_type R (void) const { return L().hermitian (); } | |
196 | |
197 octave_idx_type P (void) const { return rep->P(); } | |
198 | |
199 ColumnVector perm (void) const { return rep->perm(); } | |
200 | |
201 p_type Q (void) const { return rep->Q(); } | |
202 | |
203 bool is_positive_definite (void) const | |
204 { return rep->is_positive_definite(); } | |
205 | |
206 double rcond (void) const { return rep->rcond(); } | |
207 | |
208 chol_type inverse (void) const; | |
209 }; | |
210 | |
211 #endif |