comparison liboctave/COLAMD/symamdmex.c @ 5438:49ff3dd744ee

[project @ 2005-09-04 12:25:21 by dbateman]
author dbateman
date Sun, 04 Sep 2005 12:25:21 +0000
parents 57077d0ddc8e
children
comparison
equal deleted inserted replaced
5437:009606303874 5438:49ff3dd744ee
1 /* ========================================================================== */ 1 /* ========================================================================== */
2 /* === symamd mexFunction =================================================== */ 2 /* === symamd mexFunction =================================================== */
3 /* ========================================================================== */ 3 /* ========================================================================== */
4 4
5 /* 5 /* COLAMD Version 2.4.
6
6 Usage: 7 Usage:
7 8
8 P = symamd (A) ; 9 P = symamd (A) ;
9
10 P = symamd (A, knobs) ;
11
12 [ P, stats ] = symamd (A) ;
13
14 [ P, stats ] = symamd (A, knobs) ; 10 [ P, stats ] = symamd (A, knobs) ;
15 11
16 Returns a permutation vector P such that the Cholesky factorization of 12 See symamd.m for a description.
17 A (P,P) tends to be sparser than that of A. This routine provides the same
18 functionality as SYMMMD, but tends to be much faster and tends to return a
19 better permutation vector. Note that the SYMMMD m-file in
20 MATLAB 5.2 also performs a symmetric elimination tree post-ordering. This
21 mexFunction does not do this post-ordering. This mexFunction is a
22 replacement for the p = sparsfun ('symmmd', A) operation.
23
24 A must be square, and is assummed to have a symmetric nonzero pattern.
25 Only the nonzero pattern of the lower triangular portion of A is accessed.
26 This routine constructs a matrix M such that the nonzero pattern of M'M is
27 equal to A (assuming A has symmetric pattern), and then performs a column
28 ordering of M using colamd.
29
30 The knobs and stats vectors are optional:
31
32 knobs (1) rows and columns with more than (knobs(1))*n entries
33 are removed prior to ordering, and placed last in
34 the output ordering. If knobs is not present, then the
35 default of 0.5 is used.
36
37 knobs (2) print level, similar to spparms ('spumoni')
38
39 stats (1) the number of dense (or empty) rows and columms. These
40 are ordered last, in their natural order.
41
42 stats (2) (same as stats (1))
43
44 stats (3) the number of garbage collections performed.
45
46 stats (4) return status:
47
48 0: matrix is a valid MATLAB matrix.
49
50 1: matrix has duplicate entries or unsorted columns.
51 This should not occur in a valid MATLAB matrix,
52 but the ordering proceeded anyway by ignoring the
53 duplicate row indices in each column. See
54 stats (5:7) for more information.
55
56 stats (5) highest numbered column that is unsorted or has
57 duplicate entries (zero if none)
58
59 stats (6) last seen duplicate or unsorted row index
60 (zero if none)
61
62 stats (7) number of duplicate or unsorted row indices
63 13
64 Authors: 14 Authors:
65 15
66 The authors of the code itself are Stefan I. Larimore and Timothy A. 16 The authors of the code itself are Stefan I. Larimore and Timothy A.
67 Davis (davis@cise.ufl.edu), University of Florida. The algorithm was 17 Davis (davis at cise.ufl.edu), University of Florida. The algorithm was
68 developed in collaboration with John Gilbert, Xerox PARC, and Esmond 18 developed in collaboration with John Gilbert, Xerox PARC, and Esmond
69 Ng, Oak Ridge National Laboratory. 19 Ng, Oak Ridge National Laboratory.
70 20
71 Date:
72
73 September 8, 2003. Version 2.3.
74
75 Acknowledgements: 21 Acknowledgements:
76 22
77 This work was supported by the National Science Foundation, under 23 This work was supported by the National Science Foundation, under
78 grants DMS-9504974 and DMS-9803599. 24 grants DMS-9504974 and DMS-9803599.
79 25
80 Notice: 26 Notice:
81 27
82 Copyright (c) 1998-2003 by the University of Florida. 28 Copyright (c) 1998-2005, Timothy A. Davis. All Rights Reserved.
83 All Rights Reserved.
84 29
85 See http://www.cise.ufl.edu/research/sparse/colamd (the colamd.c 30 See http://www.cise.ufl.edu/research/sparse/colamd (the colamd.c
86 file) for the License. 31 file) for the License.
87 32
88 Availability: 33 Availability:
134 int i ; /* loop counter */ 79 int i ; /* loop counter */
135 mxArray *Ainput ; /* input matrix handle */ 80 mxArray *Ainput ; /* input matrix handle */
136 int spumoni ; /* verbosity variable */ 81 int spumoni ; /* verbosity variable */
137 int stats [COLAMD_STATS] ; /* stats for symamd */ 82 int stats [COLAMD_STATS] ; /* stats for symamd */
138 83
84 colamd_printf = mexPrintf ; /* COLAMD printf routine */
85
139 /* === Check inputs ===================================================== */ 86 /* === Check inputs ===================================================== */
140 87
141 if (nrhs < 1 || nrhs > 2 || nlhs < 0 || nlhs > 2) 88 if (nrhs < 1 || nrhs > 2 || nlhs < 0 || nlhs > 2)
142 { 89 {
143 mexErrMsgTxt ( 90 mexErrMsgTxt (
152 /* check for user-passed knobs */ 99 /* check for user-passed knobs */
153 if (nrhs == 2) 100 if (nrhs == 2)
154 { 101 {
155 in_knobs = mxGetPr (prhs [1]) ; 102 in_knobs = mxGetPr (prhs [1]) ;
156 i = mxGetNumberOfElements (prhs [1]) ; 103 i = mxGetNumberOfElements (prhs [1]) ;
157 if (i > 0) knobs [COLAMD_DENSE_ROW] = in_knobs [COLAMD_DENSE_ROW] ; 104 if (i > 0) knobs [COLAMD_DENSE_ROW] = in_knobs [0] ;
158 if (i > 1) spumoni = (int) in_knobs [1] ; 105 if (i > 1) spumoni = (int) (in_knobs [1] != 0) ;
159 } 106 }
160 107
161 /* print knob settings if spumoni > 0 */ 108 /* print knob settings if spumoni is set */
162 if (spumoni > 0) 109 if (spumoni)
163 { 110 {
164 mexPrintf ("symamd: dense row/col fraction: %f\n", 111 mexPrintf ("\nsymamd version %d.%d, %s:\n",
165 knobs [COLAMD_DENSE_ROW]) ; 112 COLAMD_MAIN_VERSION, COLAMD_SUB_VERSION, COLAMD_DATE) ;
113 if (knobs [COLAMD_DENSE_ROW] >= 0)
114 {
115 mexPrintf ("knobs(1): %g, rows/cols with > "
116 "max(16,%g*sqrt(size(A,2))) entries removed\n",
117 in_knobs [0], knobs [COLAMD_DENSE_ROW]) ;
118 }
119 else
120 {
121 mexPrintf ("knobs(1): %g, no dense rows removed\n", in_knobs [0]) ;
122 }
123 mexPrintf ("knobs(2): %g, statistics and knobs printed\n",
124 in_knobs [1]) ;
166 } 125 }
167 126
168 /* === If A is full, convert to a sparse matrix ========================= */ 127 /* === If A is full, convert to a sparse matrix ========================= */
169 128
170 Ainput = (mxArray *) prhs [0] ; 129 Ainput = (mxArray *) prhs [0] ;
216 } 175 }
217 mxFree (perm) ; 176 mxFree (perm) ;
218 177
219 /* === Return the stats vector ========================================== */ 178 /* === Return the stats vector ========================================== */
220 179
221 /* print stats if spumoni > 0 */ 180 /* print stats if spumoni is set */
222 if (spumoni > 0) 181 if (spumoni)
223 { 182 {
224 symamd_report (stats) ; 183 symamd_report (stats) ;
225 } 184 }
226 185
227 if (nlhs == 2) 186 if (nlhs == 2)