ccolamd_l_example.c
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === ccolamd and csymamd example (long integer version) =================== */
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  SuiteSparse_long 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  SuiteSparse_long 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  SuiteSparse_long 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  SuiteSparse_long 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  SuiteSparse_long perm [B_N+1] ; /* note the size is N+1 */
97  SuiteSparse_long stats [CCOLAMD_STATS] ; /* ccolamd/csymamd output stats */
98  SuiteSparse_long row, col, pp, length, ok ;
99 
100  /* ====================================================================== */
101  /* dump the input matrix A */
102  /* ====================================================================== */
103 
104  printf ("ccolamd %d-by-%d input matrix:\n", A_NROW, A_NCOL) ;
105  for (col = 0 ; col < A_NCOL ; col++)
106  {
107  length = p [col+1] - p [col] ;
108  printf ("Column %ld, with %ld entries:\n", col, length) ;
109  for (pp = p [col] ; pp < p [col+1] ; pp++)
110  {
111  row = A [pp] ;
112  printf (" row %ld\n", row) ;
113  }
114  }
115 
116  /* ====================================================================== */
117  /* order the matrix. Note that this destroys A and overwrites p */
118  /* ====================================================================== */
119 
120  ok = ccolamd_l (A_NROW, A_NCOL, ALEN, A, p, (double *) NULL, stats, NULL) ;
121  ccolamd_l_report (stats) ;
122 
123  if (!ok)
124  {
125  printf ("ccolamd error!\n") ;
126  exit (1) ;
127  }
128 
129  /* ====================================================================== */
130  /* print the column ordering */
131  /* ====================================================================== */
132 
133  printf ("ccolamd_l column ordering:\n") ;
134  printf ("1st column: %ld\n", p [0]) ;
135  printf ("2nd column: %ld\n", p [1]) ;
136  printf ("3rd column: %ld\n", p [2]) ;
137  printf ("4th column: %ld\n", p [3]) ;
138 
139  /* ====================================================================== */
140  /* dump the strictly lower triangular part of symmetric input matrix B */
141  /* ====================================================================== */
142 
143  printf ("\n\ncsymamd_l %d-by-%d input matrix:\n", B_N, B_N) ;
144  printf ("Entries in strictly lower triangular part:\n") ;
145  for (col = 0 ; col < B_N ; col++)
146  {
147  length = q [col+1] - q [col] ;
148  printf ("Column %ld, with %ld entries:\n", col, length) ;
149  for (pp = q [col] ; pp < q [col+1] ; pp++)
150  {
151  row = B [pp] ;
152  printf (" row %ld\n", row) ;
153  }
154  }
155 
156  /* ====================================================================== */
157  /* order the matrix B. Note that this does not modify B or q. */
158  /* ====================================================================== */
159 
160  ok = csymamd_l (B_N, B, q, perm, (double *) NULL, stats, &calloc, &free,
161  NULL, -1) ;
162  csymamd_l_report (stats) ;
163 
164  if (!ok)
165  {
166  printf ("csymamd error!\n") ;
167  exit (1) ;
168  }
169 
170  /* ====================================================================== */
171  /* print the symmetric ordering */
172  /* ====================================================================== */
173 
174  printf ("csymamd_l column ordering:\n") ;
175  printf ("1st row/column: %ld\n", perm [0]) ;
176  printf ("2nd row/column: %ld\n", perm [1]) ;
177  printf ("3rd row/column: %ld\n", perm [2]) ;
178  printf ("4th row/column: %ld\n", perm [3]) ;
179  printf ("5th row/column: %ld\n", perm [4]) ;
180 
181  return (0) ;
182 }
#define A_NCOL
int main(void)
SuiteSparse_long ccolamd_l(SuiteSparse_long n_row, SuiteSparse_long n_col, SuiteSparse_long Alen, SuiteSparse_long A[], SuiteSparse_long p[], double knobs[CCOLAMD_KNOBS], SuiteSparse_long stats[CCOLAMD_STATS], SuiteSparse_long cmember[])
void csymamd_l_report(SuiteSparse_long stats[CCOLAMD_STATS])
#define ALEN
SuiteSparse_long csymamd_l(SuiteSparse_long n, SuiteSparse_long A[], SuiteSparse_long p[], SuiteSparse_long perm[], double knobs[CCOLAMD_KNOBS], SuiteSparse_long stats[CCOLAMD_STATS], void *(*allocate)(size_t, size_t), void(*release)(void *), SuiteSparse_long cmember[], SuiteSparse_long stype)
void ccolamd_l_report(SuiteSparse_long stats[CCOLAMD_STATS])
bool stats
#define SuiteSparse_long
m row(1)
idx_t idx_t idx_t idx_t idx_t * perm
#define B_N
EIGEN_DEVICE_FUNC const Scalar & q
#define NULL
Definition: ccolamd.c:609
float * p
#define A_NNZ
m col(1)
#define A_NROW
#define B_NNZ
#define CCOLAMD_STATS
Definition: ccolamd.h:60


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