5506
|
1 /* |
|
2 |
|
3 Copyright (C) 2005 David Bateman |
|
4 Copyright (C) 1998-2005 Andy Adler |
|
5 |
|
6 Octave is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License as published by the |
|
8 Free Software Foundation; either version 2, or (at your option) any |
|
9 later version. |
|
10 |
|
11 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
|
17 along with this program; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 Boston, MA 02110-1301, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_sparse_base_chol_h) |
|
24 #define octave_sparse_base_chol_h 1 |
|
25 |
|
26 #ifdef HAVE_CONFIG_H |
|
27 #include <config.h> |
|
28 #endif |
|
29 |
|
30 #include "oct-sparse.h" |
|
31 #include "dColVector.h" |
|
32 |
|
33 template <class chol_type, class chol_elt, class p_type> |
|
34 class |
|
35 sparse_base_chol |
|
36 { |
|
37 protected: |
5512
|
38 #ifdef HAVE_CHOLMOD |
5506
|
39 class sparse_base_chol_rep |
|
40 { |
|
41 public: |
|
42 sparse_base_chol_rep (void) : count (1), Lsparse (NULL), |
|
43 is_pd (false), minor_p (0) { } |
5512
|
44 |
5506
|
45 sparse_base_chol_rep (const chol_type& a, |
|
46 const bool natural) : count (1) |
|
47 { init (a, natural); } |
|
48 |
|
49 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, |
|
50 const bool natural) : count (1) |
|
51 { info = init (a, natural); } |
|
52 |
|
53 ~sparse_base_chol_rep (void) |
|
54 { CHOLMOD_NAME(free_sparse) (&Lsparse, &Common); } |
|
55 |
|
56 cholmod_sparse * L (void) const { return Lsparse; } |
5512
|
57 |
5506
|
58 octave_idx_type P (void) const |
|
59 { return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? |
|
60 0 : minor_p + 1); } |
|
61 |
|
62 ColumnVector perm (void) const { return perms + 1; } |
|
63 |
|
64 p_type Q (void) const; |
|
65 |
|
66 bool is_positive_definite (void) const { return is_pd; } |
|
67 |
|
68 double rcond (void) const { return cond; } |
|
69 |
|
70 int count; |
|
71 |
|
72 private: |
|
73 cholmod_sparse *Lsparse; |
|
74 |
|
75 cholmod_common Common; |
5512
|
76 |
5506
|
77 bool is_pd; |
|
78 |
|
79 octave_idx_type minor_p; |
|
80 |
|
81 ColumnVector perms; |
|
82 |
|
83 double cond; |
|
84 |
|
85 octave_idx_type init (const chol_type& a, bool natural = true); |
|
86 |
|
87 void drop_zeros (const cholmod_sparse* S); |
|
88 |
|
89 // No assignment |
|
90 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); |
|
91 }; |
5512
|
92 #else |
|
93 class sparse_base_chol_rep |
|
94 { |
|
95 public: |
|
96 sparse_base_chol_rep (void) : count (1), is_pd (false), minor_p (0) { } |
|
97 |
|
98 sparse_base_chol_rep (const chol_type& a, |
|
99 const bool natural) : count (1) |
|
100 { init (a, natural); } |
|
101 |
|
102 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, |
|
103 const bool natural) : count (1) |
|
104 { info = init (a, natural); } |
|
105 |
|
106 ~sparse_base_chol_rep (void) { } |
|
107 |
|
108 octave_idx_type P (void) const { return 0; } |
|
109 |
|
110 ColumnVector perm (void) const { return perms + 1; } |
|
111 |
|
112 p_type Q (void) const; |
|
113 |
|
114 bool is_positive_definite (void) const { return is_pd; } |
|
115 |
|
116 double rcond (void) const { return cond; } |
|
117 |
|
118 int count; |
|
119 |
|
120 private: |
|
121 bool is_pd; |
|
122 |
|
123 octave_idx_type minor_p; |
|
124 |
|
125 ColumnVector perms; |
|
126 |
|
127 double cond; |
|
128 |
|
129 octave_idx_type init (const chol_type& a, bool natural = true); |
|
130 |
|
131 // No assignment |
|
132 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); |
|
133 }; |
|
134 #endif |
5506
|
135 |
|
136 private: |
|
137 sparse_base_chol_rep *rep; |
|
138 |
|
139 public: |
|
140 |
|
141 sparse_base_chol (void) : rep (new typename |
|
142 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep ()) { } |
|
143 |
|
144 sparse_base_chol (const chol_type& a, const bool n) : rep (new typename |
|
145 sparse_base_chol<chol_type, chol_elt, p_type>:: |
|
146 sparse_base_chol_rep (a, n)) { } |
|
147 |
|
148 sparse_base_chol (const chol_type& a, octave_idx_type& info, const bool n) : |
|
149 rep (new typename sparse_base_chol<chol_type, chol_elt, p_type>:: |
|
150 sparse_base_chol_rep (a, info, n)) { } |
|
151 |
|
152 sparse_base_chol (const sparse_base_chol<chol_type, chol_elt, p_type>& a) : |
|
153 rep (a.rep) { rep->count++; } |
|
154 |
|
155 ~sparse_base_chol (void) |
|
156 { |
|
157 if (--rep->count <= 0) |
|
158 delete rep; |
|
159 } |
|
160 |
|
161 sparse_base_chol& operator = (const sparse_base_chol& a) |
|
162 { |
|
163 if (this != &a) |
|
164 { |
|
165 if (--rep->count <= 0) |
|
166 delete rep; |
|
167 |
|
168 rep = a.rep; |
|
169 rep->count++; |
|
170 } |
|
171 |
|
172 return *this; |
|
173 } |
|
174 |
|
175 chol_type L (void) const; |
|
176 |
|
177 chol_type R (void) const { return L().hermitian (); } |
|
178 |
|
179 octave_idx_type P (void) const { return rep->P(); } |
|
180 |
|
181 ColumnVector perm (void) const { return rep->perm(); } |
|
182 |
|
183 p_type Q (void) const { return rep->Q(); } |
|
184 |
|
185 bool is_positive_definite (void) const |
|
186 { return rep->is_positive_definite(); } |
|
187 |
|
188 double rcond (void) const { return rep->rcond(); } |
|
189 |
|
190 chol_type inverse (void) const; |
|
191 }; |
|
192 |
|
193 #endif |
|
194 |
|
195 /* |
|
196 ;;; Local Variables: *** |
|
197 ;;; mode: C++ *** |
|
198 ;;; End: *** |
|
199 */ |