Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
klu2_dump.hpp
1 /* ========================================================================== */
2 /* === KLU_dump ============================================================= */
3 /* ========================================================================== */
4 // @HEADER
5 // *****************************************************************************
6 // KLU2: A Direct Linear Solver package
7 //
8 // Copyright 2011 NTESS and the KLU2 contributors.
9 // SPDX-License-Identifier: LGPL-2.1-or-later
10 // *****************************************************************************
11 // @HEADER
12 
13 /* Debug routines for klu. Only used when NDEBUGKLU2 is not defined at
14  * compile-time.
15  */
16 
17 #ifndef KLU2_DUMP_HPP
18 #define KLU2_DUMP_HPP
19 
20 #include "klu2_internal.h"
21 
22 #ifndef NDEBUGKLU2
23 
24 /* ========================================================================== */
25 /* === KLU_valid ============================================================ */
26 /* ========================================================================== */
27 
28 /* Check if a column-form matrix is valid or not. The matrix A is
29  * n-by-n. The row indices of entries in column j are in
30  * Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are:
31  *
32  * n >= 0
33  * nz = Ap [n_col] >= 0 number of entries in the matrix
34  * Ap [0] == 0
35  * Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.
36  * row indices in Ai [Ap [j] ... Ap [j+1]-1]
37  * must be in the range 0 to n_row-1,
38  * and no duplicate entries can exist (duplicates not checked here).
39  *
40  * Not user-callable. Only used when debugging.
41  */
42 
43 template <typename Entry, typename Int>
44 Int KLU_valid (Int n, Int Ap [ ], Int Ai [ ], Entry Ax [ ])
45 {
46  Int nz, j, p1, p2, i, p ;
47  PRINTF (("\ncolumn oriented matrix, n = %d\n", n)) ;
48  if (n <= 0)
49  {
50  PRINTF (("n must be >= 0: %d\n", n)) ;
51  return (FALSE) ;
52  }
53  nz = Ap [n] ;
54  if (Ap [0] != 0 || nz < 0)
55  {
56  /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
57  PRINTF (("column 0 pointer bad or nz < 0\n")) ;
58  return (FALSE) ;
59  }
60  for (j = 0 ; j < n ; j++)
61  {
62  p1 = Ap [j] ;
63  p2 = Ap [j+1] ;
64  PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ;
65  if (p1 > p2)
66  {
67  /* column pointers must be ascending */
68  PRINTF (("column %d pointer bad\n", j)) ;
69  return (FALSE) ;
70  }
71  for (p = p1 ; p < p2 ; p++)
72  {
73  i = Ai [p] ;
74  PRINTF (("row: %d", i)) ;
75  if (i < 0 || i >= n)
76  {
77  /* row index out of range */
78  PRINTF (("index out of range, col %d row %d\n", j, i)) ;
79  return (FALSE) ;
80  }
81  if (Ax != (Entry *) NULL)
82  {
83  PRINT_ENTRY (Ax [p]) ;
84  }
85  PRINTF (("\n")) ;
86  }
87  }
88  return (TRUE) ;
89 }
90 
91 
92 /* ========================================================================== */
93 /* === KLU_valid_LU ========================================================= */
94 /* ========================================================================== */
95 
96 /* This function does the same validity tests as KLU_valid but for the
97  * LU factor storage format. The flag flag_test_start_ptr is used to
98  * test if Xip [0] = 0. This is not applicable for U. So when calling this
99  * function for U, the flag should be set to false. Only used when debugging.
100  */
101 
102 template <typename Entry, typename Int>
103 Int KLU_valid_LU (Int n, Int flag_test_start_ptr, Int Xip [ ],
104  Int Xlen [ ], Unit LU [ ])
105 {
106  Int *Xi ;
107  Entry *Xx ;
108  Int j, p1, p2, i, p, len ;
109 
110  PRINTF (("\ncolumn oriented matrix, n = %d\n", n)) ;
111  if (n <= 0)
112  {
113  PRINTF (("n must be >= 0: %d\n", n)) ;
114  return (FALSE) ;
115  }
116  if (flag_test_start_ptr && Xip [0] != 0)
117  {
118  /* column pointers must start at Xip [0] = 0*/
119  PRINTF (("column 0 pointer bad\n")) ;
120  return (FALSE) ;
121  }
122 
123  for (j = 0 ; j < n ; j++)
124  {
125  p1 = Xip [j] ;
126  p2 = Xip [j+1] ;
127  PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ;
128  if (p1 > p2)
129  {
130  /* column pointers must be ascending */
131  PRINTF (("column %d pointer bad\n", j)) ;
132  return (FALSE) ;
133  }
134  GET_POINTER (LU, Xip, Xlen, Xi, Xx, j, len) ;
135  for (p = 0 ; p < len ; p++)
136  {
137  i = Xi [p] ;
138  PRINTF (("row: %d", i)) ;
139  if (i < 0 || i >= n)
140  {
141  /* row index out of range */
142  PRINTF (("index out of range, col %d row %d\n", j, i)) ;
143  return (FALSE) ;
144  }
145  if (Xx != (Entry *) NULL)
146  {
147  PRINT_ENTRY (Xx [p]) ;
148  }
149  PRINTF (("\n")) ;
150  }
151  }
152 
153  return (TRUE) ;
154 }
155 #endif
156 
157 #endif
int Ap[]
Column offsets.
Definition: klu2_simple.cpp:52
int Ai[]
Row values.
Definition: klu2_simple.cpp:54