Mercurial > hg > octave-nkf
annotate liboctave/numeric/sparse-base-chol.h @ 19898:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | 49a5a4be04a1 |
children |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 2005-2015 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) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 { } |
5512 | 43 |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
44 sparse_base_chol_rep (const chol_type& a, bool natural, bool force) |
11505
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) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
47 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 init (a, natural, force); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
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, |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
52 bool natural, bool force) |
11505
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) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 info = init (a, natural, force); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
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) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 if (is_pd) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 CHOLMOD_NAME (free_sparse) (&Lsparse, &Common); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
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 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 0 : minor_p + 1); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
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 | |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
96 octave_idx_type init (const chol_type& a, bool natural, bool force); |
5506 | 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 |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
113 sparse_base_chol_rep (const chol_type& a, bool natural, bool force) |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
114 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 init (a, natural, force); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
117 } |
5512 | 118 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
119 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
120 bool natural, bool force) |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
121 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
122 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
123 info = init (a, natural, force); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
124 } |
5512 | 125 |
126 ~sparse_base_chol_rep (void) { } | |
127 | |
128 octave_idx_type P (void) const { return 0; } | |
129 | |
130 ColumnVector perm (void) const { return perms + 1; } | |
131 | |
132 p_type Q (void) const; | |
133 | |
134 bool is_positive_definite (void) const { return is_pd; } | |
135 | |
136 double rcond (void) const { return cond; } | |
137 | |
12125
a21a3875ca83
implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
12122
diff
changeset
|
138 octave_refcount<int> count; |
5512 | 139 |
140 private: | |
141 bool is_pd; | |
142 | |
143 octave_idx_type minor_p; | |
144 | |
145 ColumnVector perms; | |
146 | |
147 double cond; | |
148 | |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
149 octave_idx_type init (const chol_type& a, bool natural, bool force); |
5512 | 150 |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
151 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
152 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
153 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
|
154 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
155 sparse_base_chol_rep& operator = (const sparse_base_chol_rep&); |
5512 | 156 }; |
157 #endif | |
5506 | 158 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 private: |
5506 | 160 sparse_base_chol_rep *rep; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
161 |
5506 | 162 public: |
163 | |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
164 sparse_base_chol (void) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
165 : rep (new typename |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
166 sparse_base_chol<chol_type, chol_elt, p_type> |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
167 ::sparse_base_chol_rep ()) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 { } |
5506 | 169 |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
170 sparse_base_chol (const chol_type& a, bool natural, bool force) |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
171 : rep (new typename |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
172 sparse_base_chol<chol_type, chol_elt, p_type> |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
173 ::sparse_base_chol_rep (a, natural, force)) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
174 { } |
5506 | 175 |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
176 sparse_base_chol (const chol_type& a, octave_idx_type& info, |
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
177 bool natural, bool force) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
178 : rep (new typename |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 sparse_base_chol<chol_type, chol_elt, p_type> |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
180 ::sparse_base_chol_rep (a, info, natural, force)) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
181 { } |
5506 | 182 |
11505
9a308e96194e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
183 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
|
184 : rep (a.rep) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
185 { rep->count++; } |
5506 | 186 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
187 virtual ~sparse_base_chol (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
188 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
189 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
190 delete rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 } |
5506 | 192 |
193 sparse_base_chol& operator = (const sparse_base_chol& a) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
194 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
195 if (this != &a) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 if (--rep->count == 0) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
198 delete rep; |
5506 | 199 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
200 rep = a.rep; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
201 rep->count++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
202 } |
5506 | 203 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
204 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
205 } |
5506 | 206 |
207 chol_type L (void) const; | |
208 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
209 chol_type R (void) const { return L ().hermitian (); } |
5506 | 210 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
211 octave_idx_type P (void) const { return rep->P (); } |
5506 | 212 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
213 ColumnVector perm (void) const { return rep->perm (); } |
5506 | 214 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
215 p_type Q (void) const { return rep->Q (); } |
5506 | 216 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
217 bool is_positive_definite (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
218 { return rep->is_positive_definite (); } |
5506 | 219 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
220 double rcond (void) const { return rep->rcond (); } |
5506 | 221 |
222 chol_type inverse (void) const; | |
223 }; | |
224 | |
225 #endif |