| 36 | #include "amd_internal.h" |
| 37 | |
| 38 | GLOBAL Int AMD_valid |
| 39 | ( |
| 40 | /* inputs, not modified on output: */ |
| 41 | Int n_row, /* A is n_row-by-n_col */ |
| 42 | Int n_col, |
| 43 | const Int Ap [ ], /* column pointers of A, of size n_col+1 */ |
| 44 | const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */ |
| 45 | ) |
| 46 | { |
| 47 | Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ; |
| 48 | |
| 49 | if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL) |
| 50 | { |
| 51 | return (AMD_INVALID) ; |
| 52 | } |
| 53 | nz = Ap [n_col] ; |
| 54 | if (Ap [0] != 0 || nz < 0) |
| 55 | { |
| 56 | /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */ |
| 57 | AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ; |
| 58 | return (AMD_INVALID) ; |
| 59 | } |
| 60 | for (j = 0 ; j < n_col ; j++) |
| 61 | { |
| 62 | p1 = Ap [j] ; |
| 63 | p2 = Ap [j+1] ; |
| 64 | AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ; |
| 65 | if (p1 > p2) |
| 66 | { |
| 67 | /* column pointers must be ascending */ |
| 68 | AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ; |
| 69 | return (AMD_INVALID) ; |
| 70 | } |
| 71 | ilast = EMPTY ; |
| 72 | for (p = p1 ; p < p2 ; p++) |
| 73 | { |
| 74 | i = Ai [p] ; |
| 75 | AMD_DEBUG3 (("row: "ID"\n", i)) ; |
| 76 | if (i < 0 || i >= n_row) |
| 77 | { |
| 78 | /* row index out of range */ |
| 79 | AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i)); |
| 80 | return (AMD_INVALID) ; |
| 81 | } |
| 82 | if (i <= ilast) |
| 83 | { |
| 84 | /* row index unsorted, or duplicate entry present */ |
| 85 | AMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i)); |
| 86 | result = AMD_OK_BUT_JUMBLED ; |
| 87 | } |
| 88 | ilast = i ; |
| 89 | } |
| 90 | } |
| 91 | return (result) ; |
| 92 | } |
no outgoing calls
no test coverage detected