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 1548, Mon Sep 11 22:13:07 2006 UTC revision 1618, Fri Oct 6 15:44:01 2006 UTC
# Line 4  Line 4 
4    
5  SEXP Csparse_validate(SEXP x)  SEXP Csparse_validate(SEXP x)
6  {  {
7        /* NB: we do *NOT* check a potential 'x' slot here, at all */
8        cholmod_sparse *chx = as_cholmod_sparse(x);
9      SEXP pslot = GET_SLOT(x, Matrix_pSym),      SEXP pslot = GET_SLOT(x, Matrix_pSym),
10          islot = GET_SLOT(x, Matrix_iSym);          islot = GET_SLOT(x, Matrix_iSym);
11      int j, ncol = length(pslot) - 1,      int j, k, ncol = length(pslot) - 1,
12          *dims = INTEGER(GET_SLOT(x, Matrix_DimSym)),          *dims = INTEGER(GET_SLOT(x, Matrix_DimSym)),
13          nrow, *xp = INTEGER(pslot),          nrow, sorted, *xp = INTEGER(pslot),
14          *xi = INTEGER(islot);          *xi = INTEGER(islot);
15    
16      nrow = dims[0];      nrow = dims[0];
# Line 17  Line 19 
19      if (xp[0] != 0)      if (xp[0] != 0)
20          return mkString(_("first element of slot p must be zero"));          return mkString(_("first element of slot p must be zero"));
21      if (length(islot) != xp[ncol])      if (length(islot) != xp[ncol])
22          return mkString(_("last element of slot p must match length of slots i and x"));          return
23      for (j = 0; j < ncol; j++) {              mkString(_("last element of slot p must match length of slots i and x"));
         if (xp[j] > xp[j+1])  
             return mkString(_("slot p must be non-decreasing"));  
     }  
24      for (j = 0; j < length(islot); j++) {      for (j = 0; j < length(islot); j++) {
25          if (xi[j] < 0 || xi[j] >= nrow)          if (xi[j] < 0 || xi[j] >= nrow)
26              return mkString(_("all row indices must be between 0 and nrow-1"));              return mkString(_("all row indices must be between 0 and nrow-1"));
27      }      }
28        sorted = TRUE;
29        for (j = 0; j < ncol; j++) {
30            if (xp[j] > xp[j+1])
31                return mkString(_("slot p must be non-decreasing"));
32            for (k = xp[j] + 1; k < xp[j + 1]; k++)
33                if (xi[k] < xi[k - 1]) sorted = FALSE;
34        }
35        if (!sorted) cholmod_sort(chx, &c);
36        Free(chx);
37      return ScalarLogical(1);      return ScalarLogical(1);
38  }  }
39    
# Line 97  Line 105 
105                                GET_SLOT(x, Matrix_DimNamesSym));                                GET_SLOT(x, Matrix_DimNamesSym));
106  }  }
107    
108    SEXP Csparse_general_to_symmetric(SEXP x, SEXP uplo)
109    {
110        cholmod_sparse *chx = as_cholmod_sparse(x), *chgx;
111        int uploT = (*CHAR(asChar(uplo)) == 'U') ? -1 : 1;
112        int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;
113    
114        chgx = cholmod_copy(chx, /* stype: */ uploT, chx->xtype, &c);
115        /* xtype: pattern, "real", complex or .. */
116        Free(chx);
117        return chm_sparse_to_SEXP(chgx, 1, 0, Rkind, "",
118                                  GET_SLOT(x, Matrix_DimNamesSym));
119    }
120    
121  SEXP Csparse_transpose(SEXP x, SEXP tri)  SEXP Csparse_transpose(SEXP x, SEXP tri)
122  {  {
123      cholmod_sparse *chx = as_cholmod_sparse(x);      cholmod_sparse *chx = as_cholmod_sparse(x);
124        int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;
125      cholmod_sparse *chxt = cholmod_transpose(chx, (int) chx->xtype, &c);      cholmod_sparse *chxt = cholmod_transpose(chx, (int) chx->xtype, &c);
126      SEXP dn = PROTECT(duplicate(GET_SLOT(x, Matrix_DimNamesSym))), tmp;      SEXP dn = PROTECT(duplicate(GET_SLOT(x, Matrix_DimNamesSym))), tmp;
127      int uploT = 0; char *diag = "";      int uploT = 0; char *diag = "";
     int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;  
128    
129      Free(chx);      Free(chx);
130      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */
# Line 175  Line 196 
196          chxt = cholmod_transpose(chx, chx->xtype, &c);          chxt = cholmod_transpose(chx, chx->xtype, &c);
197      chcp = cholmod_aat((!tr) ? chxt : chx, (int *) NULL, 0, chx->xtype, &c);      chcp = cholmod_aat((!tr) ? chxt : chx, (int *) NULL, 0, chx->xtype, &c);
198      if(!chcp)      if(!chcp)
199          error("Csparse_crossprod(): error return from cholmod_aat()");          error(_("Csparse_crossprod(): error return from cholmod_aat()"));
200      cholmod_band_inplace(0, chcp->ncol, chcp->xtype, chcp, &c);      cholmod_band_inplace(0, chcp->ncol, chcp->xtype, chcp, &c);
201      chcp->stype = 1;      chcp->stype = 1;
202      if (trip) {      if (trip) {
# Line 194  Line 215 
215      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);
216  }  }
217    
218    SEXP Csparse_drop(SEXP x, SEXP tol)
219    {
220        cholmod_sparse *chx = as_cholmod_sparse(x),
221            *ans = cholmod_copy(chx, chx->stype, chx->xtype, &c);
222        double dtol = asReal(tol);
223        int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;
224    
225        if(!cholmod_drop(dtol, ans, &c))
226            error(_("cholmod_drop() failed"));
227        Free(chx);
228        /* FIXME: currently drops dimnames */
229        return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "", R_NilValue);
230    }
231    
232    
233  SEXP Csparse_horzcat(SEXP x, SEXP y)  SEXP Csparse_horzcat(SEXP x, SEXP y)
234  {  {
235      cholmod_sparse *chx = as_cholmod_sparse(x),      cholmod_sparse *chx = as_cholmod_sparse(x),

Legend:
Removed from v.1548  
changed lines
  Added in v.1618

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