Amesos Package Browser (Single Doxygen Collection) Development
amesos_camd_valid.c
Go to the documentation of this file.
00001 /* ========================================================================= */
00002 /* === CAMD_valid ========================================================== */
00003 /* ========================================================================= */
00004 
00005 /* ------------------------------------------------------------------------- */
00006 /* CAMD, Copyright (c) Timothy A. Davis, Yanqing Chen,           */
00007 /* Patrick R. Amestoy, and Iain S. Duff.  See ../README.txt for License.     */
00008 /* email: davis at cise.ufl.edu    CISE Department, Univ. of Florida.        */
00009 /* web: http://www.cise.ufl.edu/research/sparse/camd                         */
00010 /* ------------------------------------------------------------------------- */
00011 
00012 /* Check if a column-form matrix is valid or not.  The matrix A is
00013  * n_row-by-n_col.  The row indices of entries in column j are in
00014  * Ai [Ap [j] ... Ap [j+1]-1].  Required conditions are:
00015  *
00016  *  n_row >= 0
00017  *  n_col >= 0
00018  *  nz = Ap [n_col] >= 0      number of entries in the matrix
00019  *  Ap [0] == 0
00020  *  Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.
00021  *      Ai [0 ... nz-1] must be in the range 0 to n_row-1.
00022  *
00023  * If any of the above conditions hold, CAMD_INVALID is returned.  If the
00024  * following condition holds, CAMD_OK_BUT_JUMBLED is returned (a warning,
00025  * not an error):
00026  *
00027  *  row indices in Ai [Ap [j] ... Ap [j+1]-1] are not sorted in ascending
00028  *      order, and/or duplicate entries exist.
00029  *
00030  * Otherwise, CAMD_OK is returned.
00031  */
00032 
00033 #include "amesos_camd_internal.h"
00034 
00035 GLOBAL Int CAMD_valid
00036 (
00037     /* inputs, not modified on output: */
00038     Int n_row,    /* A is n_row-by-n_col */
00039     Int n_col,
00040     const Int Ap [ ], /* column pointers of A, of size n_col+1 */
00041     const Int Ai [ ]  /* row indices of A, of size nz = Ap [n_col] */
00042 )
00043 {
00044     Int nz, j, p1, p2, ilast, i, p, result = CAMD_OK ;
00045     if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
00046     {
00047   return (CAMD_INVALID) ;
00048     }
00049     nz = Ap [n_col] ;
00050     if (Ap [0] != 0 || nz < 0)
00051     {
00052   /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
00053   CAMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
00054   return (CAMD_INVALID) ;
00055     }
00056     for (j = 0 ; j < n_col ; j++)
00057     {
00058   p1 = Ap [j] ;
00059   p2 = Ap [j+1] ;
00060   CAMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
00061   if (p1 > p2)
00062   {
00063       /* column pointers must be ascending */
00064       CAMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
00065       return (CAMD_INVALID) ;
00066   }
00067   ilast = EMPTY ;
00068   for (p = p1 ; p < p2 ; p++)
00069   {
00070       i = Ai [p] ;
00071       CAMD_DEBUG3 (("row: "ID"\n", i)) ;
00072       if (i < 0 || i >= n_row)
00073       {
00074     /* row index out of range */
00075     CAMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
00076     return (CAMD_INVALID) ;
00077       }
00078       if (i <= ilast)
00079       {
00080     /* row index unsorted, or duplicate entry present */
00081     CAMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i));
00082     result = CAMD_OK_BUT_JUMBLED ;
00083       }
00084       ilast = i ;
00085   }
00086     }
00087     return (result) ;
00088 }
00089 
00090 
00091 GLOBAL Int CAMD_cvalid  /* return TRUE if the Constraint set is valid,
00092        * FALSE otherwise */
00093 (
00094     /* inputs, not modified on output: */
00095     Int n,    /* the length of constraint set */
00096     const Int C [ ] /* constraint set */
00097 )
00098 {
00099     Int i ;
00100     if (C != NULL)
00101     {
00102   for (i = 0 ; i < n ; i++)
00103   {
00104       if (C [i] < 0 || C [i] > n - 1)
00105       {
00106     CAMD_DEBUG0 (("C["ID"] = "ID" invalid\n", i, C [i])) ;
00107     return (FALSE) ;
00108       }
00109   }
00110     }
00111     return (TRUE) ;
00112 }
00113 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines