SCM

SCM Repository

[matrix] Diff of /branches/Matrix-mer2/src/dgCMatrix.c
ViewVC logotype

Diff of /branches/Matrix-mer2/src/dgCMatrix.c

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

revision 945, Wed Sep 28 08:54:28 2005 UTC revision 956, Fri Sep 30 17:28:00 2005 UTC
# Line 4  Line 4 
4  #include "chm_common.h"  #include "chm_common.h"
5  #endif  #endif
6    
7    /* FIXME -- we "forget" about dimnames almost everywhere : */
8    
9  SEXP dgCMatrix_validate(SEXP x)  SEXP dgCMatrix_validate(SEXP x)
10  {  {
11      SEXP pslot = GET_SLOT(x, Matrix_pSym),      SEXP pslot = GET_SLOT(x, Matrix_pSym),
# Line 300  Line 302 
302      return ans;      return ans;
303  }  }
304    
305  SEXP matrix_to_csc(SEXP A)  SEXP double_to_csc(double *a, int *dim_a)
306  {  {
307      SEXP val = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));      SEXP val = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));
308      int *adims = INTEGER(getAttrib(A, R_DimSymbol)), j,      int j, maxnz, nrow, ncol, nnz, *vp, *vi;
         maxnz, nrow, ncol, nnz, *vp, *vi;  
   
309      double *vx;      double *vx;
310    
311      if (!(isMatrix(A) && isReal(A)))      nrow = dim_a[0]; ncol = dim_a[1];
         error(_("A must be a numeric matrix"));  
     nrow = adims[0]; ncol = adims[1];  
312      SET_SLOT(val, Matrix_factorSym, allocVector(VECSXP, 0));      SET_SLOT(val, Matrix_factorSym, allocVector(VECSXP, 0));
313      SET_SLOT(val, Matrix_DimSym, allocVector(INTSXP, 2));      SET_SLOT(val, Matrix_DimSym, allocVector(INTSXP, 2));
314      SET_SLOT(val, Matrix_pSym, allocVector(INTSXP, ncol + 1));      SET_SLOT(val, Matrix_pSym, allocVector(INTSXP, ncol + 1));
# Line 322  Line 320 
320          int i;          int i;
321          vp[j] = nnz;          vp[j] = nnz;
322          for (i = 0; i < nrow; i++) {          for (i = 0; i < nrow; i++) {
323              double val = REAL(A)[i + j * nrow];              double val = a[i + j * nrow];
324              if (val != 0.) {              if (val != 0.) {
325                  vi[nnz] = i;                  vi[nnz] = i;
326                  vx[nnz] = val;                  vx[nnz] = val;
# Line 340  Line 338 
338      return dgCMatrix_set_Dim(val, nrow);      return dgCMatrix_set_Dim(val, nrow);
339  }  }
340    
341    SEXP matrix_to_csc(SEXP A)
342    {
343        if (!(isMatrix(A) && isReal(A)))
344            error(_("A must be a numeric matrix"));
345        return double_to_csc(REAL(A),
346                             INTEGER(getAttrib(A, R_DimSymbol)));
347    }
348    
349    SEXP dgeMatrix_to_csc(SEXP x)
350    {
351        return double_to_csc(   REAL(GET_SLOT(x, Matrix_xSym)),
352                             INTEGER(GET_SLOT(x, Matrix_DimSym)));
353    }
354    
355    
356    
357  SEXP dgTMatrix_to_csc(SEXP dgTMatrix)  SEXP dgTMatrix_to_csc(SEXP dgTMatrix)
358  {  {

Legend:
Removed from v.945  
changed lines
  Added in v.956

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