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 3147, Thu Oct 29 16:56:10 2015 UTC revision 3213, Tue Apr 18 20:14:20 2017 UTC
# Line 151  Line 151 
151       * BUT, much worse (FIXME!), it also transforms CHOLMOD_PATTERN ("n") matrices       * BUT, much worse (FIXME!), it also transforms CHOLMOD_PATTERN ("n") matrices
152       * to numeric (CHOLMOD_REAL) ones {and we "revert" via chm_dense_to_SEXP()}: */       * to numeric (CHOLMOD_REAL) ones {and we "revert" via chm_dense_to_SEXP()}: */
153      CHM_DN chxd = cholmod_sparse_to_dense(chxs, &c);      CHM_DN chxd = cholmod_sparse_to_dense(chxs, &c);
154        /* FIXME: The above FAILS for prod(dim(.)) > INT_MAX
155         * ----
156         * TODO: use cholmod_l_* but also the 'cl' global ==> many changes in chm_common.[ch]
157         * >>>>>>>>>>> TODO <<<<<<<<<<<<
158         * CHM_DN chxd = cholmod_l_sparse_to_dense(chxs, &cl); */
159        //                   ^^^ important when prod(dim(.)) > INT_MAX
160      int Rkind = (chxs->xtype == CHOLMOD_PATTERN)? -1 : Real_kind(x);      int Rkind = (chxs->xtype == CHOLMOD_PATTERN)? -1 : Real_kind(x);
161    
162      SEXP ans = chm_dense_to_SEXP(chxd, 1, Rkind, GET_SLOT(x, Matrix_DimNamesSym),      SEXP ans = chm_dense_to_SEXP(chxd, 1, Rkind, GET_SLOT(x, Matrix_DimNamesSym),
# Line 407  Line 413 
413      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */
414      SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));      SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));
415      SET_VECTOR_ELT(dn, 1, tmp);      SET_VECTOR_ELT(dn, 1, tmp);
416      if(!isNull(tmp = getAttrib(dn, R_NamesSymbol))) { // swap names(dimnames(.)):      tmp = PROTECT(getAttrib(dn, R_NamesSymbol));
417        if(!isNull(tmp)) { // swap names(dimnames(.)):
418          SEXP nms_dns = PROTECT(allocVector(VECSXP, 2));          SEXP nms_dns = PROTECT(allocVector(VECSXP, 2));
419          SET_VECTOR_ELT(nms_dns, 1, STRING_ELT(tmp, 0));          SET_VECTOR_ELT(nms_dns, 1, STRING_ELT(tmp, 0));
420          SET_VECTOR_ELT(nms_dns, 0, STRING_ELT(tmp, 1));          SET_VECTOR_ELT(nms_dns, 0, STRING_ELT(tmp, 1));
421          setAttrib(dn, R_NamesSymbol, nms_dns);          setAttrib(dn, R_NamesSymbol, nms_dns);
422          UNPROTECT(1);          UNPROTECT(1);
423      }      }
424      UNPROTECT(1);  
425      return chm_sparse_to_SEXP(chxt, 1, /* SWAP 'uplo' for triangular */      SEXP ans = chm_sparse_to_SEXP(chxt, 1, /* SWAP 'uplo' for triangular */
426                                tr ? ((*uplo_P(x) == 'U') ? -1 : 1) : 0,                                tr ? ((*uplo_P(x) == 'U') ? -1 : 1) : 0,
427                                Rkind, tr ? diag_P(x) : "", dn);                                Rkind, tr ? diag_P(x) : "", dn);
428        UNPROTECT(2);
429        return ans;
430  }  }
431    
432  /** @brief  A %*% B  - for matrices of class CsparseMatrix (R package "Matrix")  /** @brief  A %*% B  - for matrices of class CsparseMatrix (R package "Matrix")
# Line 926  Line 935 
935      if (csize >= 0 && !isInteger(j))      if (csize >= 0 && !isInteger(j))
936          error(_("Index j must be NULL or integer"));          error(_("Index j must be NULL or integer"));
937    
938        /* Must treat 'NA's in i[] and j[] here -- they are *not* treated by Cholmod!
939         * haveNA := ...
940           if(haveNA) {
941             a. i = removeNA(i); j =removeNA(j), and remember where they were
942             b. ans = CHM_SUB(.., i, j)
943             c. add NA rows and/or columns to 'ans' according to
944                place of NA's in i and/or j.
945           } else {
946             ans = CHM_SUB(.....)  // == current code
947           }
948         */
949  #define CHM_SUB(_M_, _i_, _j_)                                  \  #define CHM_SUB(_M_, _i_, _j_)                                  \
950      cholmod_submatrix(_M_,                                      \      cholmod_submatrix(_M_,                                      \
951                        (rsize < 0) ? NULL : INTEGER(_i_), rsize, \                        (rsize < 0) ? NULL : INTEGER(_i_), rsize, \
# Line 935  Line 955 
955      if (!chx->stype) {/* non-symmetric Matrix */      if (!chx->stype) {/* non-symmetric Matrix */
956          ans = CHM_SUB(chx, i, j);          ans = CHM_SUB(chx, i, j);
957      }      }
958      else {      else { /* symmetric : "dsCMatrix";
959          /* for now, cholmod_submatrix() only accepts "generalMatrix" */                currently, cholmod_submatrix() only accepts "generalMatrix" */
960          CHM_SP tmp = cholmod_copy(chx, /* stype: */ 0, chx->xtype, &c);          CHM_SP tmp = cholmod_copy(chx, /* stype: */ 0, chx->xtype, &c);
961          ans = CHM_SUB(tmp, i, j);          ans = CHM_SUB(tmp, i, j);
962          cholmod_free_sparse(&tmp, &c);          cholmod_free_sparse(&tmp, &c);
# Line 948  Line 968 
968      /*  dn = PROTECT(allocVector(VECSXP, 2)); */      /*  dn = PROTECT(allocVector(VECSXP, 2)); */
969      return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "", /* dimnames: */ R_NilValue);      return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "", /* dimnames: */ R_NilValue);
970  }  }
971    #undef CHM_SUB
972    
973  #define _d_Csp_  #define _d_Csp_
974  #include "t_Csparse_subassign.c"  #include "t_Csparse_subassign.c"

Legend:
Removed from v.3147  
changed lines
  Added in v.3213

root@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