SCM

SCM Repository

[matrix] Diff of /pkg/Matrix/src/Csparse.c
ViewVC logotype

Diff of /pkg/Matrix/src/Csparse.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2888, Wed Aug 7 13:56:43 2013 UTC revision 2889, Thu Aug 8 21:06:22 2013 UTC
# Line 37  Line 37 
37      return Csparse_validate_(x, FALSE);      return Csparse_validate_(x, FALSE);
38  }  }
39    
40    
41    #define _t_Csparse_validate
42    #include "t_Csparse_validate.c"
43    
44    #define _t_Csparse_sort
45    #include "t_Csparse_validate.c"
46    
47    // R: .validateCsparse(x, sort.if.needed = FALSE) :
48  SEXP Csparse_validate2(SEXP x, SEXP maybe_modify) {  SEXP Csparse_validate2(SEXP x, SEXP maybe_modify) {
49      return Csparse_validate_(x, asLogical(maybe_modify));      return Csparse_validate_(x, asLogical(maybe_modify));
50  }  }
51    
52  SEXP Csparse_validate_(SEXP x, Rboolean maybe_modify)  // R: Matrix:::.sortCsparse(x) :
53  {  SEXP Csparse_sort (SEXP x) {
54      /* NB: we do *NOT* check a potential 'x' slot here, at all */     int ok = Csparse_sort_2(x, TRUE); // modifying x directly
55      SEXP pslot = GET_SLOT(x, Matrix_pSym),     if(!ok) warning(_("Csparse_sort(x): x is not a valid (apart from sorting) CsparseMatrix"));
56          islot = GET_SLOT(x, Matrix_iSym);     return x;
     Rboolean sorted, strictly;  
     int j, k,  
         *dims = INTEGER(GET_SLOT(x, Matrix_DimSym)),  
         nrow = dims[0],  
         ncol = dims[1],  
         *xp = INTEGER(pslot),  
         *xi = INTEGER(islot);  
   
     if (length(pslot) != dims[1] + 1)  
         return mkString(_("slot p must have length = ncol(.) + 1"));  
     if (xp[0] != 0)  
         return mkString(_("first element of slot p must be zero"));  
     if (length(islot) < xp[ncol]) /* allow larger slots from over-allocation!*/  
         return  
             mkString(_("last element of slot p must match length of slots i and x"));  
     for (j = 0; j < xp[ncol]; j++) {  
         if (xi[j] < 0 || xi[j] >= nrow)  
             return mkString(_("all row indices must be between 0 and nrow-1"));  
     }  
     sorted = TRUE; strictly = TRUE;  
     for (j = 0; j < ncol; j++) {  
         if (xp[j] > xp[j + 1])  
             return mkString(_("slot p must be non-decreasing"));  
         if(sorted) /* only act if >= 2 entries in column j : */  
             for (k = xp[j] + 1; k < xp[j + 1]; k++) {  
                 if (xi[k] < xi[k - 1])  
                     sorted = FALSE;  
                 else if (xi[k] == xi[k - 1])  
                     strictly = FALSE;  
             }  
     }  
     if (!sorted) {  
         if(maybe_modify) {  
             CHM_SP chx = (CHM_SP) alloca(sizeof(cholmod_sparse));  
             R_CheckStack();  
             as_cholmod_sparse(chx, x, FALSE, TRUE);/*-> cholmod_l_sort() ! */  
             /* as chx = AS_CHM_SP__(x)  but  ^^^^ sorting x in_place !!! */  
   
             /* Now re-check that row indices are *strictly* increasing  
              * (and not just increasing) within each column : */  
             for (j = 0; j < ncol; j++) {  
                 for (k = xp[j] + 1; k < xp[j + 1]; k++)  
                     if (xi[k] == xi[k - 1])  
                         return mkString(_("slot i is not *strictly* increasing inside a column (even after cholmod_l_sort)"));  
             }  
         } else { /* no modifying sorting : */  
             return mkString(_("row indices are not sorted within columns"));  
         }  
     } else if(!strictly) {  /* sorted, but not strictly */  
         return mkString(_("slot i is not *strictly* increasing inside a column"));  
     }  
     return ScalarLogical(1);  
57  }  }
58    
59  SEXP Rsparse_validate(SEXP x)  SEXP Rsparse_validate(SEXP x)

Legend:
Removed from v.2888  
changed lines
  Added in v.2889

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge