~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to CHOLMOD/MATLAB/septree.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2006-12-22 10:16:15 UTC
  • Revision ID: james.westby@ubuntu.com-20061222101615-2ohaj8902oix2rnk
Tags: upstream-2.3.1
ImportĀ upstreamĀ versionĀ 2.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ========================================================================== */
 
2
/* === CHOLMOD/MATLAB/septree mexFunction =================================== */
 
3
/* ========================================================================== */
 
4
 
 
5
/* -----------------------------------------------------------------------------
 
6
 * CHOLMOD/MATLAB Module.  Version 1.3.  Copyright (C) 2005-2006,
 
7
 * Timothy A. Davis
 
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
 * -------------------------------------------------------------------------- */
 
15
 
 
16
/* Prune a separator tree.
 
17
 *
 
18
 * Usage:
 
19
 *
 
20
 *      [cp_new, cmember_new] = septree (cp, cmember, nd_oksep, nd_small) ;
 
21
 *
 
22
 * cp and cmember are outputs of the nesdis mexFunction.
 
23
 *
 
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.
 
29
 *
 
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.
 
34
 *
 
35
 * Requires the CHOLMOD Partition Module.
 
36
 */
 
37
 
 
38
#include "cholmod_matlab.h"
 
39
 
 
40
void mexFunction
 
41
(
 
42
    int nargout,
 
43
    mxArray *pargout [ ],
 
44
    int nargin,
 
45
    const mxArray *pargin [ ]
 
46
)
 
47
{
 
48
#ifndef NPARTITION
 
49
    double *p ;
 
50
    int *Cmember, *CParent ;
 
51
    cholmod_common Common, *cm ;
 
52
    double nd_oksep ;
 
53
    int nd_small, nc, n, c, j, nc_new ;
 
54
 
 
55
    /* ---------------------------------------------------------------------- */
 
56
    /* start CHOLMOD and set defaults */
 
57
    /* ---------------------------------------------------------------------- */
 
58
 
 
59
    cm = &Common ;
 
60
    cholmod_start (cm) ;
 
61
    sputil_config (SPUMONI, cm) ;
 
62
 
 
63
    /* ---------------------------------------------------------------------- */
 
64
    /* get inputs */
 
65
    /* ---------------------------------------------------------------------- */
 
66
 
 
67
    if (nargout > 2 || nargin != 4)
 
68
    {
 
69
        mexErrMsgTxt ("Usage: [cp_new, cmember_new] = "
 
70
                "septree (cp, cmember, nd_oksep, nd_small)") ;
 
71
    }
 
72
 
 
73
    nc = mxGetNumberOfElements (pargin [0]) ;
 
74
    n  = mxGetNumberOfElements (pargin [1]) ;
 
75
    nd_oksep = mxGetScalar (pargin [2]) ;
 
76
    nd_small = mxGetScalar (pargin [3]) ;
 
77
 
 
78
    if (n < nc)
 
79
    {
 
80
        mexErrMsgTxt ("invalid inputs") ;
 
81
    }
 
82
 
 
83
    CParent = cholmod_malloc (nc, sizeof (int), cm) ;
 
84
    Cmember = cholmod_malloc (n, sizeof (int), cm) ;
 
85
 
 
86
    p = mxGetPr (pargin [0]) ;
 
87
    for (c = 0 ; c < nc ; c++)
 
88
    {
 
89
        CParent [c] = p [c] - 1 ;
 
90
        if (CParent [c] < EMPTY || CParent [c] > nc)
 
91
        {
 
92
            mexErrMsgTxt ("cp invalid") ;
 
93
        }
 
94
    }
 
95
 
 
96
    p = mxGetPr (pargin [1]) ;
 
97
    for (j = 0 ; j < n ; j++)
 
98
    {
 
99
        Cmember [j] = p [j] - 1 ;
 
100
        if (Cmember [j] < 0 || Cmember [j] > nc)
 
101
        {
 
102
            mexErrMsgTxt ("cmember invalid") ;
 
103
        }
 
104
    }
 
105
 
 
106
    /* ---------------------------------------------------------------------- */
 
107
    /* collapse the tree */
 
108
    /* ---------------------------------------------------------------------- */
 
109
 
 
110
    nc_new = cholmod_collapse_septree (n, nc, nd_oksep, nd_small, CParent,
 
111
        Cmember, cm) ; 
 
112
    if (nc_new < 0)
 
113
    {
 
114
        mexErrMsgTxt ("septree failed") ;
 
115
        return ;
 
116
    }
 
117
 
 
118
    /* ---------------------------------------------------------------------- */
 
119
    /* return CParent and Cmember */
 
120
    /* ---------------------------------------------------------------------- */
 
121
 
 
122
    pargout [0] = sputil_put_int (CParent, nc_new, 1) ;
 
123
    if (nargout > 1)
 
124
    {
 
125
        pargout [1] = sputil_put_int (Cmember, n, 1) ;
 
126
    }
 
127
 
 
128
    /* ---------------------------------------------------------------------- */
 
129
    /* free workspace */
 
130
    /* ---------------------------------------------------------------------- */
 
131
 
 
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) ;
 
136
    /*
 
137
    if (cm->malloc_count != 0) mexErrMsgTxt ("!") ;
 
138
    */
 
139
#else
 
140
    mexErrMsgTxt ("CHOLMOD Partition Module not installed\n") ;
 
141
#endif
 
142
}