SCM

SCM Repository

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

Diff of /pkg/src/dgTMatrix.c

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

revision 921, Sat Sep 17 14:27:41 2005 UTC revision 922, Sun Sep 18 16:33:54 2005 UTC
# Line 1  Line 1 
 /* Sparse matrices in triplet form */  
1  #include "dgTMatrix.h"  #include "dgTMatrix.h"
2    
3    #ifdef USE_CHOLMOD
4    #include "chm_common.h"
5    #include "Tsparse.h"
6    #endif /* USE_CHOLMOD */
7    
8  SEXP dgTMatrix_validate(SEXP x)  SEXP dgTMatrix_validate(SEXP x)
9  {  {
10      SEXP      SEXP
11          islot = GET_SLOT(x, Matrix_iSym),          islot = GET_SLOT(x, Matrix_iSym),
12          jslot = GET_SLOT(x, Matrix_jSym),          xslot = GET_SLOT(x, Matrix_xSym);
13          xslot = GET_SLOT(x, Matrix_xSym),  
14          dimslot = GET_SLOT(x, Matrix_DimSym);      if (LENGTH(xslot) != LENGTH(islot))
15      int j,          return mkString(_("lengths of slots i and x must match"));
         *dims = INTEGER(dimslot),  
         ncol, nrow, nnz = length(islot),  
         *xj = INTEGER(jslot),  
         *xi = INTEGER(islot);  
   
     if (length(xslot) != nnz || length(jslot) != nnz)  
         return mkString(_("lengths of slots i, j, and x must match"));  
     if (length(dimslot) != 2)  
         return mkString(_("slot Dim must have length 2"));  
     nrow = dims[0]; ncol = dims[1];  
     for (j = 0; j < nnz; j++) {  
         if (xi[j] < 0 || xi[j] >= nrow)  
             return mkString(_("all row indices must be between 0 and nrow-1"));  
         if (xj[j] < 0 || xj[j] >= ncol)  
             return mkString(_("all column indices must be between 0 and ncol-1"));  
     }  
16      return ScalarLogical(1);      return ScalarLogical(1);
17  }  }
18    
19  SEXP dgTMatrix_to_dgCMatrix(SEXP x)  SEXP dgTMatrix_to_dgCMatrix(SEXP x)
20  {  {
21    #ifdef USE_CHOLMOD
22        return Tsparse_to_Csparse(x);
23    #else
24      SEXP dd = GET_SLOT(x, Matrix_DimSym),      SEXP dd = GET_SLOT(x, Matrix_DimSym),
25          iP = GET_SLOT(x, Matrix_iSym),          iP = GET_SLOT(x, Matrix_iSym),
26          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));
27      int *dims = INTEGER(dd), nnz = length(iP);      int *dims = INTEGER(dd), nnz = length(iP);
28      int *p, *ti = Calloc(nnz, int), m = dims[0], n = dims[1];      int *p = INTEGER(GET_SLOT(ans, Matrix_pSym)),
29            *ti = Calloc(nnz, int), m = dims[0], n = dims[1];
30      double *tx = Calloc(nnz, double);      double *tx = Calloc(nnz, double);
31    
32      SET_SLOT(ans, Matrix_pSym, allocVector(INTSXP, n + 1));      SET_SLOT(ans, Matrix_pSym, allocVector(INTSXP, n + 1));
33      SET_SLOT(ans, Matrix_DimSym, duplicate(dd));      SET_SLOT(ans, Matrix_DimSym, duplicate(dd));
     p = INTEGER(GET_SLOT(ans, Matrix_pSym));  
34      triplet_to_col(m, n, nnz, INTEGER(iP),      triplet_to_col(m, n, nnz, INTEGER(iP),
35                     INTEGER(GET_SLOT(x, Matrix_jSym)),                     INTEGER(GET_SLOT(x, Matrix_jSym)),
36                     REAL(GET_SLOT(x, Matrix_xSym)),                     REAL(GET_SLOT(x, Matrix_xSym)),
# Line 53  Line 44 
44      Free(ti); Free(tx);      Free(ti); Free(tx);
45      UNPROTECT(1);      UNPROTECT(1);
46      return ans;      return ans;
47    #endif /* USE_CHOLMOD */
48  }  }
49    
50  static void  static void

Legend:
Removed from v.921  
changed lines
  Added in v.922

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