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 1598, Fri Sep 29 09:39:34 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    #ifdef _not_yet_FIXME_
109    /* MM: This would seem useful; e.g. lsC* can hardly be coerced to ! */
110    SEXP Csparse_general_to_symmetric(SEXP x,
111                                      int stype)/*-1 : "L", +1 : "U" */
112    {
113        cholmod_sparse *chx = as_cholmod_sparse(x), *chgx;
114        int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;
115    
116        chgx = cholmod_copy(chx, /* stype: */ stype, chx->xtype, &c);
117        /* xtype: pattern, "real", complex or .. */
118        Free(chx);
119        return chm_sparse_to_SEXP(chgx, 1, 0, Rkind, "",
120                                  GET_SLOT(x, Matrix_DimNamesSym));
121    }
122    
123    #endif
124    
125  SEXP Csparse_transpose(SEXP x, SEXP tri)  SEXP Csparse_transpose(SEXP x, SEXP tri)
126  {  {
127      cholmod_sparse *chx = as_cholmod_sparse(x);      cholmod_sparse *chx = as_cholmod_sparse(x);
128        int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;
129      cholmod_sparse *chxt = cholmod_transpose(chx, (int) chx->xtype, &c);      cholmod_sparse *chxt = cholmod_transpose(chx, (int) chx->xtype, &c);
130      SEXP dn = PROTECT(duplicate(GET_SLOT(x, Matrix_DimNamesSym))), tmp;      SEXP dn = PROTECT(duplicate(GET_SLOT(x, Matrix_DimNamesSym))), tmp;
131      int uploT = 0; char *diag = "";      int uploT = 0; char *diag = "";
     int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;  
132    
133      Free(chx);      Free(chx);
134      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */

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

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