Mercurial > jwe > octave
annotate liboctave/numeric/sparse-base-chol.cc @ 21136:7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
* Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MArray.cc,
PermMatrix.cc, Sparse.cc, Sparse.h, chMatrix.cc, chNDArray.cc, dColVector.cc,
dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc,
fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
idx-vector.cc, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc,
CmplxLU.cc, CmplxQR.cc, CmplxSCHUR.cc, CmplxSVD.cc, DASPK.cc, EIG.cc, LSODE.cc,
Quad.cc, SparseCmplxCHOL.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc,
SparsedbleCHOL.cc, SparsedbleLU.cc, base-lu.cc, bsxfun-defs.cc, dbleAEPBAL.cc,
dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc, dbleSCHUR.cc,
dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc, fCmplxCHOL.cc, fCmplxLU.cc,
fCmplxQR.cc, fCmplxSCHUR.cc, fEIG.cc, floatAEPBAL.cc, floatCHOL.cc,
floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc, floatSCHUR.cc,
floatSVD.cc, lo-specfun.cc, oct-fftw.cc, oct-rand.cc, oct-spparms.cc,
sparse-base-chol.cc, sparse-dmsolve.cc, file-ops.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-syscalls.cc, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, lo-ieee.cc, lo-regexp.cc, oct-base64.cc, oct-shlib.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-util.cc, unwind-prot.cc:
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 23 Jan 2016 13:52:03 -0800 |
parents | f5b17eb2508b |
children | 538b57866b90 |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19139
diff
changeset
|
3 Copyright (C) 2005-2015 David Bateman |
11523 | 4 Copyright (C) 1998-2005 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5506 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5506 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5506 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "sparse-base-chol.h" | |
29 #include "sparse-util.h" | |
30 #include "lo-error.h" | |
31 #include "oct-sparse.h" | |
32 #include "oct-spparms.h" | |
33 #include "quit.h" | |
5785 | 34 #include "MatrixType.h" |
5506 | 35 |
5511 | 36 #ifdef HAVE_CHOLMOD |
5506 | 37 // Can't use CHOLMOD_NAME(drop)(0.0, S, cm). It doesn't treat complex matrices |
38 template <class chol_type, class chol_elt, class p_type> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 void |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
40 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep::drop_zeros |
5506 | 41 (const cholmod_sparse* S) |
42 { | |
43 chol_elt sik; | |
44 octave_idx_type *Sp, *Si; | |
45 chol_elt *Sx; | |
46 octave_idx_type pdest, k, ncol, p, pend; | |
47 | |
5518 | 48 if (! S) |
5506 | 49 return; |
50 | |
51 Sp = static_cast<octave_idx_type *>(S->p); | |
52 Si = static_cast<octave_idx_type *>(S->i); | |
53 Sx = static_cast<chol_elt *>(S->x); | |
54 pdest = 0; | |
55 ncol = S->ncol; | |
56 | |
57 for (k = 0; k < ncol; k++) | |
58 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
59 p = Sp[k]; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
60 pend = Sp[k+1]; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
61 Sp[k] = pdest; |
5506 | 62 for (; p < pend; p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
63 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
64 sik = Sx[p]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
65 if (CHOLMOD_IS_NONZERO (sik)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
66 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
67 if (p != pdest) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
68 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
69 Si[pdest] = Si[p]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
70 Sx[pdest] = sik; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
71 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
72 pdest++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
73 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
74 } |
5506 | 75 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
76 Sp[ncol] = pdest; |
5506 | 77 } |
5511 | 78 #endif |
5506 | 79 |
80 template <class chol_type, class chol_elt, class p_type> | |
81 octave_idx_type | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
82 sparse_base_chol<chol_type, chol_elt, p_type>::sparse_base_chol_rep::init |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
83 (const chol_type& a, bool natural, bool force) |
5506 | 84 { |
5648 | 85 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
|
86 |
5506 | 87 #ifdef HAVE_CHOLMOD |
88 octave_idx_type a_nr = a.rows (); | |
89 octave_idx_type a_nc = a.cols (); | |
90 | |
91 if (a_nr != a_nc) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
92 (*current_liboctave_error_handler) ("SparseCHOL requires square matrix"); |
5506 | 93 |
94 cholmod_common *cm = &Common; | |
95 | |
96 // Setup initial parameters | |
97 CHOLMOD_NAME(start) (cm); | |
5518 | 98 cm->prefer_zomplex = false; |
5506 | 99 |
5893 | 100 double spu = octave_sparse_params::get_key ("spumoni"); |
5506 | 101 if (spu == 0.) |
102 { | |
103 cm->print = -1; | |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
104 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, 0); |
5506 | 105 } |
106 else | |
107 { | |
5760 | 108 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
|
109 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint); |
5506 | 110 } |
111 | |
112 cm->error_handler = &SparseCholError; | |
19139
afd6179d2616
allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
113 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
|
114 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot); |
5506 | 115 |
5518 | 116 cm->final_asis = false; |
117 cm->final_super = false; | |
118 cm->final_ll = true; | |
119 cm->final_pack = true; | |
120 cm->final_monotonic = true; | |
121 cm->final_resymbol = false; | |
5506 | 122 |
123 cholmod_sparse A; | |
124 cholmod_sparse *ac = &A; | |
125 double dummy; | |
126 ac->nrow = a_nr; | |
127 ac->ncol = a_nc; | |
128 | |
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
|
129 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
|
130 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
|
131 ac->nzmax = a.nnz (); |
5518 | 132 ac->packed = true; |
133 ac->sorted = true; | |
134 ac->nz = 0; | |
16313
6aafe87a3144
use int64_t for idx type if --enable-64
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
135 #ifdef USE_64_BIT_IDX_T |
5506 | 136 ac->itype = CHOLMOD_LONG; |
137 #else | |
138 ac->itype = CHOLMOD_INT; | |
139 #endif | |
140 ac->dtype = CHOLMOD_DOUBLE; | |
141 ac->stype = 1; | |
142 #ifdef OCTAVE_CHOLMOD_TYPE | |
143 ac->xtype = OCTAVE_CHOLMOD_TYPE; | |
144 #else | |
145 ac->xtype = CHOLMOD_REAL; | |
146 #endif | |
147 | |
148 if (a_nr < 1) | |
149 ac->x = &dummy; | |
150 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
|
151 ac->x = a.data (); |
5506 | 152 |
153 // use natural ordering if no q output parameter | |
154 if (natural) | |
155 { | |
156 cm->nmethods = 1 ; | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
157 cm->method[0].ordering = CHOLMOD_NATURAL ; |
5518 | 158 cm->postorder = false ; |
5506 | 159 } |
160 | |
161 cholmod_factor *Lfactor; | |
162 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
163 Lfactor = CHOLMOD_NAME(analyze) (ac, cm); | |
164 CHOLMOD_NAME(factorize) (ac, Lfactor, cm); | |
165 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
166 | |
167 is_pd = cm->status == CHOLMOD_OK; | |
168 info = (is_pd ? 0 : cm->status); | |
169 | |
15264
94cdf82d4a0c
don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents:
15185
diff
changeset
|
170 if (is_pd || force) |
5506 | 171 { |
172 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
|
173 cond = CHOLMOD_NAME(rcond) (Lfactor, cm); |
5506 | 174 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
|
175 |
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
|
176 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
|
177 |
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
|
178 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
|
179 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
|
180 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5506 | 181 |
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
|
182 if (minor_p > 0 && minor_p < a_nr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
184 size_t n1 = a_nr + 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
185 Lsparse->p = CHOLMOD_NAME(realloc) (minor_p+1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 sizeof(octave_idx_type), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
187 Lsparse->p, &n1, cm); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
189 CHOLMOD_NAME(reallocate_sparse) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
190 (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
|
191 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
192 Lsparse->ncol = minor_p; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
193 } |
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
|
194 |
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
|
195 drop_zeros (Lsparse); |
5506 | 196 |
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
|
197 if (! natural) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
198 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
199 perms.resize (a_nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
200 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
|
201 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
|
202 } |
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
|
203 |
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
|
204 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
|
205 |
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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5506 | 211 } |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
212 |
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
213 return info; |
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
214 |
5506 | 215 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
216 (*current_liboctave_error_handler) |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
217 ("support for CHOLMOD was unavailable or disabled when liboctave was built"); |
5506 | 218 #endif |
219 } | |
220 | |
221 template <class chol_type, class chol_elt, class p_type> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
222 chol_type |
5506 | 223 sparse_base_chol<chol_type, chol_elt, p_type>::L (void) const |
224 { | |
225 #ifdef HAVE_CHOLMOD | |
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
|
226 cholmod_sparse *m = rep->L (); |
5506 | 227 octave_idx_type nc = m->ncol; |
228 octave_idx_type nnz = m->nzmax; | |
229 chol_type ret (m->nrow, nc, nnz); | |
230 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
|
231 ret.xcidx (j) = static_cast<octave_idx_type *>(m->p)[j]; |
5506 | 232 for (octave_idx_type i = 0; i < nnz; i++) |
233 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
234 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
|
235 ret.xdata (i) = static_cast<chol_elt *>(m->x)[i]; |
5506 | 236 } |
237 return ret; | |
238 #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
|
239 return chol_type (); |
5506 | 240 #endif |
241 } | |
242 | |
243 template <class chol_type, class chol_elt, class p_type> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
244 p_type |
5506 | 245 sparse_base_chol<chol_type, chol_elt, p_type>:: |
246 sparse_base_chol_rep::Q (void) const | |
247 { | |
248 #ifdef HAVE_CHOLMOD | |
249 octave_idx_type n = Lsparse->nrow; | |
250 p_type p (n, n, n); | |
251 | |
252 for (octave_idx_type i = 0; i < n; i++) | |
253 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
254 p.xcidx (i) = i; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
255 p.xridx (i) = static_cast<octave_idx_type>(perms (i)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
256 p.xdata (i) = 1; |
5506 | 257 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
258 p.xcidx (n) = n; |
5506 | 259 |
260 return p; | |
261 #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
|
262 return p_type (); |
5506 | 263 #endif |
264 } | |
265 | |
266 template <class chol_type, class chol_elt, class p_type> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
267 chol_type |
5506 | 268 sparse_base_chol<chol_type, chol_elt, p_type>::inverse (void) const |
269 { | |
270 chol_type retval; | |
271 #ifdef HAVE_CHOLMOD | |
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
|
272 cholmod_sparse *m = rep->L (); |
5506 | 273 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
|
274 ColumnVector perms = rep->perm (); |
5506 | 275 double rcond2; |
276 octave_idx_type info; | |
5785 | 277 MatrixType mattype (MatrixType::Upper); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
278 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0); |
5506 | 279 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
280 if (perms.numel () == n) |
5506 | 281 { |
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
|
282 p_type Qc = Q (); |
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
|
283 retval = Qc * linv * linv.hermitian () * Qc.transpose (); |
5506 | 284 } |
285 else | |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
7637
diff
changeset
|
286 retval = linv * linv.hermitian (); |
5506 | 287 #endif |
288 return retval; | |
289 } |