Mercurial > octave
annotate liboctave/numeric/sparse-chol.cc @ 22317:6ca3acf5fad8
move some new numeric classes to namespace octave::math
* aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc,
gepbalance.h, hess.cc, hess.h, lu.cc, lu.h, qr.cc, qr.h, qrp.cc,
qrp.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h,
sparse-dmsolve.cc,sparse-lu.cc, sparse-lu.h, sparse-qr.cc,
sparse-qr.h, svd.cc, svd.h: Move classes to namespace octave::math.
* __luinc__.cc, __qp__.cc, balance.cc, hess.cc, lu.cc, qz.cc,
schur.cc, sqrtm.cc, svd.cc, chol.cc, dmperm.cc, qr.cc, lex.h,
CMatrix.cc, CSparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc,
fMatrix.cc, eigs-base.cc, oct-norm.cc: Update for new namespaces.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 16 Aug 2016 15:48:22 -0400 |
parents | 5417dad26a25 |
children | bac0d6f07a3e |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
3 Copyright (C) 2016 John W. Eaton |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19139
diff
changeset
|
4 Copyright (C) 2005-2015 David Bateman |
11523 | 5 Copyright (C) 1998-2005 Andy Adler |
7016 | 6 |
7 This file is part of Octave. | |
5506 | 8 |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
5506 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
5506 | 22 |
23 */ | |
24 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21229
diff
changeset
|
26 # include "config.h" |
5506 | 27 #endif |
28 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
29 #include "sparse-chol.h" |
5506 | 30 #include "sparse-util.h" |
31 #include "lo-error.h" | |
32 #include "oct-sparse.h" | |
33 #include "oct-spparms.h" | |
34 #include "quit.h" | |
5785 | 35 #include "MatrixType.h" |
5506 | 36 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
37 namespace octave |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
38 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
39 namespace math |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
40 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
41 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
42 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
43 class sparse_chol<chol_type>::sparse_chol_rep |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
44 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
45 public: |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
46 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
47 sparse_chol_rep (void) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
48 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
49 #if defined (HAVE_CHOLMOD) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
50 , Lsparse (0), Common () |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
51 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
52 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
53 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
54 sparse_chol_rep (const chol_type& a, bool natural, bool force) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
55 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
56 #if defined (HAVE_CHOLMOD) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
57 , Lsparse (0), Common () |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
58 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
59 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
60 init (a, natural, force); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
61 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
62 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
63 sparse_chol_rep (const chol_type& a, octave_idx_type& info, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
64 bool natural, bool force) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
65 : count (1), is_pd (false), minor_p (0), perms (), cond (0) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
66 #if defined (HAVE_CHOLMOD) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
67 , Lsparse (0), Common () |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
68 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
69 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
70 info = init (a, natural, force); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
71 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
72 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
73 ~sparse_chol_rep (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
74 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
75 #if defined (HAVE_CHOLMOD) |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
76 if (Lsparse) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
77 CHOLMOD_NAME (free_sparse) (&Lsparse, &Common); |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
78 |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
79 CHOLMOD_NAME(finish) (&Common); |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
80 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
81 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
82 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
83 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
84 cholmod_sparse *L (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
85 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
86 return Lsparse; |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
87 } |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
88 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
89 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
90 octave_idx_type P (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
91 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
92 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
93 return (minor_p == static_cast<octave_idx_type>(Lsparse->ncol) ? |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
94 0 : minor_p + 1); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
95 #else |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
96 return 0; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
97 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
98 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
99 |
22229
22c2bd440544
chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents:
21724
diff
changeset
|
100 RowVector perm (void) const { return perms + 1; } |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
101 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
102 SparseMatrix Q (void) const; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
103 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
104 bool is_positive_definite (void) const { return is_pd; } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
105 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
106 double rcond (void) const { return cond; } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
107 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
108 octave_refcount<int> count; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
109 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
110 private: |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
111 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
112 bool is_pd; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
113 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
114 octave_idx_type minor_p; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
115 |
22229
22c2bd440544
chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents:
21724
diff
changeset
|
116 RowVector perms; |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
117 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
118 double cond; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
119 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
120 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
121 cholmod_sparse *Lsparse; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
122 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
123 cholmod_common Common; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
124 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
125 void drop_zeros (const cholmod_sparse *S); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
126 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
127 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
128 octave_idx_type init (const chol_type& a, bool natural, bool force); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
129 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
130 // No copying! |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
131 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
132 sparse_chol_rep (const sparse_chol_rep&); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
133 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
134 sparse_chol_rep& operator = (const sparse_chol_rep&); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
135 }; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
136 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
137 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
138 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
139 // Can't use CHOLMOD_NAME(drop)(0.0, S, cm) because it doesn't treat |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
140 // complex matrices. |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
141 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
142 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
143 void |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
144 sparse_chol<chol_type>::sparse_chol_rep::drop_zeros (const cholmod_sparse *S) |
5506 | 145 { |
5518 | 146 if (! S) |
5506 | 147 return; |
148 | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
149 octave_idx_type *Sp = static_cast<octave_idx_type *>(S->p); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
150 octave_idx_type *Si = static_cast<octave_idx_type *>(S->i); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
151 chol_elt *Sx = static_cast<chol_elt *>(S->x); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
152 |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
153 octave_idx_type pdest = 0; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
154 octave_idx_type ncol = S->ncol; |
5506 | 155 |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
156 for (octave_idx_type k = 0; k < ncol; k++) |
5506 | 157 { |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
158 octave_idx_type p = Sp[k]; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
159 octave_idx_type pend = Sp[k+1]; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
160 Sp[k] = pdest; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
161 |
5506 | 162 for (; p < pend; p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
163 { |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
164 chol_elt sik = Sx[p]; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
165 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
166 if (CHOLMOD_IS_NONZERO (sik)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
167 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
168 if (p != pdest) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
169 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
170 Si[pdest] = Si[p]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
171 Sx[pdest] = sik; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
172 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
173 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
174 pdest++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
175 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
176 } |
5506 | 177 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
178 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
179 Sp[ncol] = pdest; |
5506 | 180 } |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
181 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
182 // Must provide a specialization for this function. |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
183 template <typename T> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
184 int |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
185 get_xtype (void); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
186 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
187 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
188 inline int |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
189 get_xtype<double> (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
190 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
191 return CHOLMOD_REAL; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
192 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
193 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
194 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
195 inline int |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
196 get_xtype<Complex> (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
197 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
198 return CHOLMOD_COMPLEX; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
199 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
200 |
5511 | 201 #endif |
5506 | 202 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
203 template <typename chol_type> |
5506 | 204 octave_idx_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
205 sparse_chol<chol_type>::sparse_chol_rep::init (const chol_type& a, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
206 bool natural, bool force) |
5506 | 207 { |
5648 | 208 volatile octave_idx_type info = 0; |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
209 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
210 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
211 |
5506 | 212 octave_idx_type a_nr = a.rows (); |
213 octave_idx_type a_nc = a.cols (); | |
214 | |
215 if (a_nr != a_nc) | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
216 (*current_liboctave_error_handler) ("sparse_chol requires square matrix"); |
5506 | 217 |
218 cholmod_common *cm = &Common; | |
219 | |
220 // Setup initial parameters | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
221 |
5506 | 222 CHOLMOD_NAME(start) (cm); |
5518 | 223 cm->prefer_zomplex = false; |
5506 | 224 |
5893 | 225 double spu = octave_sparse_params::get_key ("spumoni"); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
226 |
5506 | 227 if (spu == 0.) |
228 { | |
229 cm->print = -1; | |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
230 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, 0); |
5506 | 231 } |
232 else | |
233 { | |
5760 | 234 cm->print = static_cast<int> (spu) + 2; |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
235 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint); |
5506 | 236 } |
237 | |
238 cm->error_handler = &SparseCholError; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
239 |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
240 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex); |
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
241 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot); |
5506 | 242 |
5518 | 243 cm->final_asis = false; |
244 cm->final_super = false; | |
245 cm->final_ll = true; | |
246 cm->final_pack = true; | |
247 cm->final_monotonic = true; | |
248 cm->final_resymbol = false; | |
5506 | 249 |
250 cholmod_sparse A; | |
251 cholmod_sparse *ac = &A; | |
252 double dummy; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
253 |
5506 | 254 ac->nrow = a_nr; |
255 ac->ncol = a_nc; | |
256 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
257 ac->p = a.cidx (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
258 ac->i = a.ridx (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
259 ac->nzmax = a.nnz (); |
5518 | 260 ac->packed = true; |
261 ac->sorted = true; | |
262 ac->nz = 0; | |
21229
a83e7a384ee0
create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21207
diff
changeset
|
263 #if defined (OCTAVE_ENABLE_64) |
5506 | 264 ac->itype = CHOLMOD_LONG; |
265 #else | |
266 ac->itype = CHOLMOD_INT; | |
267 #endif | |
268 ac->dtype = CHOLMOD_DOUBLE; | |
269 ac->stype = 1; | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
270 ac->xtype = get_xtype<chol_elt> (); |
5506 | 271 |
272 if (a_nr < 1) | |
273 ac->x = &dummy; | |
274 else | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
275 ac->x = a.data (); |
5506 | 276 |
277 // use natural ordering if no q output parameter | |
278 if (natural) | |
279 { | |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21584
diff
changeset
|
280 cm->nmethods = 1; |
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21584
diff
changeset
|
281 cm->method[0].ordering = CHOLMOD_NATURAL; |
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21584
diff
changeset
|
282 cm->postorder = false; |
5506 | 283 } |
284 | |
285 cholmod_factor *Lfactor; | |
286 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
287 Lfactor = CHOLMOD_NAME(analyze) (ac, cm); | |
288 CHOLMOD_NAME(factorize) (ac, Lfactor, cm); | |
289 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
290 | |
291 is_pd = cm->status == CHOLMOD_OK; | |
292 info = (is_pd ? 0 : cm->status); | |
293 | |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
294 if (is_pd || force) |
5506 | 295 { |
296 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
297 cond = CHOLMOD_NAME(rcond) (Lfactor, cm); |
5506 | 298 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
299 |
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
300 minor_p = Lfactor->minor; |
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
301 |
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
302 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
303 Lsparse = CHOLMOD_NAME(factor_to_sparse) (Lfactor, cm); |
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
304 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5506 | 305 |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
306 if (minor_p > 0 && minor_p < a_nr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
308 size_t n1 = a_nr + 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 Lsparse->p = CHOLMOD_NAME(realloc) (minor_p+1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
310 sizeof(octave_idx_type), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 Lsparse->p, &n1, cm); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
312 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
313 CHOLMOD_NAME(reallocate_sparse) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
314 (static_cast<octave_idx_type *>(Lsparse->p)[minor_p], Lsparse, cm); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
315 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
316 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
317 Lsparse->ncol = minor_p; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 } |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
319 |
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
320 drop_zeros (Lsparse); |
5506 | 321 |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
322 if (! natural) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
323 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
324 perms.resize (a_nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
325 for (octave_idx_type i = 0; i < a_nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
326 perms(i) = static_cast<octave_idx_type *>(Lfactor->Perm)[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
327 } |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
328 } |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
329 |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
330 // NAME used to prefix statistics report from print_common |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
331 static char blank_name[] = " "; |
7637
2be056f03720
Fix fall back from sparse cholesky factorization to LU when matrix detected as not being positive definite
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
332 |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
333 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
334 CHOLMOD_NAME(print_common) (blank_name, cm); |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
335 CHOLMOD_NAME(free_factor) (&Lfactor, cm); |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
336 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
337 |
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
338 return info; |
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
339 |
5506 | 340 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
341 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
342 octave_unused_parameter (a); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
343 octave_unused_parameter (natural); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
344 octave_unused_parameter (force); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
345 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
346 (*current_liboctave_error_handler) |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
347 ("support for CHOLMOD was unavailable or disabled when liboctave was built"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
348 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
349 return info; |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
350 |
5506 | 351 #endif |
352 } | |
353 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
354 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
355 SparseMatrix |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
356 sparse_chol<chol_type>::sparse_chol_rep::Q (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
357 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
358 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
359 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
360 octave_idx_type n = Lsparse->nrow; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
361 SparseMatrix p (n, n, n); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
362 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
363 for (octave_idx_type i = 0; i < n; i++) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
364 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
365 p.xcidx (i) = i; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
366 p.xridx (i) = static_cast<octave_idx_type>(perms (i)); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
367 p.xdata (i) = 1; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
368 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
369 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
370 p.xcidx (n) = n; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
371 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
372 return p; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
373 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
374 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
375 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
376 return SparseMatrix (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
377 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
378 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
379 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
380 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
381 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
382 sparse_chol<chol_type>::sparse_chol (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
383 : rep (new typename sparse_chol<chol_type>::sparse_chol_rep ()) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
384 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
385 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
386 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
387 sparse_chol<chol_type>::sparse_chol (const chol_type& a, bool natural, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
388 bool force) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
389 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
390 sparse_chol<chol_type>::sparse_chol_rep (a, natural, force)) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
391 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
392 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
393 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
394 sparse_chol<chol_type>::sparse_chol (const chol_type& a, octave_idx_type& info, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
395 bool natural, bool force) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
396 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
397 sparse_chol<chol_type>::sparse_chol_rep (a, info, natural, force)) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
398 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
399 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
400 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
401 sparse_chol<chol_type>::sparse_chol (const chol_type& a, octave_idx_type& info, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
402 bool natural) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
403 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
404 sparse_chol<chol_type>::sparse_chol_rep (a, info, natural, false)) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
405 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
406 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
407 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
408 sparse_chol<chol_type>::sparse_chol (const chol_type& a, octave_idx_type& info) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
409 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
410 sparse_chol<chol_type>::sparse_chol_rep (a, info, false, false)) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
411 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
412 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
413 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
414 sparse_chol<chol_type>::sparse_chol (const sparse_chol<chol_type>& a) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
415 : rep (a.rep) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
416 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
417 rep->count++; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
418 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
419 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
420 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
421 sparse_chol<chol_type>::~sparse_chol (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
422 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
423 if (--rep->count == 0) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
424 delete rep; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
425 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
426 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
427 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
428 sparse_chol<chol_type>& |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
429 sparse_chol<chol_type>::operator = (const sparse_chol& a) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
430 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
431 if (this != &a) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
432 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
433 if (--rep->count == 0) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
434 delete rep; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
435 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
436 rep = a.rep; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
437 rep->count++; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
438 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
439 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
440 return *this; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
441 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
442 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
443 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
444 chol_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
445 sparse_chol<chol_type>::L (void) const |
5506 | 446 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
447 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
448 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
449 cholmod_sparse *m = rep->L (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
450 |
5506 | 451 octave_idx_type nc = m->ncol; |
452 octave_idx_type nnz = m->nzmax; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
453 |
5506 | 454 chol_type ret (m->nrow, nc, nnz); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
455 |
5506 | 456 for (octave_idx_type j = 0; j < nc+1; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
457 ret.xcidx (j) = static_cast<octave_idx_type *>(m->p)[j]; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
458 |
5506 | 459 for (octave_idx_type i = 0; i < nnz; i++) |
460 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
461 ret.xridx (i) = static_cast<octave_idx_type *>(m->i)[i]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
462 ret.xdata (i) = static_cast<chol_elt *>(m->x)[i]; |
5506 | 463 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
464 |
5506 | 465 return ret; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
466 |
5506 | 467 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
468 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
469 return chol_type (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
470 |
5506 | 471 #endif |
472 } | |
473 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
474 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
475 octave_idx_type |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
476 sparse_chol<chol_type>::P (void) const |
5506 | 477 { |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
478 return rep->P (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
479 } |
5506 | 480 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
481 template <typename chol_type> |
22229
22c2bd440544
chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents:
21724
diff
changeset
|
482 RowVector |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
483 sparse_chol<chol_type>::perm (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
484 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
485 return rep->perm (); |
5506 | 486 } |
487 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
488 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
489 SparseMatrix |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
490 sparse_chol<chol_type>::Q (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
491 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
492 return rep->Q (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
493 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
494 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
495 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
496 bool |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
497 sparse_chol<chol_type>::is_positive_definite (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
498 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
499 return rep->is_positive_definite (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
500 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
501 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
502 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
503 double |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
504 sparse_chol<chol_type>::rcond (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
505 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
506 return rep->rcond (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
507 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
508 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
509 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
510 chol_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
511 sparse_chol<chol_type>::inverse (void) const |
5506 | 512 { |
513 chol_type retval; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
514 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
515 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
516 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
517 cholmod_sparse *m = rep->L (); |
5506 | 518 octave_idx_type n = m->ncol; |
22229
22c2bd440544
chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents:
21724
diff
changeset
|
519 RowVector perms = rep->perm (); |
5506 | 520 double rcond2; |
521 octave_idx_type info; | |
5785 | 522 MatrixType mattype (MatrixType::Upper); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
523 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0); |
5506 | 524 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
525 if (perms.numel () == n) |
5506 | 526 { |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
527 SparseMatrix Qc = Q (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
528 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
529 retval = Qc * linv * linv.hermitian () * Qc.transpose (); |
5506 | 530 } |
531 else | |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
7637
diff
changeset
|
532 retval = linv * linv.hermitian (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
533 |
5506 | 534 #endif |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
535 |
5506 | 536 return retval; |
537 } | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
538 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
539 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
540 chol_type |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
541 chol2inv (const chol_type& r) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
542 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
543 octave_idx_type r_nr = r.rows (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
544 octave_idx_type r_nc = r.cols (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
545 chol_type retval; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
546 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
547 if (r_nr != r_nc) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
548 (*current_liboctave_error_handler) ("U must be a square matrix"); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
549 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
550 MatrixType mattype (r); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
551 int typ = mattype.type (false); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
552 double rcond; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
553 octave_idx_type info; |
22242
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
554 chol_type rtra, multip; |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
555 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
556 if (typ == MatrixType::Upper) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
557 { |
22242
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
558 rtra = r.transpose (); |
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
559 multip = (rtra*r); |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
560 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
561 else if (typ == MatrixType::Lower) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
562 { |
22242
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
563 rtra = r.transpose (); |
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
564 multip = (r*rtra); |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
565 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
566 else |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
567 (*current_liboctave_error_handler) ("U must be a triangular matrix"); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
568 |
22242
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
569 MatrixType mattypenew (multip); |
5417dad26a25
chol2inv: "inv (Y'*Y)" instead of "(inv(Y))' * inv(Y)" (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22229
diff
changeset
|
570 retval = multip.inverse (mattypenew, info, rcond, true, false); |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
571 return retval; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
572 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
573 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
574 // SparseComplexMatrix specialization (the value for the NATURAL |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
575 // parameter in the sparse_chol<T>::sparse_chol_rep constructor is |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
576 // different from the default). |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
577 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
578 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
579 sparse_chol<SparseComplexMatrix>::sparse_chol (const SparseComplexMatrix& a, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
580 octave_idx_type& info) |
21324
5169d5993d77
sparse-chol.cc: Fix minor syntax error to compile with older gcc
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
581 : rep ( |
5169d5993d77
sparse-chol.cc: Fix minor syntax error to compile with older gcc
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
582 new sparse_chol<SparseComplexMatrix>::sparse_chol_rep (a, info, true, false)) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
583 { } |
21186
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
584 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
585 // Instantiations we need. |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
586 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
587 template class sparse_chol<SparseMatrix>; |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
588 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
589 template class sparse_chol<SparseComplexMatrix>; |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
590 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
591 template SparseMatrix |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
592 chol2inv<SparseMatrix> (const SparseMatrix& r); |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
593 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
594 template SparseComplexMatrix |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
595 chol2inv<SparseComplexMatrix> (const SparseComplexMatrix& r); |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
596 |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
597 } |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22242
diff
changeset
|
598 } |