/* ========================================================================= */1/* === AMD_valid =========================================================== */2/* ========================================================================= */34/* ------------------------------------------------------------------------- */5/* AMD Version 1.1 (Jan. 21, 2004), Copyright (c) 2004 by Timothy A. Davis, */6/* Patrick R. Amestoy, and Iain S. Duff. See ../README for License. */7/* email: [email protected] CISE Department, Univ. of Florida. */8/* web: http://www.cise.ufl.edu/research/sparse/amd */9/* ------------------------------------------------------------------------- */1011/* Check if a column-form matrix is valid or not. The matrix A is12* n_row-by-n_col. The row indices of entries in column j are in13* Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are:14*15* n_row >= 016* n_col >= 017* nz = Ap [n_col] >= 0 number of entries in the matrix18* Ap [0] == 019* Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.20* row indices in Ai [Ap [j] ... Ap [j+1]-1] must be sorted in ascending21* order, must be in the range 0 to n_row-1, and no duplicate entries22* can exist.23*24* Not user-callable.25*/2627#include "amd_internal.h"2829GLOBAL Int AMD_valid30(31/* inputs, not modified on output: */32Int n_row, /* A is n_row-by-n_col */33Int n_col,34const Int Ap [ ], /* column pointers of A, of size n_col+1 */35const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */36)37{38Int nz, j, p1, p2, ilast, i, p ;39if (n_row < 0 || n_col < 0)40{41AMD_DEBUG0 (("n must be >= 0: "ID" "ID"\n", n_row, n_col)) ;42return (FALSE) ;43}44nz = Ap [n_col] ;45if (Ap [0] != 0 || nz < 0)46{47/* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */48AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;49return (FALSE) ;50}51for (j = 0 ; j < n_col ; j++)52{53p1 = Ap [j] ;54p2 = Ap [j+1] ;55AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;56if (p1 > p2)57{58/* column pointers must be ascending */59AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;60return (FALSE) ;61}62ilast = EMPTY ;63for (p = p1 ; p < p2 ; p++)64{65i = Ai [p] ;66AMD_DEBUG3 (("row: "ID"\n", i)) ;67if (i <= ilast || i >= n_row)68{69/* row index out of range, or unsorted */70AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));71return (FALSE) ;72}73ilast = i ;74}75}76return (TRUE) ;77}787980