Mercurial > hg > octave-nkf
annotate liboctave/sparse-base-chol.h @ 14626:f947d2922feb stable rc-3-6-2-0
3.6.2-rc0 release candidate
* configure.ac (AC_INIT): Version is now 3.6.2-rc0.
(OCTAVE_RELEASE_DATE): Now 2012-05-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 May 2012 13:46:18 -0400 |
parents | 72c96de7a403 |
children | 460a3c6d8bf1 |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13985
diff
changeset
|
3 Copyright (C) 2005-2012 David Bateman |
11523 | 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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
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 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
69 return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? |
11505
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 | |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
12122
diff
changeset
|
81 octave_refcount<int> count; |
5506 | 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 | |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
100 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
101 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
102 sparse_base_chol_rep (const sparse_base_chol_rep&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
103 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
104 sparse_base_chol_rep& operator = (const sparse_base_chol_rep&); |
5506 | 105 }; |
5512 | 106 #else |
107 class sparse_base_chol_rep | |
108 { | |
109 public: | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
110 sparse_base_chol_rep (void) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
111 : count (1), is_pd (false), minor_p (0), perms (), cond (0) { } |
5512 | 112 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
113 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
|
114 const bool natural) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
115 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
5512 | 116 { init (a, natural); } |
117 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
118 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
|
119 const bool natural) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
120 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
5512 | 121 { info = init (a, natural); } |
122 | |
123 ~sparse_base_chol_rep (void) { } | |
124 | |
125 octave_idx_type P (void) const { return 0; } | |
126 | |
127 ColumnVector perm (void) const { return perms + 1; } | |
128 | |
129 p_type Q (void) const; | |
130 | |
131 bool is_positive_definite (void) const { return is_pd; } | |
132 | |
133 double rcond (void) const { return cond; } | |
134 | |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
12122
diff
changeset
|
135 octave_refcount<int> count; |
5512 | 136 |
137 private: | |
138 bool is_pd; | |
139 | |
140 octave_idx_type minor_p; | |
141 | |
142 ColumnVector perms; | |
143 | |
144 double cond; | |
145 | |
146 octave_idx_type init (const chol_type& a, bool natural = true); | |
147 | |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
148 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
149 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
150 sparse_base_chol_rep (const sparse_base_chol_rep&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
151 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
152 sparse_base_chol_rep& operator = (const sparse_base_chol_rep&); |
5512 | 153 }; |
154 #endif | |
5506 | 155 |
156 private: | |
157 sparse_base_chol_rep *rep; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
158 |
5506 | 159 public: |
160 | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
161 sparse_base_chol (void) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
162 : rep (new typename |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
163 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
|
164 { } |
5506 | 165 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
166 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
|
167 : rep (new typename |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
168 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
|
169 { } |
5506 | 170 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
171 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
|
172 : 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
|
173 { } |
5506 | 174 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
175 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
|
176 : rep (a.rep) |
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
177 { rep->count++; } |
5506 | 178 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
179 virtual ~sparse_base_chol (void) |
5506 | 180 { |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
181 if (--rep->count == 0) |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
182 delete rep; |
5506 | 183 } |
184 | |
185 sparse_base_chol& operator = (const sparse_base_chol& a) | |
186 { | |
187 if (this != &a) | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 { |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
189 if (--rep->count == 0) |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
190 delete rep; |
5506 | 191 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
192 rep = a.rep; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
193 rep->count++; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
194 } |
5506 | 195 |
196 return *this; | |
197 } | |
198 | |
199 chol_type L (void) const; | |
200 | |
201 chol_type R (void) const { return L().hermitian (); } | |
202 | |
203 octave_idx_type P (void) const { return rep->P(); } | |
204 | |
205 ColumnVector perm (void) const { return rep->perm(); } | |
206 | |
207 p_type Q (void) const { return rep->Q(); } | |
208 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
209 bool is_positive_definite (void) const |
5506 | 210 { return rep->is_positive_definite(); } |
211 | |
212 double rcond (void) const { return rep->rcond(); } | |
213 | |
214 chol_type inverse (void) const; | |
215 }; | |
216 | |
217 #endif |