SCM

SCM Repository

[matrix] Annotation of /pkg/src/Metis_utils.c
ViewVC logotype

Annotation of /pkg/src/Metis_utils.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 692 - (view) (download) (as text)

1 : bates 351 #include <Rdefines.h>
2 :     #include "metis.h"
3 : bates 10 #include "Metis_utils.h"
4 :    
5 : bates 692
6 :    
7 :     /**
8 :     * Establish a fill-reducing permutation for the sparse symmetric
9 :     * matrix of order n represented by the column pointers Tp and row
10 :     * indices Ti.
11 :     *
12 :     * @param n order of the sparse symmetric matrix
13 :     * @param Tp column pointers (total length n + 1)
14 :     * @param Ti row indices (total length Tp[n])
15 :     * @param Perm array of length n to hold the permutation
16 :     * @param iPerm array of length n to hold the inverse permutation
17 :     *
18 :     */
19 : bates 70 void ssc_metis_order(int n, const int Tp [], const int Ti [],
20 : bates 148 int Perm[], int iPerm[])
21 : bates 10 {
22 : bates 70 int j, num_flag = 0, options_flag = 0;
23 : bates 146 idxtype
24 : bates 149 *perm = Calloc(n, idxtype), /* in case idxtype != int */
25 :     *iperm = Calloc(n, idxtype),
26 : bates 146 *xadj = Calloc(n+1, idxtype),
27 : bates 150 *adj = Calloc(2 * (Tp[n] - n), idxtype);
28 : bates 10
29 : bates 692 /* check row indices for correct range */
30 :     for (j = 0; j < Tp[n]; j++)
31 :     if (Ti[j] < 0 || Ti[j] >= n)
32 :     error(_("row index Ti[%d] = %d is out of range [0,%d]"),
33 :     j, Ti[j], n - 1);
34 : bates 10 /* temporarily use perm to store lengths */
35 : bates 692 AZERO(perm, n);
36 : bates 10 for (j = 0; j < n; j++) {
37 : bates 70 int ip, p2 = Tp[j+1];
38 :     for (ip = Tp[j]; ip < p2; ip++) {
39 :     int i = Ti[ip];
40 : bates 10 if (i != j) {
41 :     perm[i]++;
42 :     perm[j]++;
43 :     }
44 :     }
45 :     }
46 :     xadj[0] = 0;
47 :     for (j = 0; j < n; j++) xadj[j+1] = xadj[j] + perm[j];
48 :     /* temporarily use perm to store pointers */
49 : bates 70 Memcpy(perm, xadj, n);
50 : bates 10 for (j = 0; j < n; j++) {
51 : bates 70 int ip, p2 = Tp[j+1];
52 :     for (ip = Tp[j]; ip < p2; ip++) {
53 :     int i = Ti[ip];
54 : bates 10 if (i != j) {
55 :     adj[perm[i]] = j;
56 :     adj[perm[j]] = i;
57 :     perm[i]++;
58 :     perm[j]++;
59 :     }
60 :     }
61 :     }
62 :     METIS_NodeND(&n, xadj, adj, &num_flag, &options_flag, perm, iperm);
63 : bates 148 for (j = 0; j < n; j++) {
64 : bates 150 Perm[j] = (int) perm[j];
65 :     iPerm[j] = (int) iperm[j];
66 : bates 146 }
67 : bates 148 Free(iperm); Free(perm); Free(xadj); Free(adj);
68 : bates 146 }

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge