Amesos Package Browser (Single Doxygen Collection) Development
amesos_amd_l_valid.c
Go to the documentation of this file.
00001 /* ========================================================================= */
00002 /* === AMD_valid =========================================================== */
00003 /* ========================================================================= */
00004 
00005 /* ------------------------------------------------------------------------- */
00006 /* AMD, Copyright (c) Timothy A. Davis,              */
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/amd                          */
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, AMD_INVALID is returned.  If the
00024  * following condition holds, AMD_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, AMD_OK is returned.
00031  *
00032  * In v1.2 and earlier, this function returned TRUE if the matrix was valid
00033  * (now returns AMD_OK), or FALSE otherwise (now returns AMD_INVALID or
00034  * AMD_OK_BUT_JUMBLED).
00035  */
00036 
00037 /* This file should make the long int version of AMD */
00038 #define DLONG 1
00039 
00040 #include "amesos_amd_internal.h"
00041 
00042 GLOBAL Int AMD_valid
00043 (
00044     /* inputs, not modified on output: */
00045     Int n_row,    /* A is n_row-by-n_col */
00046     Int n_col,
00047     const Int Ap [ ], /* column pointers of A, of size n_col+1 */
00048     const Int Ai [ ]  /* row indices of A, of size nz = Ap [n_col] */
00049 )
00050 {
00051     Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ;
00052 
00053     if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
00054     {
00055   return (AMD_INVALID) ;
00056     }
00057     nz = Ap [n_col] ;
00058     if (Ap [0] != 0 || nz < 0)
00059     {
00060   /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
00061   AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
00062   return (AMD_INVALID) ;
00063     }
00064     for (j = 0 ; j < n_col ; j++)
00065     {
00066   p1 = Ap [j] ;
00067   p2 = Ap [j+1] ;
00068   AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
00069   if (p1 > p2)
00070   {
00071       /* column pointers must be ascending */
00072       AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
00073       return (AMD_INVALID) ;
00074   }
00075   ilast = EMPTY ;
00076   for (p = p1 ; p < p2 ; p++)
00077   {
00078       i = Ai [p] ;
00079       AMD_DEBUG3 (("row: "ID"\n", i)) ;
00080       if (i < 0 || i >= n_row)
00081       {
00082     /* row index out of range */
00083     AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
00084     return (AMD_INVALID) ;
00085       }
00086       if (i <= ilast)
00087       {
00088     /* row index unsorted, or duplicate entry present */
00089     AMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i));
00090     result = AMD_OK_BUT_JUMBLED ;
00091       }
00092       ilast = i ;
00093   }
00094     }
00095     return (result) ;
00096 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines