Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_klu_dump.c
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === KLU_dump ============================================================= */
3 /* ========================================================================== */
4 
5 /* Debug routines for klu. Only used when NDEBUG is not defined at
6  * compile-time.
7  */
8 
9 #include "amesos_klu_internal.h"
10 
11 #ifndef NDEBUG
12 
13 /* ========================================================================== */
14 /* === KLU_valid ============================================================ */
15 /* ========================================================================== */
16 
17 /* Check if a column-form matrix is valid or not. The matrix A is
18  * n-by-n. The row indices of entries in column j are in
19  * Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are:
20  *
21  * n >= 0
22  * nz = Ap [n_col] >= 0 number of entries in the matrix
23  * Ap [0] == 0
24  * Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.
25  * row indices in Ai [Ap [j] ... Ap [j+1]-1]
26  * must be in the range 0 to n_row-1,
27  * and no duplicate entries can exist (duplicates not checked here).
28  *
29  * Not user-callable. Only used when debugging.
30  */
31 
32 Int KLU_valid (Int n, Int Ap [ ], Int Ai [ ], Entry Ax [ ])
33 {
34  Int nz, j, p1, p2, i, p ;
35  PRINTF (("\ncolumn oriented matrix, n = %d\n", n)) ;
36  if (n <= 0)
37  {
38  PRINTF (("n must be >= 0: %d\n", n)) ;
39  return (FALSE) ;
40  }
41  nz = Ap [n] ;
42  if (Ap [0] != 0 || nz < 0)
43  {
44  /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
45  PRINTF (("column 0 pointer bad or nz < 0\n")) ;
46  return (FALSE) ;
47  }
48  for (j = 0 ; j < n ; j++)
49  {
50  p1 = Ap [j] ;
51  p2 = Ap [j+1] ;
52  PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ;
53  if (p1 > p2)
54  {
55  /* column pointers must be ascending */
56  PRINTF (("column %d pointer bad\n", j)) ;
57  return (FALSE) ;
58  }
59  for (p = p1 ; p < p2 ; p++)
60  {
61  i = Ai [p] ;
62  PRINTF (("row: %d", i)) ;
63  if (i < 0 || i >= n)
64  {
65  /* row index out of range */
66  PRINTF (("index out of range, col %d row %d\n", j, i)) ;
67  return (FALSE) ;
68  }
69  if (Ax != (Entry *) NULL)
70  {
71  PRINT_ENTRY (Ax [p]) ;
72  }
73  PRINTF (("\n")) ;
74  }
75  }
76  return (TRUE) ;
77 }
78 
79 
80 /* ========================================================================== */
81 /* === KLU_valid_LU ========================================================= */
82 /* ========================================================================== */
83 
84 /* This function does the same validity tests as KLU_valid but for the
85  * LU factor storage format. The flag flag_test_start_ptr is used to
86  * test if Xip [0] = 0. This is not applicable for U. So when calling this
87  * function for U, the flag should be set to false. Only used when debugging.
88  */
89 
90 Int KLU_valid_LU (Int n, Int flag_test_start_ptr, Int Xip [ ],
91  Int Xlen [ ], Unit LU [ ])
92 {
93  Int *Xi ;
94  Entry *Xx ;
95  Int j, p1, p2, i, p, len ;
96 
97  PRINTF (("\ncolumn oriented matrix, n = %d\n", n)) ;
98  if (n <= 0)
99  {
100  PRINTF (("n must be >= 0: %d\n", n)) ;
101  return (FALSE) ;
102  }
103  if (flag_test_start_ptr && Xip [0] != 0)
104  {
105  /* column pointers must start at Xip [0] = 0*/
106  PRINTF (("column 0 pointer bad\n")) ;
107  return (FALSE) ;
108  }
109 
110  for (j = 0 ; j < n ; j++)
111  {
112  p1 = Xip [j] ;
113  p2 = Xip [j+1] ;
114  PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ;
115  if (p1 > p2)
116  {
117  /* column pointers must be ascending */
118  PRINTF (("column %d pointer bad\n", j)) ;
119  return (FALSE) ;
120  }
121  GET_POINTER (LU, Xip, Xlen, Xi, Xx, j, len) ;
122  for (p = 0 ; p < len ; p++)
123  {
124  i = Xi [p] ;
125  PRINTF (("row: %d", i)) ;
126  if (i < 0 || i >= n)
127  {
128  /* row index out of range */
129  PRINTF (("index out of range, col %d row %d\n", j, i)) ;
130  return (FALSE) ;
131  }
132  if (Xx != (Entry *) NULL)
133  {
134  PRINT_ENTRY (Xx [p]) ;
135  }
136  PRINTF (("\n")) ;
137  }
138  }
139 
140  return (TRUE) ;
141 }
142 #endif
#define GET_POINTER(LU, Xip, Xlen, Xi, Xx, k, xlen)
#define PRINT_ENTRY(a)
#define Int
#define FALSE
double Unit
Int KLU_valid(Int n, Int Ap[], Int Ai[], Entry Ax[])
#define NULL
Int KLU_valid_LU(Int n, Int flag_test_start_ptr, Int Xip[], Int Xlen[], Unit LU[])
#define Entry
#define PRINTF(params)
#define TRUE