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