1
/* ========================================================================== */
2
/* === CHOLMOD/MATLAB/septree mexFunction =================================== */
3
/* ========================================================================== */
5
/* -----------------------------------------------------------------------------
6
* CHOLMOD/MATLAB Module. Version 1.3. Copyright (C) 2005-2006,
8
* The CHOLMOD/MATLAB Module is licensed under Version 2.0 of the GNU
9
* General Public License. See gpl.txt for a text of the license.
10
* CHOLMOD is also available under other licenses; contact authors for details.
11
* http://www.cise.ufl.edu/research/sparse
12
* MATLAB(tm) is a Trademark of The MathWorks, Inc.
13
* METIS (Copyright 1998, G. Karypis) is not distributed with CHOLMOD.
14
* -------------------------------------------------------------------------- */
16
/* Prune a separator tree.
20
* [cp_new, cmember_new] = septree (cp, cmember, nd_oksep, nd_small) ;
22
* cp and cmember are outputs of the nesdis mexFunction.
24
* cmember(i)=c means that node i is in component
25
* c, where c is in the range of 1 to the number of components. length(cp) is
26
* the number of components found. cp is the separator tree; cp(c) is the
27
* parent of component c, or 0 if c is a root. There can be anywhere from
28
* 1 to n components, where n is the number of rows of A, A*A', or A'*A.
30
* On output, cp_new and cmember_new are the new tree and graph-to-tree mapping.
31
* A subtree is collapsed into a single node if the number of nodes in the
32
* separator is > nd_oksep times the total size of the subtree, or if the
33
* subtree has fewer than nd_small nodes.
35
* Requires the CHOLMOD Partition Module.
38
#include "cholmod_matlab.h"
45
const mxArray *pargin [ ]
50
int *Cmember, *CParent ;
51
cholmod_common Common, *cm ;
53
int nd_small, nc, n, c, j, nc_new ;
55
/* ---------------------------------------------------------------------- */
56
/* start CHOLMOD and set defaults */
57
/* ---------------------------------------------------------------------- */
61
sputil_config (SPUMONI, cm) ;
63
/* ---------------------------------------------------------------------- */
65
/* ---------------------------------------------------------------------- */
67
if (nargout > 2 || nargin != 4)
69
mexErrMsgTxt ("Usage: [cp_new, cmember_new] = "
70
"septree (cp, cmember, nd_oksep, nd_small)") ;
73
nc = mxGetNumberOfElements (pargin [0]) ;
74
n = mxGetNumberOfElements (pargin [1]) ;
75
nd_oksep = mxGetScalar (pargin [2]) ;
76
nd_small = mxGetScalar (pargin [3]) ;
80
mexErrMsgTxt ("invalid inputs") ;
83
CParent = cholmod_malloc (nc, sizeof (int), cm) ;
84
Cmember = cholmod_malloc (n, sizeof (int), cm) ;
86
p = mxGetPr (pargin [0]) ;
87
for (c = 0 ; c < nc ; c++)
89
CParent [c] = p [c] - 1 ;
90
if (CParent [c] < EMPTY || CParent [c] > nc)
92
mexErrMsgTxt ("cp invalid") ;
96
p = mxGetPr (pargin [1]) ;
97
for (j = 0 ; j < n ; j++)
99
Cmember [j] = p [j] - 1 ;
100
if (Cmember [j] < 0 || Cmember [j] > nc)
102
mexErrMsgTxt ("cmember invalid") ;
106
/* ---------------------------------------------------------------------- */
107
/* collapse the tree */
108
/* ---------------------------------------------------------------------- */
110
nc_new = cholmod_collapse_septree (n, nc, nd_oksep, nd_small, CParent,
114
mexErrMsgTxt ("septree failed") ;
118
/* ---------------------------------------------------------------------- */
119
/* return CParent and Cmember */
120
/* ---------------------------------------------------------------------- */
122
pargout [0] = sputil_put_int (CParent, nc_new, 1) ;
125
pargout [1] = sputil_put_int (Cmember, n, 1) ;
128
/* ---------------------------------------------------------------------- */
130
/* ---------------------------------------------------------------------- */
132
cholmod_free (nc, sizeof (int), CParent, cm) ;
133
cholmod_free (n, sizeof (int), Cmember, cm) ;
134
cholmod_finish (cm) ;
135
cholmod_print_common (" ", cm) ;
137
if (cm->malloc_count != 0) mexErrMsgTxt ("!") ;
140
mexErrMsgTxt ("CHOLMOD Partition Module not installed\n") ;