Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_amd_l_valid.c
Go to the documentation of this file.
1 /* ========================================================================= */
2 /* === AMD_valid =========================================================== */
3 /* ========================================================================= */
4 
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 /* ------------------------------------------------------------------------- */
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, AMD_INVALID is returned. If the
24  * following condition holds, AMD_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, AMD_OK is returned.
31  *
32  * In v1.2 and earlier, this function returned TRUE if the matrix was valid
33  * (now returns AMD_OK), or FALSE otherwise (now returns AMD_INVALID or
34  * AMD_OK_BUT_JUMBLED).
35  */
36 
37 /* This file should make the long int version of AMD */
38 #define DLONG 1
39 
40 #include "amesos_amd_internal.h"
41 
43 (
44  /* inputs, not modified on output: */
45  Int n_row, /* A is n_row-by-n_col */
46  Int n_col,
47  const Int Ap [ ], /* column pointers of A, of size n_col+1 */
48  const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */
49 )
50 {
51  Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ;
52 
53  if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
54  {
55  return (AMD_INVALID) ;
56  }
57  nz = Ap [n_col] ;
58  if (Ap [0] != 0 || nz < 0)
59  {
60  /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
61  AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
62  return (AMD_INVALID) ;
63  }
64  for (j = 0 ; j < n_col ; j++)
65  {
66  p1 = Ap [j] ;
67  p2 = Ap [j+1] ;
68  AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
69  if (p1 > p2)
70  {
71  /* column pointers must be ascending */
72  AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
73  return (AMD_INVALID) ;
74  }
75  ilast = EMPTY ;
76  for (p = p1 ; p < p2 ; p++)
77  {
78  i = Ai [p] ;
79  AMD_DEBUG3 (("row: "ID"\n", i)) ;
80  if (i < 0 || i >= n_row)
81  {
82  /* row index out of range */
83  AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
84  return (AMD_INVALID) ;
85  }
86  if (i <= ilast)
87  {
88  /* row index unsorted, or duplicate entry present */
89  AMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i));
90  result = AMD_OK_BUT_JUMBLED ;
91  }
92  ilast = i ;
93  }
94  }
95  return (result) ;
96 }
#define AMD_DEBUG0(params)
#define EMPTY
#define GLOBAL
#define AMD_DEBUG1(params)
#define AMD_DEBUG3(params)
#define Int
#define NULL
#define ID
#define AMD_INVALID
Definition: amesos_amd.h:373
#define AMD_DEBUG2(params)
#define AMD_OK
Definition: amesos_amd.h:371
GLOBAL Int AMD_valid(Int n_row, Int n_col, const Int Ap[], const Int Ai[])
#define AMD_OK_BUT_JUMBLED
Definition: amesos_amd.h:374