Mercurial > hg > octave-nkf
annotate liboctave/sparse-base-chol.h @ 11897:ee24b6c413f6 release-3-0-x
contourf.m: Correct order of patch object handles.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sat, 13 Dec 2008 17:30:38 +0100 |
parents | 72830070a17b |
children |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
11740 | 3 Copyright (C) 2005, 2007, 2008 David Bateman |
7016 | 4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Andy Adler |
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 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
31 #include "oct-sparse.h" | |
32 #include "dColVector.h" | |
33 | |
34 template <class chol_type, class chol_elt, class p_type> | |
35 class | |
36 sparse_base_chol | |
37 { | |
38 protected: | |
5512 | 39 #ifdef HAVE_CHOLMOD |
5506 | 40 class sparse_base_chol_rep |
41 { | |
42 public: | |
43 sparse_base_chol_rep (void) : count (1), Lsparse (NULL), | |
44 is_pd (false), minor_p (0) { } | |
5512 | 45 |
5506 | 46 sparse_base_chol_rep (const chol_type& a, |
47 const bool natural) : count (1) | |
48 { init (a, natural); } | |
49 | |
50 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, | |
51 const bool natural) : count (1) | |
52 { info = init (a, natural); } | |
53 | |
11716
017e13f0d056
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
54 ~sparse_base_chol_rep (void) |
017e13f0d056
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
55 { if (is_pd) CHOLMOD_NAME(free_sparse) (&Lsparse, &Common); } |
5506 | 56 |
57 cholmod_sparse * L (void) const { return Lsparse; } | |
5512 | 58 |
5506 | 59 octave_idx_type P (void) const |
60 { return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? | |
61 0 : minor_p + 1); } | |
62 | |
63 ColumnVector perm (void) const { return perms + 1; } | |
64 | |
65 p_type Q (void) const; | |
66 | |
67 bool is_positive_definite (void) const { return is_pd; } | |
68 | |
69 double rcond (void) const { return cond; } | |
70 | |
71 int count; | |
72 | |
73 private: | |
74 cholmod_sparse *Lsparse; | |
75 | |
76 cholmod_common Common; | |
5512 | 77 |
5506 | 78 bool is_pd; |
79 | |
80 octave_idx_type minor_p; | |
81 | |
82 ColumnVector perms; | |
83 | |
84 double cond; | |
85 | |
86 octave_idx_type init (const chol_type& a, bool natural = true); | |
87 | |
88 void drop_zeros (const cholmod_sparse* S); | |
89 | |
90 // No assignment | |
91 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); | |
92 }; | |
5512 | 93 #else |
94 class sparse_base_chol_rep | |
95 { | |
96 public: | |
97 sparse_base_chol_rep (void) : count (1), is_pd (false), minor_p (0) { } | |
98 | |
99 sparse_base_chol_rep (const chol_type& a, | |
100 const bool natural) : count (1) | |
101 { init (a, natural); } | |
102 | |
103 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, | |
104 const bool natural) : count (1) | |
105 { info = init (a, natural); } | |
106 | |
107 ~sparse_base_chol_rep (void) { } | |
108 | |
109 octave_idx_type P (void) const { return 0; } | |
110 | |
111 ColumnVector perm (void) const { return perms + 1; } | |
112 | |
113 p_type Q (void) const; | |
114 | |
115 bool is_positive_definite (void) const { return is_pd; } | |
116 | |
117 double rcond (void) const { return cond; } | |
118 | |
119 int count; | |
120 | |
121 private: | |
122 bool is_pd; | |
123 | |
124 octave_idx_type minor_p; | |
125 | |
126 ColumnVector perms; | |
127 | |
128 double cond; | |
129 | |
130 octave_idx_type init (const chol_type& a, bool natural = true); | |
131 | |
132 // No assignment | |
133 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); | |
134 }; | |
135 #endif | |
5506 | 136 |
137 private: | |
138 sparse_base_chol_rep *rep; | |
139 | |
140 public: | |
141 | |
142 sparse_base_chol (void) : rep (new typename | |
143 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep ()) { } | |
144 | |
145 sparse_base_chol (const chol_type& a, const bool n) : rep (new typename | |
146 sparse_base_chol<chol_type, chol_elt, p_type>:: | |
147 sparse_base_chol_rep (a, n)) { } | |
148 | |
149 sparse_base_chol (const chol_type& a, octave_idx_type& info, const bool n) : | |
150 rep (new typename sparse_base_chol<chol_type, chol_elt, p_type>:: | |
151 sparse_base_chol_rep (a, info, n)) { } | |
152 | |
153 sparse_base_chol (const sparse_base_chol<chol_type, chol_elt, p_type>& a) : | |
154 rep (a.rep) { rep->count++; } | |
155 | |
156 ~sparse_base_chol (void) | |
157 { | |
158 if (--rep->count <= 0) | |
159 delete rep; | |
160 } | |
161 | |
162 sparse_base_chol& operator = (const sparse_base_chol& a) | |
163 { | |
164 if (this != &a) | |
165 { | |
166 if (--rep->count <= 0) | |
167 delete rep; | |
168 | |
169 rep = a.rep; | |
170 rep->count++; | |
171 } | |
172 | |
173 return *this; | |
174 } | |
175 | |
176 chol_type L (void) const; | |
177 | |
178 chol_type R (void) const { return L().hermitian (); } | |
179 | |
180 octave_idx_type P (void) const { return rep->P(); } | |
181 | |
182 ColumnVector perm (void) const { return rep->perm(); } | |
183 | |
184 p_type Q (void) const { return rep->Q(); } | |
185 | |
186 bool is_positive_definite (void) const | |
187 { return rep->is_positive_definite(); } | |
188 | |
189 double rcond (void) const { return rep->rcond(); } | |
190 | |
191 chol_type inverse (void) const; | |
192 }; | |
193 | |
194 #endif | |
195 | |
196 /* | |
197 ;;; Local Variables: *** | |
198 ;;; mode: C++ *** | |
199 ;;; End: *** | |
200 */ |