Mercurial > octave-antonio
annotate src/DLD-FUNCTIONS/ccolamd.cc @ 10155:d0ce5e973937
DLD-FUNCTIONS/*.cc: delete Emacs local-variables settings
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Jan 2010 17:40:53 -0500 |
parents | 40dfc0c99116 |
children | c9780d8e228c |
rev | line source |
---|---|
5451 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2005, 2006, 2007, 2008 David Bateman |
5451 | 4 |
7016 | 5 This file is part of Octave. |
6 | |
5451 | 7 Octave is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
5451 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
5451 | 20 |
21 */ | |
22 | |
23 // This is the octave interface to ccolamd, which bore the copyright given | |
24 // in the help of the functions. | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include <config.h> | |
28 #endif | |
29 | |
30 #include <cstdlib> | |
31 | |
32 #include <string> | |
33 #include <vector> | |
34 | |
35 #include "ov.h" | |
36 #include "defun-dld.h" | |
37 #include "pager.h" | |
38 #include "ov-re-mat.h" | |
39 | |
40 #include "ov-re-sparse.h" | |
41 #include "ov-cx-sparse.h" | |
42 | |
43 #include "oct-sparse.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
44 #include "oct-locbuf.h" |
5451 | 45 |
46 #ifdef IDX_TYPE_LONG | |
47 #define CCOLAMD_NAME(name) ccolamd_l ## name | |
48 #define CSYMAMD_NAME(name) csymamd_l ## name | |
49 #else | |
50 #define CCOLAMD_NAME(name) ccolamd ## name | |
51 #define CSYMAMD_NAME(name) csymamd ## name | |
52 #endif | |
53 | |
54 DEFUN_DLD (ccolamd, args, nargout, | |
55 "-*- texinfo -*-\n\ | |
56 @deftypefn {Loadable Function} {@var{p} =} ccolamd (@var{s})\n\ | |
57 @deftypefnx {Loadable Function} {@var{p} =} ccolamd (@var{s}, @var{knobs})\n\ | |
58 @deftypefnx {Loadable Function} {@var{p} =} ccolamd (@var{s}, @var{knobs}, @var{cmember})\n\ | |
59 @deftypefnx {Loadable Function} {[@var{p}, @var{stats}] =} ccolamd (@dots{})\n\ | |
60 \n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
61 Constrained column approximate minimum degree permutation. @code{@var{p} =\n\ |
5451 | 62 ccolamd (@var{s})} returns the column approximate minimum degree permutation\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
63 vector for the sparse matrix @var{s}. For a non-symmetric matrix @var{s},\n\ |
7107 | 64 @code{@var{s} (:, @var{p})} tends to have sparser LU factors than @var{s}.\n\ |
65 @code{chol (@var{s} (:, @var{p})' * @var{s} (:, @var{p}))} also tends to be\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
66 sparser than @code{chol (@var{s}' * @var{s})}. @code{@var{p} = ccolamd\n\ |
7107 | 67 (@var{s}, 1)} optimizes the ordering for @code{lu (@var{s} (:, @var{p}))}.\n\ |
5451 | 68 The ordering is followed by a column elimination tree post-ordering.\n\ |
69 \n\ | |
70 @var{knobs} is an optional one- to five-element input vector, with a default\n\ | |
71 value of @code{[0 10 10 1 0]} if not present or empty. Entries not present\n\ | |
72 are set to their defaults.\n\ | |
73 \n\ | |
74 @table @code\n\ | |
75 @item @var{knobs}(1)\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
76 if nonzero, the ordering is optimized for @code{lu (S (:, p))}. It will be a\n\ |
7107 | 77 poor ordering for @code{chol (@var{s} (:, @var{p})' * @var{s} (:,\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
78 @var{p}))}. This is the most important knob for ccolamd.\n\ |
5451 | 79 \n\ |
80 @item @var{knob}(2)\n\ | |
7107 | 81 if @var{s} is m-by-n, rows with more than @code{max (16, @var{knobs} (2) *\n\ |
82 sqrt (n))} entries are ignored.\n\ | |
5451 | 83 \n\ |
84 @item @var{knob}(3)\n\ | |
7107 | 85 columns with more than @code{max (16, @var{knobs} (3) * sqrt (min (@var{m},\n\ |
86 @var{n})))} entries are ignored and ordered last in the output permutation\n\ | |
87 (subject to the cmember constraints).\n\ | |
5451 | 88 \n\ |
89 @item @var{knob}(4)\n\ | |
90 if nonzero, aggressive absorption is performed.\n\ | |
91 \n\ | |
92 @item @var{knob}(5)\n\ | |
93 if nonzero, statistics and knobs are printed.\n\ | |
94 \n\ | |
95 @end table\n\ | |
96 \n\ | |
97 @var{cmember} is an optional vector of length n. It defines the constraints\n\ | |
7107 | 98 on the column ordering. If @code{@var{cmember} (j) = @var{c}}, then column\n\ |
99 @var{j} is in constraint set @var{c} (@var{c} must be in the range 1 to\n\ | |
100 @var{n}). In the output permutation @var{p}, all columns in set 1 appear\n\ | |
101 first, followed by all columns in set 2, and so on. @code{@var{cmember} =\n\ | |
102 ones(1,n)} if not present or empty. @code{ccolamd (@var{s}, [], 1 :\n\ | |
103 @var{n})} returns @code{1 : @var{n}}\n\ | |
5451 | 104 \n\ |
7107 | 105 @code{@var{p} = ccolamd (@var{s})} is about the same as @code{@var{p} =\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
106 colamd (@var{s})}. @var{knobs} and its default values differ. @code{colamd}\n\ |
5451 | 107 always does aggressive absorption, and it finds an ordering suitable for\n\ |
7107 | 108 both @code{lu (@var{s} (:, @var{p}))} and @code{chol (@var{S} (:, @var{p})'\n\ |
109 * @var{s} (:, @var{p}))}; it cannot optimize its ordering for\n\ | |
110 @code{lu (@var{s} (:, @var{p}))} to the extent that\n\ | |
111 @code{ccolamd (@var{s}, 1)} can.\n\ | |
5451 | 112 \n\ |
113 @var{stats} is an optional 20-element output vector that provides data\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
114 about the ordering and the validity of the input matrix @var{s}. Ordering\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
115 statistics are in @code{@var{stats} (1 : 3)}. @code{@var{stats} (1)} and\n\ |
5451 | 116 @code{@var{stats} (2)} are the number of dense or empty rows and columns\n\ |
117 ignored by CCOLAMD and @code{@var{stats} (3)} is the number of garbage\n\ | |
118 collections performed on the internal data structure used by CCOLAMD\n\ | |
7107 | 119 (roughly of size @code{2.2 * nnz (@var{s}) + 4 * @var{m} + 7 * @var{n}}\n\ |
5451 | 120 integers).\n\ |
121 \n\ | |
7107 | 122 @code{@var{stats} (4 : 7)} provide information if CCOLAMD was able to\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
123 continue. The matrix is OK if @code{@var{stats} (4)} is zero, or 1 if\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
124 invalid. @code{@var{stats} (5)} is the rightmost column index that is\n\ |
5451 | 125 unsorted or contains duplicate entries, or zero if no such column exists.\n\ |
126 @code{@var{stats} (6)} is the last seen duplicate or out-of-order row\n\ | |
127 index in the column index given by @code{@var{stats} (5)}, or zero if no\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
128 such row index exists. @code{@var{stats} (7)} is the number of duplicate\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
129 or out-of-order row indices. @code{@var{stats} (8 : 20)} is always zero in\n\ |
5451 | 130 the current version of CCOLAMD (reserved for future use).\n\ |
131 \n\ | |
132 The authors of the code itself are S. Larimore, T. Davis (Uni of Florida)\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
133 and S. Rajamanickam in collaboration with J. Bilbert and E. Ng. Supported\n\ |
5451 | 134 by the National Science Foundation (DMS-9504974, DMS-9803599, CCR-0203270),\n\ |
135 and a grant from Sandia National Lab. See\n\ | |
136 @url{http://www.cise.ufl.edu/research/sparse} for ccolamd, csymamd, amd,\n\ | |
137 colamd, symamd, and other related orderings.\n\ | |
5642 | 138 @seealso{colamd, csymamd}\n\ |
139 @end deftypefn") | |
5451 | 140 { |
5771 | 141 octave_value_list retval; |
142 | |
5451 | 143 #ifdef HAVE_CCOLAMD |
5771 | 144 |
5451 | 145 int nargin = args.length (); |
146 int spumoni = 0; | |
147 | |
148 if (nargout < 0 || nargout > 2 || nargin < 0 || nargin > 3) | |
149 usage ("ccolamd: incorrect number of input and/or output arguments"); | |
150 else | |
151 { | |
152 // Get knobs | |
153 OCTAVE_LOCAL_BUFFER (double, knobs, CCOLAMD_KNOBS); | |
154 CCOLAMD_NAME (_set_defaults) (knobs); | |
155 | |
156 // Check for user-passed knobs | |
157 if (nargin > 1) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
158 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
159 NDArray User_knobs = args(1).array_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
160 int nel_User_knobs = User_knobs.length (); |
5451 | 161 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
162 if (nel_User_knobs > 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
163 knobs [CCOLAMD_LU] = (User_knobs (0) != 0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
164 if (nel_User_knobs > 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
165 knobs [CCOLAMD_DENSE_ROW] = User_knobs (1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
166 if (nel_User_knobs > 2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
167 knobs [CCOLAMD_DENSE_COL] = User_knobs (2); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
168 if (nel_User_knobs > 3) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
169 knobs [CCOLAMD_AGGRESSIVE] = (User_knobs (3) != 0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
170 if (nel_User_knobs > 4) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
171 spumoni = (User_knobs (4) != 0); |
5451 | 172 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
173 // print knob settings if spumoni is set |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
174 if (spumoni) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
175 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
176 octave_stdout << "\nccolamd version " << CCOLAMD_MAIN_VERSION << "." |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
177 << CCOLAMD_SUB_VERSION << ", " << CCOLAMD_DATE |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
178 << ":\nknobs(1): " << User_knobs (0) << ", order for "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
179 if ( knobs [CCOLAMD_LU] != 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
180 octave_stdout << "lu(A)\n"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
181 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
182 octave_stdout << "chol(A'*A)\n"; |
5451 | 183 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
184 if (knobs [CCOLAMD_DENSE_ROW] >= 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
185 octave_stdout << "knobs(2): " << User_knobs (1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
186 << ", rows with > max(16," |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
187 << knobs [CCOLAMD_DENSE_ROW] << "*sqrt(size(A,2)))" |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
188 << " entries removed\n"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
189 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
190 octave_stdout << "knobs(2): " << User_knobs (1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
191 << ", no dense rows removed\n"; |
5451 | 192 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
193 if (knobs [CCOLAMD_DENSE_COL] >= 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
194 octave_stdout << "knobs(3): " << User_knobs (2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
195 << ", cols with > max(16," |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
196 << knobs [CCOLAMD_DENSE_COL] << "*sqrt(size(A)))" |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
197 << " entries removed\n"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
198 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
199 octave_stdout << "knobs(3): " << User_knobs (2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
200 << ", no dense columns removed\n"; |
5451 | 201 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
202 if (knobs [CCOLAMD_AGGRESSIVE] != 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
203 octave_stdout << "knobs(4): " << User_knobs(3) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
204 << ", aggressive absorption: yes"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
205 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
206 octave_stdout << "knobs(4): " << User_knobs(3) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
207 << ", aggressive absorption: no"; |
5451 | 208 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
209 octave_stdout << "knobs(5): " << User_knobs (4) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
210 << ", statistics and knobs printed\n"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
211 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
212 } |
5451 | 213 |
214 octave_idx_type n_row, n_col, nnz; | |
215 octave_idx_type *ridx, *cidx; | |
216 SparseComplexMatrix scm; | |
217 SparseMatrix sm; | |
218 | |
5631 | 219 if (args(0).is_sparse_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
220 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
221 if (args(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
222 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
223 scm = args(0). sparse_complex_matrix_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
224 n_row = scm.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
225 n_col = scm.cols (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
226 nnz = scm.nzmax (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
227 ridx = scm.xridx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
228 cidx = scm.xcidx (); |
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 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
231 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
232 sm = args(0).sparse_matrix_value (); |
5451 | 233 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
234 n_row = sm.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
235 n_col = sm.cols (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
236 nnz = sm.nzmax (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
237 ridx = sm.xridx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
238 cidx = sm.xcidx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
239 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
240 } |
5451 | 241 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
242 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
243 if (args(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
244 sm = SparseMatrix (real (args(0).complex_matrix_value ())); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
245 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
246 sm = SparseMatrix (args(0).matrix_value ()); |
5451 | 247 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
248 n_row = sm.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
249 n_col = sm.cols (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
250 nnz = sm.nzmax (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
251 ridx = sm.xridx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
252 cidx = sm.xcidx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
253 } |
5451 | 254 |
255 // Allocate workspace for ccolamd | |
256 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, n_col+1); | |
257 for (octave_idx_type i = 0; i < n_col+1; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
258 p[i] = cidx [i]; |
5451 | 259 |
260 octave_idx_type Alen = CCOLAMD_NAME (_recommended) (nnz, n_row, n_col); | |
261 OCTAVE_LOCAL_BUFFER (octave_idx_type, A, Alen); | |
262 for (octave_idx_type i = 0; i < nnz; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
263 A[i] = ridx [i]; |
5451 | 264 |
265 OCTAVE_LOCAL_BUFFER (octave_idx_type, stats, CCOLAMD_STATS); | |
266 | |
267 if (nargin > 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
268 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
269 NDArray in_cmember = args(2).array_value(); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
270 octave_idx_type cslen = in_cmember.length(); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
271 OCTAVE_LOCAL_BUFFER (octave_idx_type, cmember, cslen); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
272 for (octave_idx_type i = 0; i < cslen; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
273 // convert cmember from 1-based to 0-based |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
274 cmember[i] = static_cast<octave_idx_type>(in_cmember(i) - 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
275 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
276 if (cslen != n_col) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
277 error ("ccolamd: cmember must be of length equal to #cols of A"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
278 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
279 // Order the columns (destroys A) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
280 if (! CCOLAMD_NAME () (n_row, n_col, Alen, A, p, knobs, stats, cmember)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
281 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
282 CCOLAMD_NAME (_report) (stats) ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
283 error ("ccolamd: internal error!"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
284 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
285 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
286 } |
5451 | 287 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
288 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
289 // Order the columns (destroys A) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
290 if (! CCOLAMD_NAME () (n_row, n_col, Alen, A, p, knobs, stats, 0)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
291 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
292 CCOLAMD_NAME (_report) (stats) ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
293 error ("ccolamd: internal error!"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
294 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
295 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
296 } |
5451 | 297 |
298 // return the permutation vector | |
299 NDArray out_perm (dim_vector (1, n_col)); | |
300 for (octave_idx_type i = 0; i < n_col; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
301 out_perm(i) = p [i] + 1; |
5451 | 302 |
303 retval (0) = out_perm; | |
304 | |
305 // print stats if spumoni > 0 | |
306 if (spumoni > 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
307 CCOLAMD_NAME (_report) (stats) ; |
5451 | 308 |
309 // Return the stats vector | |
310 if (nargout == 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
311 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
312 NDArray out_stats (dim_vector (1, CCOLAMD_STATS)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
313 for (octave_idx_type i = 0 ; i < CCOLAMD_STATS ; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
314 out_stats (i) = stats [i] ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
315 retval(1) = out_stats; |
5451 | 316 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
317 // fix stats (5) and (6), for 1-based information on |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
318 // jumbled matrix. note that this correction doesn't |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
319 // occur if symamd returns FALSE |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
320 out_stats (CCOLAMD_INFO1) ++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
321 out_stats (CCOLAMD_INFO2) ++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
322 } |
5451 | 323 } |
324 | |
325 #else | |
326 | |
327 error ("ccolamd: not available in this version of Octave"); | |
328 | |
329 #endif | |
5771 | 330 |
331 return retval; | |
5451 | 332 } |
333 | |
334 DEFUN_DLD (csymamd, args, nargout, | |
335 "-*- texinfo -*-\n\ | |
336 @deftypefn {Loadable Function} {@var{p} =} csymamd (@var{s})\n\ | |
337 @deftypefnx {Loadable Function} {@var{p} =} csymamd (@var{s}, @var{knobs})\n\ | |
338 @deftypefnx {Loadable Function} {@var{p} =} csymamd (@var{s}, @var{knobs}, @var{cmember})\n\ | |
339 @deftypefnx {Loadable Function} {[@var{p}, @var{stats}] =} csymamd (@dots{})\n\ | |
340 \n\ | |
341 For a symmetric positive definite matrix @var{s}, returns the permutation\n\ | |
342 vector @var{p} such that @code{@var{s}(@var{p},@var{p})} tends to have a\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
343 sparser Cholesky factor than @var{s}. Sometimes @code{csymamd} works well\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
344 for symmetric indefinite matrices too. The matrix @var{s} is assumed to\n\ |
5451 | 345 be symmetric; only the strictly lower triangular part is referenced.\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
346 @var{s} must be square. The ordering is followed by an elimination tree\n\ |
5451 | 347 post-ordering.\n\ |
348 \n\ | |
349 @var{knobs} is an optional one- to three-element input vector, with a\n\ | |
350 default value of @code{[10 1 0]} if present or empty. Entries not\n\ | |
351 present are set to their defaults.\n\ | |
352 \n\ | |
353 @table @code\n\ | |
354 @item @var{knobs}(1)\n\ | |
355 If @var{s} is n-by-n, then rows and columns with more than\n\ | |
356 @code{max(16,@var{knobs}(1)*sqrt(n))} entries are ignored, and ordered\n\ | |
357 last in the output permutation (subject to the cmember constraints).\n\ | |
358 \n\ | |
359 @item @var{knobs}(2)\n\ | |
360 If nonzero, aggressive absorption is performed.\n\ | |
361 \n\ | |
362 @item @var{knobs}(3)\n\ | |
363 If nonzero, statistics and knobs are printed.\n\ | |
364 \n\ | |
365 @end table\n\ | |
366 \n\ | |
367 @var{cmember} is an optional vector of length n. It defines the constraints\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
368 on the ordering. If @code{@var{cmember}(j) = @var{s}}, then row/column j is\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
369 in constraint set @var{c} (@var{c} must be in the range 1 to n). In the\n\ |
5451 | 370 output permutation @var{p}, rows/columns in set 1 appear first, followed\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
371 by all rows/columns in set 2, and so on. @code{@var{cmember} = ones(1,n)}\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
372 if not present or empty. @code{csymamd(@var{s},[],1:n)} returns @code{1:n}.\n\ |
5451 | 373 \n\ |
374 @code{@var{p} = csymamd(@var{s})} is about the same as @code{@var{p} =\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
375 symamd(@var{s})}. @var{knobs} and its default values differ.\n\ |
5451 | 376 \n\ |
377 @code{@var{stats} (4:7)} provide information if CCOLAMD was able to\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
378 continue. The matrix is OK if @code{@var{stats} (4)} is zero, or 1 if\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
379 invalid. @code{@var{stats} (5)} is the rightmost column index that is\n\ |
5451 | 380 unsorted or contains duplicate entries, or zero if no such column exists.\n\ |
381 @code{@var{stats} (6)} is the last seen duplicate or out-of-order row\n\ | |
382 index in the column index given by @code{@var{stats} (5)}, or zero if no\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
383 such row index exists. @code{@var{stats} (7)} is the number of duplicate\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
384 or out-of-order row indices. @code{@var{stats} (8:20)} is always zero in\n\ |
5451 | 385 the current version of CCOLAMD (reserved for future use).\n\ |
386 \n\ | |
387 The authors of the code itself are S. Larimore, T. Davis (Uni of Florida)\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
388 and S. Rajamanickam in collaboration with J. Bilbert and E. Ng. Supported\n\ |
5451 | 389 by the National Science Foundation (DMS-9504974, DMS-9803599, CCR-0203270),\n\ |
390 and a grant from Sandia National Lab. See\n\ | |
391 @url{http://www.cise.ufl.edu/research/sparse} for ccolamd, csymamd, amd,\n\ | |
392 colamd, symamd, and other related orderings.\n\ | |
5642 | 393 @seealso{symamd, ccolamd}\n\ |
394 @end deftypefn") | |
5451 | 395 { |
5771 | 396 octave_value_list retval; |
397 | |
5451 | 398 #if HAVE_CCOLAMD |
5771 | 399 |
5451 | 400 int nargin = args.length (); |
401 int spumoni = 0; | |
402 | |
403 if (nargout < 0 || nargout > 2 || nargin < 0 || nargin > 3) | |
404 usage ("ccolamd: incorrect number of input and/or output arguments"); | |
405 else | |
406 { | |
407 // Get knobs | |
408 OCTAVE_LOCAL_BUFFER (double, knobs, CCOLAMD_KNOBS); | |
409 CCOLAMD_NAME (_set_defaults) (knobs); | |
410 | |
411 // Check for user-passed knobs | |
412 if (nargin > 1) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
413 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
414 NDArray User_knobs = args(1).array_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
415 int nel_User_knobs = User_knobs.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
416 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
417 if (nel_User_knobs > 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
418 knobs [CCOLAMD_DENSE_ROW] = User_knobs (0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
419 if (nel_User_knobs > 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
420 knobs [CCOLAMD_AGGRESSIVE] = User_knobs (1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
421 if (nel_User_knobs > 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
422 spumoni = static_cast<int> (User_knobs (2)); |
5451 | 423 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
424 // print knob settings if spumoni is set |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
425 if (spumoni) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
426 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
427 octave_stdout << "\ncsymamd version " << CCOLAMD_MAIN_VERSION << "." |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
428 << CCOLAMD_SUB_VERSION << ", " << CCOLAMD_DATE << "\n"; |
5451 | 429 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
430 if (knobs [CCOLAMD_DENSE_ROW] >= 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
431 octave_stdout << "knobs(1): " << User_knobs (0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
432 << ", rows/cols with > max(16," |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
433 << knobs [CCOLAMD_DENSE_ROW] << "*sqrt(size(A,2)))" |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
434 << " entries removed\n"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
435 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
436 octave_stdout << "knobs(1): " << User_knobs (0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
437 << ", no dense rows/cols removed\n"; |
5451 | 438 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
439 if (knobs [CCOLAMD_AGGRESSIVE] != 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
440 octave_stdout << "knobs(2): " << User_knobs(1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
441 << ", aggressive absorption: yes"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
442 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
443 octave_stdout << "knobs(2): " << User_knobs(1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
444 << ", aggressive absorption: no"; |
5451 | 445 |
446 | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
447 octave_stdout << "knobs(3): " << User_knobs (2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
448 << ", statistics and knobs printed\n"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
449 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
450 } |
5451 | 451 |
452 octave_idx_type n_row, n_col, nnz; | |
453 octave_idx_type *ridx, *cidx; | |
454 SparseMatrix sm; | |
455 SparseComplexMatrix scm; | |
456 | |
5631 | 457 if (args(0).is_sparse_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
458 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
459 if (args(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
460 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
461 scm = args(0).sparse_complex_matrix_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
462 n_row = scm.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
463 n_col = scm.cols (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
464 nnz = scm.nzmax (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
465 ridx = scm.xridx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
466 cidx = scm.xcidx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
467 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
468 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
469 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
470 sm = args(0).sparse_matrix_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
471 n_row = sm.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
472 n_col = sm.cols (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
473 nnz = sm.nzmax (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
474 ridx = sm.xridx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
475 cidx = sm.xcidx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
476 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
477 } |
5451 | 478 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
479 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
480 if (args(0).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
481 sm = SparseMatrix (real (args(0).complex_matrix_value ())); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
482 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
483 sm = SparseMatrix (args(0).matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
484 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
485 n_row = sm.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
486 n_col = sm.cols (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
487 nnz = sm.nzmax (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
488 ridx = sm.xridx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
489 cidx = sm.xcidx (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
490 } |
5451 | 491 |
492 if (n_row != n_col) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
493 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
494 error ("symamd: matrix must be square"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
495 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
496 } |
5451 | 497 |
498 // Allocate workspace for symamd | |
499 OCTAVE_LOCAL_BUFFER (octave_idx_type, perm, n_col+1); | |
500 OCTAVE_LOCAL_BUFFER (octave_idx_type, stats, CCOLAMD_STATS); | |
501 | |
502 if (nargin > 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
503 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
504 NDArray in_cmember = args(2).array_value(); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
505 octave_idx_type cslen = in_cmember.length(); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
506 OCTAVE_LOCAL_BUFFER (octave_idx_type, cmember, cslen); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
507 for (octave_idx_type i = 0; i < cslen; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
508 // convert cmember from 1-based to 0-based |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
509 cmember[i] = static_cast<octave_idx_type>(in_cmember(i) - 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
510 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
511 if (cslen != n_col) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
512 error ("ccolamd: cmember must be of length equal to #cols of A"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
513 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
514 if (!CSYMAMD_NAME () (n_col, ridx, cidx, perm, knobs, stats, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
515 &calloc, &free, cmember, -1)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
516 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
517 CSYMAMD_NAME (_report) (stats) ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
518 error ("symamd: internal error!") ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
519 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
520 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
521 } |
5451 | 522 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
523 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
524 if (!CSYMAMD_NAME () (n_col, ridx, cidx, perm, knobs, stats, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
525 &calloc, &free, 0, -1)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
526 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
527 CSYMAMD_NAME (_report) (stats) ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
528 error ("symamd: internal error!") ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
529 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
530 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
531 } |
5451 | 532 |
533 // return the permutation vector | |
534 NDArray out_perm (dim_vector (1, n_col)); | |
535 for (octave_idx_type i = 0; i < n_col; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
536 out_perm(i) = perm [i] + 1; |
5451 | 537 |
538 retval (0) = out_perm; | |
539 | |
540 // Return the stats vector | |
541 if (nargout == 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
542 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
543 NDArray out_stats (dim_vector (1, CCOLAMD_STATS)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
544 for (octave_idx_type i = 0 ; i < CCOLAMD_STATS ; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
545 out_stats (i) = stats [i] ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
546 retval(1) = out_stats; |
5451 | 547 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
548 // fix stats (5) and (6), for 1-based information on |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
549 // jumbled matrix. note that this correction doesn't |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
550 // occur if symamd returns FALSE |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
551 out_stats (CCOLAMD_INFO1) ++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
552 out_stats (CCOLAMD_INFO2) ++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
553 } |
5451 | 554 |
555 // print stats if spumoni > 0 | |
556 if (spumoni > 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
557 CSYMAMD_NAME (_report) (stats) ; |
5451 | 558 |
559 // Return the stats vector | |
560 if (nargout == 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
561 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
562 NDArray out_stats (dim_vector (1, CCOLAMD_STATS)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
563 for (octave_idx_type i = 0 ; i < CCOLAMD_STATS ; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
564 out_stats (i) = stats [i] ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
565 retval(1) = out_stats; |
5451 | 566 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
567 // fix stats (5) and (6), for 1-based information on |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
568 // jumbled matrix. note that this correction doesn't |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
569 // occur if symamd returns FALSE |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
570 out_stats (CCOLAMD_INFO1) ++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
571 out_stats (CCOLAMD_INFO2) ++ ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
572 } |
5451 | 573 } |
574 | |
575 #else | |
576 | |
577 error ("csymamd: not available in this version of Octave"); | |
578 | |
579 #endif | |
5771 | 580 |
581 return retval; | |
5451 | 582 } |