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: |
|
38 class sparse_base_chol_rep |
|
39 { |
|
40 public: |
|
41 sparse_base_chol_rep (void) : count (1), Lsparse (NULL), |
|
42 is_pd (false), minor_p (0) { } |
|
43 |
|
44 sparse_base_chol_rep (const chol_type& a, |
|
45 const bool natural) : count (1) |
|
46 { init (a, natural); } |
|
47 |
|
48 sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, |
|
49 const bool natural) : count (1) |
|
50 { info = init (a, natural); } |
|
51 |
|
52 #ifndef HAVE_CHOLMOD |
|
53 ~sparse_base_chol_rep (void) { } |
|
54 #else |
|
55 ~sparse_base_chol_rep (void) |
|
56 { CHOLMOD_NAME(free_sparse) (&Lsparse, &Common); } |
|
57 #endif |
|
58 |
|
59 cholmod_sparse * L (void) const { return Lsparse; } |
|
60 |
|
61 octave_idx_type P (void) const |
|
62 { return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? |
|
63 0 : minor_p + 1); } |
|
64 |
|
65 ColumnVector perm (void) const { return perms + 1; } |
|
66 |
|
67 p_type Q (void) const; |
|
68 |
|
69 bool is_positive_definite (void) const { return is_pd; } |
|
70 |
|
71 double rcond (void) const { return cond; } |
|
72 |
|
73 int count; |
|
74 |
|
75 private: |
|
76 cholmod_sparse *Lsparse; |
|
77 |
|
78 cholmod_common Common; |
|
79 |
|
80 bool is_pd; |
|
81 |
|
82 octave_idx_type minor_p; |
|
83 |
|
84 ColumnVector perms; |
|
85 |
|
86 double cond; |
|
87 |
|
88 octave_idx_type init (const chol_type& a, bool natural = true); |
|
89 |
|
90 void drop_zeros (const cholmod_sparse* S); |
|
91 |
|
92 // No assignment |
|
93 sparse_base_chol_rep& operator = (const sparse_base_chol_rep& a); |
|
94 }; |
|
95 |
|
96 private: |
|
97 sparse_base_chol_rep *rep; |
|
98 |
|
99 public: |
|
100 |
|
101 sparse_base_chol (void) : rep (new typename |
|
102 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep ()) { } |
|
103 |
|
104 sparse_base_chol (const chol_type& a, const bool n) : rep (new typename |
|
105 sparse_base_chol<chol_type, chol_elt, p_type>:: |
|
106 sparse_base_chol_rep (a, n)) { } |
|
107 |
|
108 sparse_base_chol (const chol_type& a, octave_idx_type& info, const bool n) : |
|
109 rep (new typename sparse_base_chol<chol_type, chol_elt, p_type>:: |
|
110 sparse_base_chol_rep (a, info, n)) { } |
|
111 |
|
112 sparse_base_chol (const sparse_base_chol<chol_type, chol_elt, p_type>& a) : |
|
113 rep (a.rep) { rep->count++; } |
|
114 |
|
115 ~sparse_base_chol (void) |
|
116 { |
|
117 if (--rep->count <= 0) |
|
118 delete rep; |
|
119 } |
|
120 |
|
121 sparse_base_chol& operator = (const sparse_base_chol& a) |
|
122 { |
|
123 if (this != &a) |
|
124 { |
|
125 if (--rep->count <= 0) |
|
126 delete rep; |
|
127 |
|
128 rep = a.rep; |
|
129 rep->count++; |
|
130 } |
|
131 |
|
132 return *this; |
|
133 } |
|
134 |
|
135 chol_type L (void) const; |
|
136 |
|
137 chol_type R (void) const { return L().hermitian (); } |
|
138 |
|
139 octave_idx_type P (void) const { return rep->P(); } |
|
140 |
|
141 ColumnVector perm (void) const { return rep->perm(); } |
|
142 |
|
143 p_type Q (void) const { return rep->Q(); } |
|
144 |
|
145 bool is_positive_definite (void) const |
|
146 { return rep->is_positive_definite(); } |
|
147 |
|
148 double rcond (void) const { return rep->rcond(); } |
|
149 |
|
150 chol_type inverse (void) const; |
|
151 }; |
|
152 |
|
153 #endif |
|
154 |
|
155 /* |
|
156 ;;; Local Variables: *** |
|
157 ;;; mode: C++ *** |
|
158 ;;; End: *** |
|
159 */ |