ccolamd_example.c
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === ccolamd and csymamd example ========================================== */
3 /* ========================================================================== */
4 
5 /* ----------------------------------------------------------------------------
6  * CCOLAMD Copyright (C), Univ. of Florida. Authors: Timothy A. Davis,
7  * Sivasankaran Rajamanickam, and Stefan Larimore
8  * -------------------------------------------------------------------------- */
9 
10 /*
11  * ccolamd example of use, to order the columns of a 5-by-4 matrix with
12  * 11 nonzero entries in the following nonzero pattern, with default knobs
13  * and no ordering constraints.
14  *
15  * x 0 x 0
16  * x 0 x x
17  * 0 x x 0
18  * 0 0 x x
19  * x x 0 0
20  *
21  * csymamd example of use, to order the rows and columns of a 5-by-5
22  * matrix with 13 nonzero entries in the following nonzero pattern,
23  * with default knobs and no ordering constraints.
24  *
25  * x x 0 0 0
26  * x x x x 0
27  * 0 x x 0 0
28  * 0 x 0 x x
29  * 0 0 0 x x
30  *
31  * (where x denotes a nonzero value).
32  */
33 
34 /* ========================================================================== */
35 
36 #include <stdio.h>
37 #include "ccolamd.h"
38 
39 #define A_NNZ 11
40 #define A_NROW 5
41 #define A_NCOL 4
42 #define ALEN 150 /* size max (2.2*nnz+17*ncol+7*nrow+6, 23*ncol+7*nrow+6) */
43 
44 #define B_NNZ 4
45 #define B_N 5
46 
47 int main (void)
48 {
49 
50  /* ====================================================================== */
51  /* input matrix A definition */
52  /* ====================================================================== */
53 
54  int A [ALEN] = {
55 
56  0, 1, 4, /* row indices of nonzeros in column 0 */
57  2, 4, /* row indices of nonzeros in column 1 */
58  0, 1, 2, 3, /* row indices of nonzeros in column 2 */
59  1, 3} ; /* row indices of nonzeros in column 3 */
60 
61  int p [ ] = {
62 
63  0, /* column 0 is in A [0..2] */
64  3, /* column 1 is in A [3..4] */
65  5, /* column 2 is in A [5..8] */
66  9, /* column 3 is in A [9..10] */
67  A_NNZ} ; /* number of nonzeros in A */
68 
69  /* ====================================================================== */
70  /* input matrix B definition */
71  /* ====================================================================== */
72 
73  int B [ ] = { /* Note: only strictly lower triangular part */
74  /* is included, since symamd ignores the */
75  /* diagonal and upper triangular part of B. */
76 
77  1, /* row indices of nonzeros in column 0 */
78  2, 3, /* row indices of nonzeros in column 1 */
79  /* row indices of nonzeros in column 2 (none) */
80  4 /* row indices of nonzeros in column 3 */
81  } ; /* row indices of nonzeros in column 4 (none) */
82 
83  int q [ ] = {
84 
85  0, /* column 0 is in B [0] */
86  1, /* column 1 is in B [1..2] */
87  3, /* column 2 is empty */
88  3, /* column 3 is in B [3] */
89  4, /* column 4 is empty */
90  B_NNZ} ; /* number of nonzeros in strictly lower B */
91 
92  /* ====================================================================== */
93  /* other variable definitions */
94  /* ====================================================================== */
95 
96  int perm [B_N+1] ; /* note the size is N+1 */
97  int stats [CCOLAMD_STATS] ; /* for ccolamd and csymamd output statistics */
98 
99  int row, col, pp, length, ok ;
100 
101  /* ====================================================================== */
102  /* dump the input matrix A */
103  /* ====================================================================== */
104 
105  printf ("ccolamd %d-by-%d input matrix:\n", A_NROW, A_NCOL) ;
106  for (col = 0 ; col < A_NCOL ; col++)
107  {
108  length = p [col+1] - p [col] ;
109  printf ("Column %d, with %d entries:\n", col, length) ;
110  for (pp = p [col] ; pp < p [col+1] ; pp++)
111  {
112  row = A [pp] ;
113  printf (" row %d\n", row) ;
114  }
115  }
116 
117  /* ====================================================================== */
118  /* order the matrix. Note that this destroys A and overwrites p */
119  /* ====================================================================== */
120 
121  ok = ccolamd (A_NROW, A_NCOL, ALEN, A, p, (double *) NULL, stats, NULL) ;
122  ccolamd_report (stats) ;
123 
124  if (!ok)
125  {
126  printf ("ccolamd error!\n") ;
127  exit (1) ;
128  }
129 
130  /* ====================================================================== */
131  /* print the column ordering */
132  /* ====================================================================== */
133 
134  printf ("ccolamd column ordering:\n") ;
135  printf ("1st column: %d\n", p [0]) ;
136  printf ("2nd column: %d\n", p [1]) ;
137  printf ("3rd column: %d\n", p [2]) ;
138  printf ("4th column: %d\n", p [3]) ;
139 
140  /* ====================================================================== */
141  /* dump the strictly lower triangular part of symmetric input matrix B */
142  /* ====================================================================== */
143 
144  printf ("\n\ncsymamd %d-by-%d input matrix:\n", B_N, B_N) ;
145  printf ("Entries in strictly lower triangular part:\n") ;
146  for (col = 0 ; col < B_N ; col++)
147  {
148  length = q [col+1] - q [col] ;
149  printf ("Column %d, with %d entries:\n", col, length) ;
150  for (pp = q [col] ; pp < q [col+1] ; pp++)
151  {
152  row = B [pp] ;
153  printf (" row %d\n", row) ;
154  }
155  }
156 
157  /* ====================================================================== */
158  /* order the matrix B. Note that this does not modify B or q. */
159  /* ====================================================================== */
160 
161  ok = csymamd (B_N, B, q, perm, (double *) NULL, stats, &calloc, &free,
162  NULL, -1) ;
163  csymamd_report (stats) ;
164 
165  if (!ok)
166  {
167  printf ("csymamd error!\n") ;
168  exit (1) ;
169  }
170 
171  /* ====================================================================== */
172  /* print the symmetric ordering */
173  /* ====================================================================== */
174 
175  printf ("csymamd column ordering:\n") ;
176  printf ("1st row/column: %d\n", perm [0]) ;
177  printf ("2nd row/column: %d\n", perm [1]) ;
178  printf ("3rd row/column: %d\n", perm [2]) ;
179  printf ("4th row/column: %d\n", perm [3]) ;
180  printf ("5th row/column: %d\n", perm [4]) ;
181 
182  return (0) ;
183 }
int csymamd(int n, int A[], int p[], int perm[], double knobs[CCOLAMD_KNOBS], int stats[CCOLAMD_STATS], void *(*allocate)(size_t, size_t), void(*release)(void *), int cmember[], int stype)
#define B_N
bool stats
#define B_NNZ
void ccolamd_report(int stats[CCOLAMD_STATS])
m row(1)
idx_t idx_t idx_t idx_t idx_t * perm
EIGEN_DEVICE_FUNC const Scalar & q
#define NULL
Definition: ccolamd.c:609
#define A_NCOL
#define A_NNZ
#define A_NROW
#define ALEN
int ccolamd(int n_row, int n_col, int Alen, int A[], int p[], double knobs[CCOLAMD_KNOBS], int stats[CCOLAMD_STATS], int cmember[])
float * p
int main(void)
m col(1)
#define CCOLAMD_STATS
Definition: ccolamd.h:60
void csymamd_report(int stats[CCOLAMD_STATS])


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:46