Mercurial > octave
annotate liboctave/numeric/sparse-chol.cc @ 22229:22c2bd440544
chol: return permutation vector as row vector instead of column vector.
* libinterp/dldfcn/chol.cc: add tests for the vector option. Also error
if there's a "vector" option but input was not sparse. Existing test
for case sensitivity was also useless, since change is on the 3rd argument.
* liboctave/numeric/sparse-chol.cc, liboctave/numeric/sparse-chol.h: use
RowVector instead of ColumnVector for permutation vector, for Matlab
compatibility.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 09 Aug 2016 04:14:55 +0100 |
parents | aba2e6293dd8 |
children | 5417dad26a25 |
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 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
37 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
38 class sparse_chol<chol_type>::sparse_chol_rep |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
39 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
40 public: |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
41 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
42 sparse_chol_rep (void) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
43 : 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
|
44 #if defined (HAVE_CHOLMOD) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
45 , Lsparse (0), Common () |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
46 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
47 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
48 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
49 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
|
50 : 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
|
51 #if defined (HAVE_CHOLMOD) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
52 , Lsparse (0), Common () |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
53 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
54 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
55 init (a, natural, force); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
56 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
57 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
58 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
|
59 bool natural, bool force) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
60 : 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
|
61 #if defined (HAVE_CHOLMOD) |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
62 , Lsparse (0), Common () |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
63 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
64 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
65 info = init (a, natural, force); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
66 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
67 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
68 ~sparse_chol_rep (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
69 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
70 #if defined (HAVE_CHOLMOD) |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
71 if (Lsparse) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
72 CHOLMOD_NAME (free_sparse) (&Lsparse, &Common); |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
73 |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
74 CHOLMOD_NAME(finish) (&Common); |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
75 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
76 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
77 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
78 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
79 cholmod_sparse *L (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
80 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
81 return Lsparse; |
21207
945695cafd2b
allow build to succeed with missing dependencies
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
82 } |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
83 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
84 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
85 octave_idx_type P (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
86 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
87 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
88 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
|
89 0 : minor_p + 1); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
90 #else |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
91 return 0; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
92 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
93 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
94 |
22229
22c2bd440544
chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents:
21724
diff
changeset
|
95 RowVector perm (void) const { return perms + 1; } |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
96 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
97 SparseMatrix Q (void) const; |
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 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
|
100 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
101 double rcond (void) const { return cond; } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
102 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
103 octave_refcount<int> count; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
104 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
105 private: |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
106 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
107 bool is_pd; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
108 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
109 octave_idx_type minor_p; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
110 |
22229
22c2bd440544
chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents:
21724
diff
changeset
|
111 RowVector perms; |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
112 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
113 double cond; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
114 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
115 #if defined (HAVE_CHOLMOD) |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
116 cholmod_sparse *Lsparse; |
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 cholmod_common Common; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
119 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
120 void drop_zeros (const cholmod_sparse *S); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
121 #endif |
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 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
|
124 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
125 // No copying! |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
126 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
127 sparse_chol_rep (const sparse_chol_rep&); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
128 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
129 sparse_chol_rep& operator = (const sparse_chol_rep&); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
130 }; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
131 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
132 #if defined (HAVE_CHOLMOD) |
21145
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 // 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
|
135 // complex matrices. |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
136 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
137 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
138 void |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
139 sparse_chol<chol_type>::sparse_chol_rep::drop_zeros (const cholmod_sparse *S) |
5506 | 140 { |
5518 | 141 if (! S) |
5506 | 142 return; |
143 | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
148 octave_idx_type pdest = 0; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
149 octave_idx_type ncol = S->ncol; |
5506 | 150 |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
151 for (octave_idx_type k = 0; k < ncol; k++) |
5506 | 152 { |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
153 octave_idx_type p = Sp[k]; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
154 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
|
155 Sp[k] = pdest; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
156 |
5506 | 157 for (; p < pend; p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
158 { |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
159 chol_elt sik = Sx[p]; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
160 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
161 if (CHOLMOD_IS_NONZERO (sik)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
163 if (p != pdest) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
164 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
165 Si[pdest] = Si[p]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
166 Sx[pdest] = sik; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
167 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
168 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
169 pdest++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
170 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
171 } |
5506 | 172 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
173 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
174 Sp[ncol] = pdest; |
5506 | 175 } |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
176 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
177 // Must provide a specialization for this function. |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
178 template <typename T> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
179 int |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
180 get_xtype (void); |
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 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
183 inline int |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
184 get_xtype<double> (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
185 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
186 return CHOLMOD_REAL; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
187 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
188 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
189 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
190 inline int |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
191 get_xtype<Complex> (void) |
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 return CHOLMOD_COMPLEX; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
194 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
195 |
5511 | 196 #endif |
5506 | 197 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
198 template <typename chol_type> |
5506 | 199 octave_idx_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
200 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
|
201 bool natural, bool force) |
5506 | 202 { |
5648 | 203 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
|
204 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
205 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
206 |
5506 | 207 octave_idx_type a_nr = a.rows (); |
208 octave_idx_type a_nc = a.cols (); | |
209 | |
210 if (a_nr != a_nc) | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
211 (*current_liboctave_error_handler) ("sparse_chol requires square matrix"); |
5506 | 212 |
213 cholmod_common *cm = &Common; | |
214 | |
215 // Setup initial parameters | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
216 |
5506 | 217 CHOLMOD_NAME(start) (cm); |
5518 | 218 cm->prefer_zomplex = false; |
5506 | 219 |
5893 | 220 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
|
221 |
5506 | 222 if (spu == 0.) |
223 { | |
224 cm->print = -1; | |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
225 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, 0); |
5506 | 226 } |
227 else | |
228 { | |
5760 | 229 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
|
230 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint); |
5506 | 231 } |
232 | |
233 cm->error_handler = &SparseCholError; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
234 |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
235 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
|
236 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot); |
5506 | 237 |
5518 | 238 cm->final_asis = false; |
239 cm->final_super = false; | |
240 cm->final_ll = true; | |
241 cm->final_pack = true; | |
242 cm->final_monotonic = true; | |
243 cm->final_resymbol = false; | |
5506 | 244 |
245 cholmod_sparse A; | |
246 cholmod_sparse *ac = &A; | |
247 double dummy; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
248 |
5506 | 249 ac->nrow = a_nr; |
250 ac->ncol = a_nc; | |
251 | |
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
|
252 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
|
253 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
|
254 ac->nzmax = a.nnz (); |
5518 | 255 ac->packed = true; |
256 ac->sorted = true; | |
257 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
|
258 #if defined (OCTAVE_ENABLE_64) |
5506 | 259 ac->itype = CHOLMOD_LONG; |
260 #else | |
261 ac->itype = CHOLMOD_INT; | |
262 #endif | |
263 ac->dtype = CHOLMOD_DOUBLE; | |
264 ac->stype = 1; | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
265 ac->xtype = get_xtype<chol_elt> (); |
5506 | 266 |
267 if (a_nr < 1) | |
268 ac->x = &dummy; | |
269 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
|
270 ac->x = a.data (); |
5506 | 271 |
272 // use natural ordering if no q output parameter | |
273 if (natural) | |
274 { | |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21584
diff
changeset
|
275 cm->nmethods = 1; |
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21584
diff
changeset
|
276 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
|
277 cm->postorder = false; |
5506 | 278 } |
279 | |
280 cholmod_factor *Lfactor; | |
281 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
282 Lfactor = CHOLMOD_NAME(analyze) (ac, cm); | |
283 CHOLMOD_NAME(factorize) (ac, Lfactor, cm); | |
284 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
285 | |
286 is_pd = cm->status == CHOLMOD_OK; | |
287 info = (is_pd ? 0 : cm->status); | |
288 | |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
289 if (is_pd || force) |
5506 | 290 { |
291 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
|
292 cond = CHOLMOD_NAME(rcond) (Lfactor, cm); |
5506 | 293 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
|
294 |
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
|
295 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
|
296 |
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 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
|
298 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
|
299 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5506 | 300 |
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
|
301 if (minor_p > 0 && minor_p < a_nr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
302 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 size_t n1 = a_nr + 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
304 Lsparse->p = CHOLMOD_NAME(realloc) (minor_p+1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
305 sizeof(octave_idx_type), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
306 Lsparse->p, &n1, cm); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
308 CHOLMOD_NAME(reallocate_sparse) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 (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
|
310 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
311 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
312 Lsparse->ncol = minor_p; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
313 } |
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
|
314 |
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
|
315 drop_zeros (Lsparse); |
5506 | 316 |
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
|
317 if (! natural) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
319 perms.resize (a_nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
320 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
|
321 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
|
322 } |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
323 } |
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
|
324 |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
325 // 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
|
326 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
|
327 |
21584
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
328 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
329 CHOLMOD_NAME(print_common) (blank_name, cm); |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
330 CHOLMOD_NAME(free_factor) (&Lfactor, cm); |
ee1a009dd60f
Fix memory leak using cholmod library (bug #47372).
Rik <rik@octave.org>
parents:
21324
diff
changeset
|
331 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
|
332 |
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
333 return info; |
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
334 |
5506 | 335 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
336 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
337 octave_unused_parameter (a); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
338 octave_unused_parameter (natural); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
339 octave_unused_parameter (force); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
340 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
341 (*current_liboctave_error_handler) |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
342 ("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
|
343 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
344 return info; |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21602
diff
changeset
|
345 |
5506 | 346 #endif |
347 } | |
348 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
349 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
350 SparseMatrix |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
351 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
|
352 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
353 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
354 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
355 octave_idx_type n = Lsparse->nrow; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
356 SparseMatrix p (n, n, n); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
357 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
358 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
|
359 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
360 p.xcidx (i) = i; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
361 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
|
362 p.xdata (i) = 1; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
363 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
364 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
365 p.xcidx (n) = n; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
366 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
367 return p; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
368 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
369 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
370 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
371 return SparseMatrix (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
372 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
373 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
374 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
375 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
376 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
377 sparse_chol<chol_type>::sparse_chol (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
378 : 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
|
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 (const chol_type& a, bool natural, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
383 bool force) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
384 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
385 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
|
386 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
387 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
388 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
389 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
|
390 bool natural, bool force) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
391 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
392 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
|
393 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
394 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
395 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
396 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
|
397 bool natural) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
398 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
399 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
|
400 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
401 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
402 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
403 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
|
404 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
405 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
|
406 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
407 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
408 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
409 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
|
410 : rep (a.rep) |
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 rep->count++; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
413 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
414 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
415 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
416 sparse_chol<chol_type>::~sparse_chol (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
417 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
418 if (--rep->count == 0) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
419 delete rep; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
420 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
421 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
422 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
423 sparse_chol<chol_type>& |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
424 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
|
425 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
426 if (this != &a) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
427 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
428 if (--rep->count == 0) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
429 delete rep; |
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 rep = a.rep; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
432 rep->count++; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
433 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
434 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
435 return *this; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
436 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
437 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
438 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
439 chol_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
440 sparse_chol<chol_type>::L (void) const |
5506 | 441 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
442 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
443 |
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
|
444 cholmod_sparse *m = rep->L (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
445 |
5506 | 446 octave_idx_type nc = m->ncol; |
447 octave_idx_type nnz = m->nzmax; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
448 |
5506 | 449 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
|
450 |
5506 | 451 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
|
452 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
|
453 |
5506 | 454 for (octave_idx_type i = 0; i < nnz; i++) |
455 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
456 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
|
457 ret.xdata (i) = static_cast<chol_elt *>(m->x)[i]; |
5506 | 458 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
459 |
5506 | 460 return ret; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
461 |
5506 | 462 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
463 |
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
|
464 return chol_type (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
465 |
5506 | 466 #endif |
467 } | |
468 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
469 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
470 octave_idx_type |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
471 sparse_chol<chol_type>::P (void) const |
5506 | 472 { |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
473 return rep->P (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
474 } |
5506 | 475 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
476 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
|
477 RowVector |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
478 sparse_chol<chol_type>::perm (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
479 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
480 return rep->perm (); |
5506 | 481 } |
482 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
483 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
484 SparseMatrix |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
485 sparse_chol<chol_type>::Q (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
486 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
487 return rep->Q (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
488 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
489 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
490 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
491 bool |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
492 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
|
493 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
494 return rep->is_positive_definite (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
495 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
496 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
497 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
498 double |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
499 sparse_chol<chol_type>::rcond (void) const |
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 return rep->rcond (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
502 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
503 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
504 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
505 chol_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
506 sparse_chol<chol_type>::inverse (void) const |
5506 | 507 { |
508 chol_type retval; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
509 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
510 #if defined (HAVE_CHOLMOD) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
511 |
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
|
512 cholmod_sparse *m = rep->L (); |
5506 | 513 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
|
514 RowVector perms = rep->perm (); |
5506 | 515 double rcond2; |
516 octave_idx_type info; | |
5785 | 517 MatrixType mattype (MatrixType::Upper); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
518 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0); |
5506 | 519 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
520 if (perms.numel () == n) |
5506 | 521 { |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
522 SparseMatrix Qc = Q (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
523 |
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
|
524 retval = Qc * linv * linv.hermitian () * Qc.transpose (); |
5506 | 525 } |
526 else | |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
7637
diff
changeset
|
527 retval = linv * linv.hermitian (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
528 |
5506 | 529 #endif |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
530 |
5506 | 531 return retval; |
532 } | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
533 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
534 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
535 chol_type |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
536 chol2inv (const chol_type& r) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
537 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
538 octave_idx_type r_nr = r.rows (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
539 octave_idx_type r_nc = r.cols (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
540 chol_type retval; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
541 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
542 if (r_nr != r_nc) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
543 (*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
|
544 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
545 MatrixType mattype (r); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
546 int typ = mattype.type (false); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
547 double rcond; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
548 octave_idx_type info; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
549 chol_type rinv; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
550 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
551 if (typ == MatrixType::Upper) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
552 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
553 rinv = r.inverse (mattype, info, rcond, true, false); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
554 retval = rinv.transpose () * rinv; |
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 else if (typ == MatrixType::Lower) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
557 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
558 rinv = r.transpose ().inverse (mattype, info, rcond, true, false); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
559 retval = rinv.transpose () * rinv; |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
562 (*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
|
563 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
564 return retval; |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
567 // SparseComplexMatrix specialization (the value for the NATURAL |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
568 // 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
|
569 // different from the default). |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
570 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
571 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
572 sparse_chol<SparseComplexMatrix>::sparse_chol (const SparseComplexMatrix& a, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
573 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
|
574 : rep ( |
5169d5993d77
sparse-chol.cc: Fix minor syntax error to compile with older gcc
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
575 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
|
576 { } |
21186
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
577 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
578 // Instantiations we need. |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
579 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
580 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
|
581 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
582 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
|
583 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
584 template SparseMatrix |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
585 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
|
586 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
587 template SparseComplexMatrix |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
588 chol2inv<SparseComplexMatrix> (const SparseComplexMatrix& r); |