Mercurial > octave-antonio
annotate src/DLD-FUNCTIONS/symbfact.cc @ 10840:89f4d7e294cc
Grammarcheck .cc files
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 31 Jul 2010 11:18:11 -0700 |
parents | d0ce5e973937 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2005, 2006, 2007, 2008 David Bateman |
7016 | 4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Andy Adler |
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 | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
28 #include "SparseCmplxCHOL.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
29 #include "SparsedbleCHOL.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
30 #include "oct-spparms.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
31 #include "sparse-util.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
32 #include "oct-locbuf.h" |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
33 |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
34 #include "ov-re-sparse.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
35 #include "ov-cx-sparse.h" |
5506 | 36 #include "defun-dld.h" |
37 #include "error.h" | |
38 #include "gripes.h" | |
39 #include "oct-obj.h" | |
40 #include "utils.h" | |
41 | |
42 DEFUN_DLD (symbfact, args, nargout, | |
43 "-*- texinfo -*-\n\ | |
6547 | 44 @deftypefn {Loadable Function} {[@var{count}, @var{h}, @var{parent}, @var{post}, @var{r}] =} symbfact (@var{s}, @var{typ}, @var{mode})\n\ |
5506 | 45 \n\ |
46 Performs a symbolic factorization analysis on the sparse matrix @var{s}.\n\ | |
47 Where\n\ | |
48 \n\ | |
49 @table @asis\n\ | |
50 @item @var{s}\n\ | |
51 @var{s} is a complex or real sparse matrix.\n\ | |
52 \n\ | |
53 @item @var{typ}\n\ | |
54 Is the type of the factorization and can be one of\n\ | |
55 \n\ | |
56 @table @code\n\ | |
57 @item sym\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
58 Factorize @var{s}. This is the default.\n\ |
5506 | 59 \n\ |
60 @item col\n\ | |
61 Factorize @code{@var{s}' * @var{s}}.\n\ | |
10840 | 62 \n\ |
5506 | 63 @item row\n\ |
64 Factorize @code{@var{s} * @var{s}'}.\n\ | |
10840 | 65 \n\ |
5506 | 66 @item lo\n\ |
67 Factorize @code{@var{s}'}\n\ | |
68 @end table\n\ | |
69 \n\ | |
70 @item @var{mode}\n\ | |
71 The default is to return the Cholesky factorization for @var{r}, and if\n\ | |
7001 | 72 @var{mode} is 'L', the conjugate transpose of the Cholesky factorization\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
73 is returned. The conjugate transpose version is faster and uses less\n\ |
5506 | 74 memory, but returns the same values for @var{count}, @var{h}, @var{parent}\n\ |
75 and @var{post} outputs.\n\ | |
76 @end table\n\ | |
77 \n\ | |
78 The output variables are\n\ | |
79 \n\ | |
80 @table @asis\n\ | |
81 @item @var{count}\n\ | |
82 The row counts of the Cholesky factorization as determined by @var{typ}.\n\ | |
83 \n\ | |
84 @item @var{h}\n\ | |
85 The height of the elimination tree.\n\ | |
86 \n\ | |
87 @item @var{parent}\n\ | |
88 The elimination tree itself.\n\ | |
89 \n\ | |
90 @item @var{post}\n\ | |
91 A sparse boolean matrix whose structure is that of the Cholesky\n\ | |
92 factorization as determined by @var{typ}.\n\ | |
93 @end table\n\ | |
94 @end deftypefn") | |
95 { | |
96 octave_value_list retval; | |
97 int nargin = args.length (); | |
98 | |
99 if (nargin < 1 || nargin > 3 || nargout > 5) | |
100 { | |
5823 | 101 print_usage (); |
5506 | 102 return retval; |
103 } | |
104 | |
5512 | 105 #ifdef HAVE_CHOLMOD |
106 | |
5506 | 107 cholmod_common Common; |
108 cholmod_common *cm = &Common; | |
109 CHOLMOD_NAME(start) (cm); | |
110 | |
5893 | 111 double spu = octave_sparse_params::get_key ("spumoni"); |
5506 | 112 if (spu == 0.) |
113 { | |
114 cm->print = -1; | |
7520 | 115 cm->print_function = 0; |
5506 | 116 } |
117 else | |
118 { | |
5760 | 119 cm->print = static_cast<int> (spu) + 2; |
5506 | 120 cm->print_function =&SparseCholPrint; |
121 } | |
122 | |
123 cm->error_handler = &SparseCholError; | |
124 cm->complex_divide = CHOLMOD_NAME(divcomplex); | |
125 cm->hypotenuse = CHOLMOD_NAME(hypot); | |
126 | |
127 double dummy; | |
128 cholmod_sparse Astore; | |
129 cholmod_sparse *A = &Astore; | |
5527 | 130 A->packed = true; |
131 A->sorted = true; | |
7520 | 132 A->nz = 0; |
5506 | 133 #ifdef IDX_TYPE_LONG |
134 A->itype = CHOLMOD_LONG; | |
135 #else | |
136 A->itype = CHOLMOD_INT; | |
137 #endif | |
138 A->dtype = CHOLMOD_DOUBLE; | |
139 A->stype = 1; | |
140 A->x = &dummy; | |
141 | |
142 if (args(0).is_real_type ()) | |
143 { | |
144 const SparseMatrix a = args(0).sparse_matrix_value(); | |
145 A->nrow = a.rows(); | |
146 A->ncol = a.cols(); | |
147 A->p = a.cidx(); | |
148 A->i = a.ridx(); | |
5604 | 149 A->nzmax = a.nnz(); |
5506 | 150 A->xtype = CHOLMOD_REAL; |
151 | |
152 if (a.rows() > 0 && a.cols() > 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
153 A->x = a.data(); |
5506 | 154 } |
155 else if (args(0).is_complex_type ()) | |
156 { | |
157 const SparseComplexMatrix a = args(0).sparse_complex_matrix_value(); | |
158 A->nrow = a.rows(); | |
159 A->ncol = a.cols(); | |
160 A->p = a.cidx(); | |
161 A->i = a.ridx(); | |
5604 | 162 A->nzmax = a.nnz(); |
5506 | 163 A->xtype = CHOLMOD_COMPLEX; |
164 | |
165 if (a.rows() > 0 && a.cols() > 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
166 A->x = a.data(); |
5506 | 167 } |
168 else | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7520
diff
changeset
|
169 gripe_wrong_type_arg ("symbfact", args(0)); |
5506 | 170 |
5527 | 171 octave_idx_type coletree = false; |
5506 | 172 octave_idx_type n = A->nrow; |
173 | |
174 if (nargin > 1) | |
175 { | |
176 char ch; | |
177 std::string str = args(1).string_value(); | |
178 ch = tolower (str.c_str()[0]); | |
179 if (ch == 'r') | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
180 A->stype = 0; |
5506 | 181 else if (ch == 'c') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
182 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
183 n = A->ncol; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
184 coletree = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
185 A->stype = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
186 } |
5506 | 187 else if (ch == 's') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
188 A->stype = 1; |
5506 | 189 else if (ch == 's') |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
190 A->stype = -1; |
5506 | 191 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
192 error ("Unrecognized typ in symbolic factorization"); |
5506 | 193 } |
194 | |
195 if (A->stype && A->nrow != A->ncol) | |
196 error ("Matrix must be square"); | |
197 | |
198 if (!error_state) | |
199 { | |
200 OCTAVE_LOCAL_BUFFER (octave_idx_type, Parent, n); | |
201 OCTAVE_LOCAL_BUFFER (octave_idx_type, Post, n); | |
202 OCTAVE_LOCAL_BUFFER (octave_idx_type, ColCount, n); | |
203 OCTAVE_LOCAL_BUFFER (octave_idx_type, First, n); | |
204 OCTAVE_LOCAL_BUFFER (octave_idx_type, Level, n); | |
205 | |
206 cholmod_sparse *F = CHOLMOD_NAME(transpose) (A, 0, cm); | |
207 cholmod_sparse *Aup, *Alo; | |
208 | |
209 if (A->stype == 1 || coletree) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
210 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
211 Aup = A ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
212 Alo = F ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
213 } |
5506 | 214 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
215 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
216 Aup = F ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
217 Alo = A ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
218 } |
5506 | 219 |
220 CHOLMOD_NAME(etree) (Aup, Parent, cm); | |
221 | |
222 if (cm->status < CHOLMOD_OK) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
223 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
224 error("matrix corrupted"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
225 goto symbfact_error; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
226 } |
5506 | 227 |
7520 | 228 if (CHOLMOD_NAME(postorder) (Parent, n, 0, Post, cm) != n) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
229 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
230 error("postorder failed"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
231 goto symbfact_error; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
232 } |
5506 | 233 |
7520 | 234 CHOLMOD_NAME(rowcolcounts) (Alo, 0, 0, Parent, Post, 0, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
235 ColCount, First, Level, cm); |
5506 | 236 |
237 if (cm->status < CHOLMOD_OK) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
238 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
239 error("matrix corrupted"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
240 goto symbfact_error; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
241 } |
5506 | 242 |
243 if (nargout > 4) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
244 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
245 cholmod_sparse *A1, *A2; |
5506 | 246 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
247 if (A->stype == 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
248 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
249 A1 = A; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
250 A2 = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
251 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
252 else if (A->stype == -1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
253 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
254 A1 = F; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
255 A2 = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
256 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
257 else if (coletree) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
258 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
259 A1 = F; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
260 A2 = A; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
261 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
262 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
263 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
264 A1 = A; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
265 A2 = F; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
266 } |
5506 | 267 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
268 // count the total number of entries in L |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
269 octave_idx_type lnz = 0 ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
270 for (octave_idx_type j = 0 ; j < n ; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
271 lnz += ColCount [j] ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
272 |
5506 | 273 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
274 // allocate the output matrix L (pattern-only) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
275 SparseBoolMatrix L (n, n, lnz); |
5506 | 276 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
277 // initialize column pointers |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
278 lnz = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
279 for (octave_idx_type j = 0 ; j < n ; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
280 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
281 L.xcidx(j) = lnz; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
282 lnz += ColCount [j]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
283 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
284 L.xcidx(n) = lnz; |
5506 | 285 |
286 | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
287 /* create a copy of the column pointers */ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
288 octave_idx_type *W = First; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
289 for (octave_idx_type j = 0 ; j < n ; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
290 W [j] = L.xcidx(j); |
5506 | 291 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
292 // get workspace for computing one row of L |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
293 cholmod_sparse *R = cholmod_allocate_sparse (n, 1, n, false, true, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
294 0, CHOLMOD_PATTERN, cm); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
295 octave_idx_type *Rp = static_cast<octave_idx_type *>(R->p); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
296 octave_idx_type *Ri = static_cast<octave_idx_type *>(R->i); |
5506 | 297 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
298 // compute L one row at a time |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
299 for (octave_idx_type k = 0 ; k < n ; k++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
300 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
301 // get the kth row of L and store in the columns of L |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
302 CHOLMOD_NAME (row_subtree) (A1, A2, k, Parent, R, cm) ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
303 for (octave_idx_type p = 0 ; p < Rp [1] ; p++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
304 L.xridx (W [Ri [p]]++) = k ; |
5506 | 305 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
306 // add the diagonal entry |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
307 L.xridx (W [k]++) = k ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
308 } |
5506 | 309 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
310 // free workspace |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
311 cholmod_free_sparse (&R, cm) ; |
5506 | 312 |
313 | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
314 // transpose L to get R, or leave as is |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
315 if (nargin < 3) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
316 L = L.transpose (); |
5506 | 317 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
318 // fill numerical values of L with one's |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
319 for (octave_idx_type p = 0 ; p < lnz ; p++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
320 L.xdata(p) = true; |
5506 | 321 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
322 retval(4) = L; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
323 } |
5506 | 324 |
325 ColumnVector tmp (n); | |
326 if (nargout > 3) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
327 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
328 for (octave_idx_type i = 0; i < n; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
329 tmp(i) = Post[i] + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
330 retval(3) = tmp; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
331 } |
5506 | 332 |
333 if (nargout > 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
334 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
335 for (octave_idx_type i = 0; i < n; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
336 tmp(i) = Parent[i] + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
337 retval(2) = tmp; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
338 } |
5506 | 339 |
340 if (nargout > 1) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
341 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
342 /* compute the elimination tree height */ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
343 octave_idx_type height = 0 ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
344 for (int i = 0 ; i < n ; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
345 height = (height > Level[i] ? height : Level[i]); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
346 height++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
347 retval(1) = static_cast<double> (height); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
348 } |
5506 | 349 |
350 for (octave_idx_type i = 0; i < n; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
351 tmp(i) = ColCount[i]; |
5506 | 352 retval(0) = tmp; |
353 } | |
354 | |
5512 | 355 symbfact_error: |
356 #else | |
357 error ("symbfact: not available in this version of Octave"); | |
358 #endif | |
359 | |
5506 | 360 return retval; |
361 } |