Mercurial > octave
annotate liboctave/numeric/sparse-chol.cc @ 21186:7f35125714b4
don't install some internal headers and template sources
* sparse-chol-inst.cc: Delete.
Instantiate needed classes and functions in sparse-chol.cc.
* sparse-lu-inst.cc: Delete.
Instantiate needed classes and functions in sparse-lu.cc.
* sparse-qr-inst.cc: Delete.
Instantiate needed classes and functions in sparse-qr.cc.
* sighandlers.h: Include sys/types.h.
Don't include syswait.h or siglist.h
* sparse-chol.h, sparse-qr.h: Don't include oct-sparse.h.
* symbfact.cc, sparse-dmsolve.cc: Include oct-sparse.h.
* octave.cc: Include siglist.h.
* liboctave/numeric/module.mk: Don't install sparse-chol.cc,
sparse-lu.cc, or sparse-qr.cc with header files.
* liboctave/util/module.mk: Don't install oct-sparse.h.
* liboctave/system/module.mk: Don't install pathlen.h, sysdir.h, or
syswait.h header files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2016 23:44:49 -0500 |
parents | a10f60e13243 |
children | f7121e111991 |
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 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
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) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
43 : count (1), is_pd (false), minor_p (0), perms (), cond (0), |
5511 | 44 #ifdef HAVE_CHOLMOD |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
45 Lsparse (0), Common () |
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) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
50 : count (1), is_pd (false), minor_p (0), perms (), cond (0), |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
51 #ifdef HAVE_CHOLMOD |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
52 Lsparse (0), Common () |
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) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
60 : count (1), is_pd (false), minor_p (0), perms (), cond (0), |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
61 #ifdef HAVE_CHOLMOD |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
62 Lsparse (0), Common () |
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 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
70 #ifdef HAVE_CHOLMOD |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
71 if (is_pd) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
72 CHOLMOD_NAME (free_sparse) (&Lsparse, &Common); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
73 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
74 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
75 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
76 cholmod_sparse *L (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
77 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
78 #ifdef HAVE_CHOLMOD |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
79 return Lsparse; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
80 #else |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
81 return 0; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
82 #endif |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
83 } |
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 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
87 #ifdef HAVE_CHOLMOD |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
95 ColumnVector perm (void) const { return perms + 1; } |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
111 ColumnVector perms; |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
115 #ifdef HAVE_CHOLMOD |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
132 #ifdef HAVE_CHOLMOD |
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 |
5506 | 205 #ifdef 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; | |
21140
e06e600f396a
eliminate use of USE_64_BIT_IDX_T
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
258 #if defined (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 { | |
275 cm->nmethods = 1 ; | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
276 cm->method[0].ordering = CHOLMOD_NATURAL ; |
5518 | 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 } |
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
|
323 |
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 static char tmp[] = " "; |
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
|
325 |
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
|
326 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
|
327 CHOLMOD_NAME(free_factor) (&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
|
328 CHOLMOD_NAME(finish) (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
|
329 CHOLMOD_NAME(print_common) (tmp, 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
|
330 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5506 | 331 } |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
336 (*current_liboctave_error_handler) |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
337 ("support for CHOLMOD was unavailable or disabled when liboctave was built"); |
5506 | 338 #endif |
339 } | |
340 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
341 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
342 SparseMatrix |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
343 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
|
344 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
345 #ifdef HAVE_CHOLMOD |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
346 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
347 octave_idx_type n = Lsparse->nrow; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
348 SparseMatrix p (n, n, n); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
349 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
350 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
|
351 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
352 p.xcidx (i) = i; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
353 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
|
354 p.xdata (i) = 1; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
355 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
356 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
357 p.xcidx (n) = n; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
358 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
359 return p; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
360 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
361 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
362 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
363 return SparseMatrix (); |
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 #endif |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
368 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
369 sparse_chol<chol_type>::sparse_chol (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
370 : 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
|
371 { } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
372 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
373 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
374 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
|
375 bool force) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
376 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
377 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
|
378 { } |
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 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
381 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
|
382 bool natural, bool force) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
383 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
384 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
|
385 { } |
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 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
388 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
|
389 bool natural) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
390 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
391 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
|
392 { } |
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 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
395 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
|
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, false, false)) |
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 sparse_chol<chol_type>& a) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
402 : rep (a.rep) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
403 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
404 rep->count++; |
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 (void) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
409 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
410 if (--rep->count == 0) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
411 delete rep; |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
414 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
415 sparse_chol<chol_type>& |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
416 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
|
417 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
418 if (this != &a) |
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 if (--rep->count == 0) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
421 delete rep; |
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 rep = a.rep; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
424 rep->count++; |
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 return *this; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
428 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
429 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
430 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
431 chol_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
432 sparse_chol<chol_type>::L (void) const |
5506 | 433 { |
434 #ifdef HAVE_CHOLMOD | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
435 |
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
|
436 cholmod_sparse *m = rep->L (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
437 |
5506 | 438 octave_idx_type nc = m->ncol; |
439 octave_idx_type nnz = m->nzmax; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
440 |
5506 | 441 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
|
442 |
5506 | 443 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
|
444 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
|
445 |
5506 | 446 for (octave_idx_type i = 0; i < nnz; i++) |
447 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
448 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
|
449 ret.xdata (i) = static_cast<chol_elt *>(m->x)[i]; |
5506 | 450 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
451 |
5506 | 452 return ret; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
453 |
5506 | 454 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
455 |
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
|
456 return chol_type (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
457 |
5506 | 458 #endif |
459 } | |
460 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
461 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
462 octave_idx_type |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
463 sparse_chol<chol_type>::P (void) const |
5506 | 464 { |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
465 return rep->P (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
466 } |
5506 | 467 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
468 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
469 ColumnVector |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
470 sparse_chol<chol_type>::perm (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
471 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
472 return rep->perm (); |
5506 | 473 } |
474 | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
475 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
476 SparseMatrix |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
477 sparse_chol<chol_type>::Q (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
478 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
479 return rep->Q (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
480 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
481 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
482 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
483 bool |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
484 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
|
485 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
486 return rep->is_positive_definite (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
487 } |
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 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
490 double |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
491 sparse_chol<chol_type>::rcond (void) const |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
492 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
493 return rep->rcond (); |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
496 template <typename chol_type> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
497 chol_type |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
498 sparse_chol<chol_type>::inverse (void) const |
5506 | 499 { |
500 chol_type retval; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
501 |
5506 | 502 #ifdef HAVE_CHOLMOD |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
503 |
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
|
504 cholmod_sparse *m = rep->L (); |
5506 | 505 octave_idx_type n = m->ncol; |
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
|
506 ColumnVector perms = rep->perm (); |
5506 | 507 double rcond2; |
508 octave_idx_type info; | |
5785 | 509 MatrixType mattype (MatrixType::Upper); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
510 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0); |
5506 | 511 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
512 if (perms.numel () == n) |
5506 | 513 { |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
514 SparseMatrix Qc = Q (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
515 |
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
|
516 retval = Qc * linv * linv.hermitian () * Qc.transpose (); |
5506 | 517 } |
518 else | |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
7637
diff
changeset
|
519 retval = linv * linv.hermitian (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
520 |
5506 | 521 #endif |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
522 |
5506 | 523 return retval; |
524 } | |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
525 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
526 template <typename chol_type> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
527 chol_type |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
528 chol2inv (const chol_type& r) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
529 { |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
530 octave_idx_type r_nr = r.rows (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
531 octave_idx_type r_nc = r.cols (); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
532 chol_type retval; |
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 if (r_nr != r_nc) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
535 (*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
|
536 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
537 MatrixType mattype (r); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
538 int typ = mattype.type (false); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
539 double rcond; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
540 octave_idx_type info; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
541 chol_type rinv; |
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 if (typ == MatrixType::Upper) |
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 rinv = r.inverse (mattype, info, rcond, true, false); |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
546 retval = rinv.transpose () * rinv; |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
547 } |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
548 else if (typ == MatrixType::Lower) |
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 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
|
551 retval = rinv.transpose () * rinv; |
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 else |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
554 (*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
|
555 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
556 return retval; |
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 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
559 // SparseComplexMatrix specialization (the value for the NATURAL |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
560 // 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
|
561 // different from the default). |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
562 |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
563 template <> |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
564 sparse_chol<SparseComplexMatrix>::sparse_chol (const SparseComplexMatrix& a, |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
565 octave_idx_type& info) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
566 : rep (new typename |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
567 sparse_chol<SparseComplexMatrix>::sparse_chol_rep (a, info, true, false)) |
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
568 { } |
21186
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
569 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
570 // Instantiations we need. |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
571 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
572 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
|
573 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
574 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
|
575 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
576 template SparseMatrix |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
577 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
|
578 |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
579 template SparseComplexMatrix |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
580 chol2inv<SparseComplexMatrix> (const SparseComplexMatrix& r); |