1 /* ========================================================================= */
2 /* === AMD_aat ============================================================= */
3 /* ========================================================================= */
5 /* ------------------------------------------------------------------------- */
6 /* AMD, Copyright (c) Timothy A. Davis, */
7 /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
8 /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
9 /* web: http://www.cise.ufl.edu/research/sparse/amd */
10 /* ------------------------------------------------------------------------- */
12 /* AMD_aat: compute the symmetry of the pattern of A, and count the number of
13 * nonzeros each column of A+A' (excluding the diagonal). Assumes the input
14 * matrix has no errors, with sorted columns and no duplicates
15 * (AMD_valid (n, n, Ap, Ai) must be AMD_OK, but this condition is not
19 #include "amd_internal.h"
21 GLOBAL size_t AMD_aat /* returns nz in A+A' */
26 Int Len [ ], /* Len [j]: length of column j of A+A', excl diagonal*/
27 Int Tp [ ], /* workspace of size n */
31 Int p1, p2, p, i, j, pj, pj2, k, nzdiag, nzboth, nz ;
36 AMD_debug_init ("AMD AAT") ;
37 for (k = 0 ; k < n ; k++) Tp [k] = EMPTY ;
38 ASSERT (AMD_valid (n, n, Ap, Ai) == AMD_OK) ;
41 if (Info != (double *) NULL)
43 /* clear the Info array, if it exists */
44 for (i = 0 ; i < AMD_INFO ; i++)
48 Info [AMD_STATUS] = AMD_OK ;
51 for (k = 0 ; k < n ; k++)
60 for (k = 0 ; k < n ; k++)
64 AMD_DEBUG2 (("\nAAT Column: "ID" p1: "ID" p2: "ID"\n", k, p1, p2)) ;
67 for (p = p1 ; p < p2 ; )
69 /* scan the upper triangular part of A */
73 /* entry A (j,k) is in the strictly upper triangular part,
74 * add both A (j,k) and A (k,j) to the matrix A+A' */
77 AMD_DEBUG3 ((" upper ("ID","ID") ("ID","ID")\n", j,k, k,j));
82 /* skip the diagonal */
89 /* first entry below the diagonal */
92 /* scan lower triangular part of A, in column j until reaching
93 * row k. Start where last scan left off. */
94 ASSERT (Tp [j] != EMPTY) ;
95 ASSERT (Ap [j] <= Tp [j] && Tp [j] <= Ap [j+1]) ;
97 for (pj = Tp [j] ; pj < pj2 ; )
102 /* A (i,j) is only in the lower part, not in upper.
103 * add both A (i,j) and A (j,i) to the matrix A+A' */
106 AMD_DEBUG3 ((" lower ("ID","ID") ("ID","ID")\n",
112 /* entry A (k,j) in lower part and A (j,k) in upper */
119 /* consider this entry later, when k advances to i */
125 /* Tp [k] points to the entry just below the diagonal in column k */
129 /* clean up, for remaining mismatched entries */
130 for (j = 0 ; j < n ; j++)
132 for (pj = Tp [j] ; pj < Ap [j+1] ; pj++)
135 /* A (i,j) is only in the lower part, not in upper.
136 * add both A (i,j) and A (j,i) to the matrix A+A' */
139 AMD_DEBUG3 ((" lower cleanup ("ID","ID") ("ID","ID")\n",
144 /* --------------------------------------------------------------------- */
145 /* compute the symmetry of the nonzero pattern of A */
146 /* --------------------------------------------------------------------- */
148 /* Given a matrix A, the symmetry of A is:
149 * B = tril (spones (A), -1) + triu (spones (A), 1) ;
150 * sym = nnz (B & B') / nnz (B) ;
151 * or 1 if nnz (B) is zero.
160 sym = (2 * (double) nzboth) / ((double) (nz - nzdiag)) ;
164 for (k = 0 ; k < n ; k++)
169 AMD_DEBUG1 (("AMD nz in A+A', excluding diagonal (nzaat) = %g\n",
171 AMD_DEBUG1 ((" nzboth: "ID" nz: "ID" nzdiag: "ID" symmetry: %g\n",
172 nzboth, nz, nzdiag, sym)) ;
174 if (Info != (double *) NULL)
176 Info [AMD_STATUS] = AMD_OK ;
179 Info [AMD_SYMMETRY] = sym ; /* symmetry of pattern of A */
180 Info [AMD_NZDIAG] = nzdiag ; /* nonzeros on diagonal of A */
181 Info [AMD_NZ_A_PLUS_AT] = nzaat ; /* nonzeros in A+A' */