Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/umfpack/src/amd/amd_valid.c
3203 views
1
/* ========================================================================= */
2
/* === AMD_valid =========================================================== */
3
/* ========================================================================= */
4
5
/* ------------------------------------------------------------------------- */
6
/* AMD Version 1.1 (Jan. 21, 2004), Copyright (c) 2004 by Timothy A. Davis, */
7
/* Patrick R. Amestoy, and Iain S. Duff. See ../README for License. */
8
/* email: [email protected] 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
* row indices in Ai [Ap [j] ... Ap [j+1]-1] must be sorted in ascending
22
* order, must be in the range 0 to n_row-1, and no duplicate entries
23
* can exist.
24
*
25
* Not user-callable.
26
*/
27
28
#include "amd_internal.h"
29
30
GLOBAL Int AMD_valid
31
(
32
/* inputs, not modified on output: */
33
Int n_row, /* A is n_row-by-n_col */
34
Int n_col,
35
const Int Ap [ ], /* column pointers of A, of size n_col+1 */
36
const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */
37
)
38
{
39
Int nz, j, p1, p2, ilast, i, p ;
40
if (n_row < 0 || n_col < 0)
41
{
42
AMD_DEBUG0 (("n must be >= 0: "ID" "ID"\n", n_row, n_col)) ;
43
return (FALSE) ;
44
}
45
nz = Ap [n_col] ;
46
if (Ap [0] != 0 || nz < 0)
47
{
48
/* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
49
AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
50
return (FALSE) ;
51
}
52
for (j = 0 ; j < n_col ; j++)
53
{
54
p1 = Ap [j] ;
55
p2 = Ap [j+1] ;
56
AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
57
if (p1 > p2)
58
{
59
/* column pointers must be ascending */
60
AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
61
return (FALSE) ;
62
}
63
ilast = EMPTY ;
64
for (p = p1 ; p < p2 ; p++)
65
{
66
i = Ai [p] ;
67
AMD_DEBUG3 (("row: "ID"\n", i)) ;
68
if (i <= ilast || i >= n_row)
69
{
70
/* row index out of range, or unsorted */
71
AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
72
return (FALSE) ;
73
}
74
ilast = i ;
75
}
76
}
77
return (TRUE) ;
78
}
79
80