Amesos Package Browser (Single Doxygen Collection) Development
amesos_amd_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 #include "amesos_amd_internal.h"
00038 
00039 GLOBAL Int AMD_valid
00040 (
00041     /* inputs, not modified on output: */
00042     Int n_row,    /* A is n_row-by-n_col */
00043     Int n_col,
00044     const Int Ap [ ], /* column pointers of A, of size n_col+1 */
00045     const Int Ai [ ]  /* row indices of A, of size nz = Ap [n_col] */
00046 )
00047 {
00048     Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ;
00049 
00050     if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
00051     {
00052   return (AMD_INVALID) ;
00053     }
00054     nz = Ap [n_col] ;
00055     if (Ap [0] != 0 || nz < 0)
00056     {
00057   /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
00058   AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
00059   return (AMD_INVALID) ;
00060     }
00061     for (j = 0 ; j < n_col ; j++)
00062     {
00063   p1 = Ap [j] ;
00064   p2 = Ap [j+1] ;
00065   AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
00066   if (p1 > p2)
00067   {
00068       /* column pointers must be ascending */
00069       AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
00070       return (AMD_INVALID) ;
00071   }
00072   ilast = EMPTY ;
00073   for (p = p1 ; p < p2 ; p++)
00074   {
00075       i = Ai [p] ;
00076       AMD_DEBUG3 (("row: "ID"\n", i)) ;
00077       if (i < 0 || i >= n_row)
00078       {
00079     /* row index out of range */
00080     AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
00081     return (AMD_INVALID) ;
00082       }
00083       if (i <= ilast)
00084       {
00085     /* row index unsorted, or duplicate entry present */
00086     AMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i));
00087     result = AMD_OK_BUT_JUMBLED ;
00088       }
00089       ilast = i ;
00090   }
00091     }
00092     return (result) ;
00093 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines