Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_camd_valid.c
Go to the documentation of this file.
1 /* ========================================================================= */
2 /* === CAMD_valid ========================================================== */
3 /* ========================================================================= */
4 
5 /* ------------------------------------------------------------------------- */
6 /* CAMD, Copyright (c) Timothy A. Davis, Yanqing Chen, */
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/camd */
10 /* ------------------------------------------------------------------------- */
11 
12 /* Check if a column-form matrix is valid or not. The matrix A is
13  * n_row-by-n_col. The row indices of entries in column j are in
14  * Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are:
15  *
16  * n_row >= 0
17  * n_col >= 0
18  * nz = Ap [n_col] >= 0 number of entries in the matrix
19  * Ap [0] == 0
20  * Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.
21  * Ai [0 ... nz-1] must be in the range 0 to n_row-1.
22  *
23  * If any of the above conditions hold, CAMD_INVALID is returned. If the
24  * following condition holds, CAMD_OK_BUT_JUMBLED is returned (a warning,
25  * not an error):
26  *
27  * row indices in Ai [Ap [j] ... Ap [j+1]-1] are not sorted in ascending
28  * order, and/or duplicate entries exist.
29  *
30  * Otherwise, CAMD_OK is returned.
31  */
32 
33 #include "amesos_camd_internal.h"
34 
36 (
37  /* inputs, not modified on output: */
38  Int n_row, /* A is n_row-by-n_col */
39  Int n_col,
40  const Int Ap [ ], /* column pointers of A, of size n_col+1 */
41  const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */
42 )
43 {
44  Int nz, j, p1, p2, ilast, i, p, result = CAMD_OK ;
45  if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
46  {
47  return (CAMD_INVALID) ;
48  }
49  nz = Ap [n_col] ;
50  if (Ap [0] != 0 || nz < 0)
51  {
52  /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
53  CAMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
54  return (CAMD_INVALID) ;
55  }
56  for (j = 0 ; j < n_col ; j++)
57  {
58  p1 = Ap [j] ;
59  p2 = Ap [j+1] ;
60  CAMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
61  if (p1 > p2)
62  {
63  /* column pointers must be ascending */
64  CAMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
65  return (CAMD_INVALID) ;
66  }
67  ilast = EMPTY ;
68  for (p = p1 ; p < p2 ; p++)
69  {
70  i = Ai [p] ;
71  CAMD_DEBUG3 (("row: "ID"\n", i)) ;
72  if (i < 0 || i >= n_row)
73  {
74  /* row index out of range */
75  CAMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
76  return (CAMD_INVALID) ;
77  }
78  if (i <= ilast)
79  {
80  /* row index unsorted, or duplicate entry present */
81  CAMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i));
82  result = CAMD_OK_BUT_JUMBLED ;
83  }
84  ilast = i ;
85  }
86  }
87  return (result) ;
88 }
89 
90 
91 GLOBAL Int CAMD_cvalid /* return TRUE if the Constraint set is valid,
92  * FALSE otherwise */
93 (
94  /* inputs, not modified on output: */
95  Int n, /* the length of constraint set */
96  const Int C [ ] /* constraint set */
97 )
98 {
99  Int i ;
100  if (C != NULL)
101  {
102  for (i = 0 ; i < n ; i++)
103  {
104  if (C [i] < 0 || C [i] > n - 1)
105  {
106  CAMD_DEBUG0 (("C["ID"] = "ID" invalid\n", i, C [i])) ;
107  return (FALSE) ;
108  }
109  }
110  }
111  return (TRUE) ;
112 }
113 
#define CAMD_DEBUG0(params)
#define EMPTY
#define GLOBAL
#define Int
#define FALSE
#define CAMD_DEBUG3(params)
#define NULL
#define ID
#define CAMD_DEBUG1(params)
GLOBAL Int CAMD_cvalid(Int n, const Int C[])
#define CAMD_INVALID
Definition: amesos_camd.h:384
#define CAMD_OK
Definition: amesos_camd.h:382
GLOBAL Int CAMD_valid(Int n_row, Int n_col, const Int Ap[], const Int Ai[])
#define CAMD_OK_BUT_JUMBLED
Definition: amesos_camd.h:385
int n
#define TRUE
#define CAMD_DEBUG2(params)