GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sparse-base-chol.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2005-2015 David Bateman
4 Copyright (C) 1998-2005 Andy Adler
5 
6 This file is part of Octave.
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
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
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
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
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
33 {
34 protected:
35 #ifdef HAVE_CHOLMOD
37  {
38  public:
40  : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0),
41  perms (), cond (0)
42  { }
43 
44  sparse_base_chol_rep (const chol_type& a, bool natural, bool force)
45  : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0),
46  perms (), cond (0)
47  {
48  init (a, natural, force);
49  }
50 
51  sparse_base_chol_rep (const chol_type& a, octave_idx_type& info,
52  bool natural, bool force)
53  : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0),
54  perms (), cond (0)
55  {
56  info = init (a, natural, force);
57  }
58 
60  {
61  if (is_pd)
62  CHOLMOD_NAME (free_sparse) (&Lsparse, &Common);
63  }
64 
65  cholmod_sparse * L (void) const { return Lsparse; }
66 
67  octave_idx_type P (void) const
68  {
69  return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ?
70  0 : minor_p + 1);
71  }
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 
82 
83  private:
84  cholmod_sparse *Lsparse;
85 
86  cholmod_common Common;
87 
88  bool is_pd;
89 
91 
93 
94  double cond;
95 
96  octave_idx_type init (const chol_type& a, bool natural, bool force);
97 
98  void drop_zeros (const cholmod_sparse* S);
99 
100  // No copying!
101 
103 
104  sparse_base_chol_rep& operator = (const sparse_base_chol_rep&);
105  };
106 #else
108  {
109  public:
110  sparse_base_chol_rep (void)
111  : count (1), is_pd (false), minor_p (0), perms (), cond (0) { }
112 
113  sparse_base_chol_rep (const chol_type& a, bool natural, bool force)
114  : count (1), is_pd (false), minor_p (0), perms (), cond (0)
115  {
116  init (a, natural, force);
117  }
118 
119  sparse_base_chol_rep (const chol_type& a, octave_idx_type& info,
120  bool natural, bool force)
121  : count (1), is_pd (false), minor_p (0), perms (), cond (0)
122  {
123  info = init (a, natural, force);
124  }
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 
138  octave_refcount<int> count;
139 
140  private:
141  bool is_pd;
142 
143  octave_idx_type minor_p;
144 
145  ColumnVector perms;
146 
147  double cond;
148 
149  octave_idx_type init (const chol_type& a, bool natural, bool force);
150 
151  // No copying!
152 
153  sparse_base_chol_rep (const sparse_base_chol_rep&);
154 
155  sparse_base_chol_rep& operator = (const sparse_base_chol_rep&);
156  };
157 #endif
158 
159 private:
160  sparse_base_chol_rep *rep;
161 
162 public:
163 
165  : rep (new typename
166  sparse_base_chol<chol_type, chol_elt, p_type>
167  ::sparse_base_chol_rep ())
168  { }
169 
170  sparse_base_chol (const chol_type& a, bool natural, bool force)
171  : rep (new typename
172  sparse_base_chol<chol_type, chol_elt, p_type>
173  ::sparse_base_chol_rep (a, natural, force))
174  { }
175 
176  sparse_base_chol (const chol_type& a, octave_idx_type& info,
177  bool natural, bool force)
178  : rep (new typename
179  sparse_base_chol<chol_type, chol_elt, p_type>
180  ::sparse_base_chol_rep (a, info, natural, force))
181  { }
182 
184  : rep (a.rep)
185  { rep->count++; }
186 
187  virtual ~sparse_base_chol (void)
188  {
189  if (--rep->count == 0)
190  delete rep;
191  }
192 
193  sparse_base_chol& operator = (const sparse_base_chol& a)
194  {
195  if (this != &a)
196  {
197  if (--rep->count == 0)
198  delete rep;
199 
200  rep = a.rep;
201  rep->count++;
202  }
203 
204  return *this;
205  }
206 
207  chol_type L (void) const;
208 
209  chol_type R (void) const { return L ().hermitian (); }
210 
211  octave_idx_type P (void) const { return rep->P (); }
212 
213  ColumnVector perm (void) const { return rep->perm (); }
214 
215  p_type Q (void) const { return rep->Q (); }
216 
217  bool is_positive_definite (void) const
218  { return rep->is_positive_definite (); }
219 
220  double rcond (void) const { return rep->rcond (); }
221 
222  chol_type inverse (void) const;
223 };
224 
225 #endif
bool is_positive_definite(void) const
chol_type R(void) const
virtual ~sparse_base_chol(void)
octave_idx_type P(void) const
sparse_base_chol(const chol_type &a, bool natural, bool force)
double rcond(void) const
octave_idx_type P(void) const
sparse_base_chol_rep * rep
sparse_base_chol_rep(const chol_type &a, octave_idx_type &info, bool natural, bool force)
ColumnVector perm(void) const
p_type Q(void) const
SparseComplexMatrix hermitian(void) const
Definition: CSparse.cc:679
sparse_base_chol(const sparse_base_chol< chol_type, chol_elt, p_type > &a)
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type double const octave_idx_type double const octave_idx_type double * Q
Definition: qz.cc:114
sparse_base_chol(const chol_type &a, octave_idx_type &info, bool natural, bool force)
cholmod_sparse * L(void) const
sparse_base_chol_rep(const chol_type &a, bool natural, bool force)