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 2677, Sat Jun 25 19:18:12 2011 UTC revision 2681, Mon Aug 1 20:43:16 2011 UTC
# Line 628  Line 628 
628  {  {
629      // TODO: for other classes consider using a trick as  RallocedReal() in ./chm_common.c      // TODO: for other classes consider using a trick as  RallocedReal() in ./chm_common.c
630      static const char      static const char
631          *valid_cM [] = {"dgCMatrix",// the only one, for "the moment", .. TODO          *valid_cM [] = { // the only ones, for "the moment". FIXME: extend (!)
632            "dgCMatrix",// 0
633            "dtCMatrix",// 1
634                          ""},                          ""},
635            // value: assume a  "dsparseVector" for now -- slots: (i, length, x)
636          *valid_spv[] = {"dsparseVector",          *valid_spv[] = {"dsparseVector",
637                          ""};                          ""};
638    
639      int ctype = Matrix_check_class_etc(x, valid_cM);      int ctype_x = Matrix_check_class_etc(x, valid_cM),
640      if (ctype < 0)          ctype_v = Matrix_check_class_etc(value, valid_spv);
641        if (ctype_x < 0)
642          error(_("invalid class of 'x' in Csparse_subassign()"));          error(_("invalid class of 'x' in Csparse_subassign()"));
643      // value: assume a  "dsparseVector" for now -- slots: (i, length, x)      if (ctype_v < 0)
     ctype = Matrix_check_class_etc(value, valid_spv);  
     if (ctype < 0)  
644          error(_("invalid class of 'value' in Csparse_subassign()"));          error(_("invalid class of 'value' in Csparse_subassign()"));
645    
646      SEXP      SEXP
# Line 676  Line 678 
678    
679      SEXP ans;      SEXP ans;
680      /* Instead of simple "duplicate": PROTECT(ans = duplicate(x)) , build up: */      /* Instead of simple "duplicate": PROTECT(ans = duplicate(x)) , build up: */
681      ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix" /* <- TODO*/)));      // Assuming that ans will have the same basic Matrix type as x :
682        ans = PROTECT(NEW_OBJECT(MAKE_CLASS(valid_cM[ctype_x])));
683      SET_SLOT(ans, Matrix_DimSym,      duplicate(dimslot));      SET_SLOT(ans, Matrix_DimSym,      duplicate(dimslot));
684      SET_SLOT(ans, Matrix_DimNamesSym, duplicate(GET_SLOT(x, Matrix_DimNamesSym)));      SET_SLOT(ans, Matrix_DimNamesSym, duplicate(GET_SLOT(x, Matrix_DimNamesSym)));
685      SET_SLOT(ans, Matrix_pSym,        duplicate(GET_SLOT(x, Matrix_pSym)));      SET_SLOT(ans, Matrix_pSym,        duplicate(GET_SLOT(x, Matrix_pSym)));
# Line 768  Line 771 
771    
772                  // Case I --------------------------------------------                  // Case I --------------------------------------------
773  /*              if(v == z_ans) { // remove x[i, j] = M_ij  which we know is *non*-zero */  /*              if(v == z_ans) { // remove x[i, j] = M_ij  which we know is *non*-zero */
774    //-------- Better (memory-management) *NOT* to remove, but rather at the very end
775    //         currently using  drop0() in R code
776  /*                  // we know : have_entry = TRUE ; */  /*                  // we know : have_entry = TRUE ; */
777  /*                  //  ri[ind] == i__; M_ij = rx[ind]; */  /*                  //  ri[ind] == i__; M_ij = rx[ind]; */
778  /* #ifdef MATRIX_SUBASSIGN_VERBOSE */  /* #ifdef MATRIX_SUBASSIGN_VERBOSE */
# Line 841  Line 846 
846          }// for( ii )          }// for( ii )
847      }// for( jj )      }// for( jj )
848    
849        if(ctype_x == 1) { // triangularMatrix: copy the 'diag' and 'uplo' slots
850            SET_SLOT(ans, Matrix_uploSym, duplicate(GET_SLOT(x, Matrix_uploSym)));
851            SET_SLOT(ans, Matrix_diagSym, duplicate(GET_SLOT(x, Matrix_diagSym)));
852        }
853      // now assign the i- and x- slots,  free memory and return :      // now assign the i- and x- slots,  free memory and return :
854      Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_iSym,  INTSXP, nnz)), ri, nnz);      Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_iSym,  INTSXP, nnz)), ri, nnz);
855      Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, nnz)), rx, nnz);      Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, nnz)), rx, nnz);

Legend:
Removed from v.2677  
changed lines
  Added in v.2681

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