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

pkg/src/Csparse.c revision 2491, Sat Oct 24 21:04:46 2009 UTC pkg/Matrix/src/Csparse.c revision 2586, Sun Jul 25 02:32:06 2010 UTC
# Line 253  Line 253 
253      const char *cl_a = class_P(a), *cl_b = class_P(b);      const char *cl_a = class_P(a), *cl_b = class_P(b);
254      char diag[] = {'\0', '\0'};      char diag[] = {'\0', '\0'};
255      int uploT = 0;      int uploT = 0;
256      SEXP dn = allocVector(VECSXP, 2);      SEXP dn = PROTECT(allocVector(VECSXP, 2));
257      R_CheckStack();      R_CheckStack();
258    
259  #ifdef DEBUG_Matrix  #ifdef DEBUG_Matrix_verbose
260      Rprintf("DBG Csparse_C*_prod(%s, %s)\n", cl_a, cl_b);      Rprintf("DBG Csparse_C*_prod(%s, %s)\n", cl_a, cl_b);
261  #endif  #endif
262    
# Line 281  Line 281 
281                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 0)));                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 0)));
282      SET_VECTOR_ELT(dn, 1,      SET_VECTOR_ELT(dn, 1,
283                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));
284        UNPROTECT(1);
285      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);
286  }  }
287    
# Line 294  Line 295 
295      const char *cl_a = class_P(a), *cl_b = class_P(b);      const char *cl_a = class_P(a), *cl_b = class_P(b);
296      char diag[] = {'\0', '\0'};      char diag[] = {'\0', '\0'};
297      int uploT = 0;      int uploT = 0;
298      SEXP dn = allocVector(VECSXP, 2);      SEXP dn = PROTECT(allocVector(VECSXP, 2));
299      R_CheckStack();      R_CheckStack();
300    
301      chTr = cholmod_l_transpose((tr) ? chb : cha, chb->xtype, &c);      chTr = cholmod_l_transpose((tr) ? chb : cha, chb->xtype, &c);
# Line 313  Line 314 
314              }              }
315              else diag[0]= 'N';              else diag[0]= 'N';
316          }          }
   
317      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
318                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), (tr) ? 0 : 1)));                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), (tr) ? 0 : 1)));
319      SET_VECTOR_ELT(dn, 1,      SET_VECTOR_ELT(dn, 1,
320                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), (tr) ? 0 : 1)));                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), (tr) ? 0 : 1)));
321        UNPROTECT(1);
322      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);
323  }  }
324    
# Line 370  Line 371 
371  #ifdef AS_CHM_DIAGU2N_FIXED_FINALLY  #ifdef AS_CHM_DIAGU2N_FIXED_FINALLY
372      CHM_TR cht = trip ? AS_CHM_TR(x) : (CHM_TR) NULL;      CHM_TR cht = trip ? AS_CHM_TR(x) : (CHM_TR) NULL;
373  #else /* workaround needed:*/  #else /* workaround needed:*/
374      CHM_TR cht = trip ? AS_CHM_TR__(Tsparse_diagU2N(x)) : (CHM_TR) NULL;      SEXP xx = PROTECT(Tsparse_diagU2N(x));
375        CHM_TR cht = trip ? AS_CHM_TR__(xx) : (CHM_TR) NULL;
376  #endif  #endif
377      CHM_SP chcp, chxt,      CHM_SP chcp, chxt,
378          chx = (trip ?          chx = (trip ?
# Line 393  Line 395 
395                     duplicate(VECTOR_ELT(GET_SLOT(x, Matrix_DimNamesSym),                     duplicate(VECTOR_ELT(GET_SLOT(x, Matrix_DimNamesSym),
396                                          (tr) ? 0 : 1)));                                          (tr) ? 0 : 1)));
397      SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));      SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));
398    #ifdef AS_CHM_DIAGU2N_FIXED_FINALLY
399      UNPROTECT(1);      UNPROTECT(1);
400    #else
401        UNPROTECT(2);
402    #endif
403      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);
404  }  }
405    
# Line 419  Line 425 
425  SEXP Csparse_horzcat(SEXP x, SEXP y)  SEXP Csparse_horzcat(SEXP x, SEXP y)
426  {  {
427      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);
428      int Rkind = 0; /* only for "d" - FIXME */      int Rk_x = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0,
429            Rk_y = (chy->xtype != CHOLMOD_PATTERN) ? Real_kind(y) : 0,
430            Rkind = /* logical if both x and y are */ (Rk_x == 1 && Rk_y == 1) ? 1 : 0;
431      R_CheckStack();      R_CheckStack();
432    
433      /* FIXME: currently drops dimnames */      /* TODO: currently drops dimnames - and we fix at R level */
434      return chm_sparse_to_SEXP(cholmod_l_horzcat(chx, chy, 1, &c),      return chm_sparse_to_SEXP(cholmod_l_horzcat(chx, chy, 1, &c),
435                                1, 0, Rkind, "", R_NilValue);                                1, 0, Rkind, "", R_NilValue);
436  }  }
# Line 430  Line 438 
438  SEXP Csparse_vertcat(SEXP x, SEXP y)  SEXP Csparse_vertcat(SEXP x, SEXP y)
439  {  {
440      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);
441      int Rkind = 0; /* only for "d" - FIXME */      int Rk_x = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0,
442            Rk_y = (chy->xtype != CHOLMOD_PATTERN) ? Real_kind(y) : 0,
443            Rkind = /* logical if both x and y are */ (Rk_x == 1 && Rk_y == 1) ? 1 : 0;
444      R_CheckStack();      R_CheckStack();
445    
446      /* FIXME: currently drops dimnames */      /* TODO: currently drops dimnames - and we fix at R level */
447      return chm_sparse_to_SEXP(cholmod_l_vertcat(chx, chy, 1, &c),      return chm_sparse_to_SEXP(cholmod_l_vertcat(chx, chy, 1, &c),
448                                1, 0, Rkind, "", R_NilValue);                                1, 0, Rkind, "", R_NilValue);
449  }  }
# Line 497  Line 507 
507      }      }
508  }  }
509    
510    /**
511     * "Indexing" aka subsetting : Compute  x[i,j], also for vectors i and j
512     * Working via CHOLMOD_submatrix, see ./CHOLMOD/MatrixOps/cholmod_submatrix.c
513     * @param x CsparseMatrix
514     * @param i row     indices (0-origin), or NULL (R's)
515     * @param j columns indices (0-origin), or NULL
516     *
517     * @return x[i,j]  still CsparseMatrix --- currently, this loses dimnames
518     */
519  SEXP Csparse_submatrix(SEXP x, SEXP i, SEXP j)  SEXP Csparse_submatrix(SEXP x, SEXP i, SEXP j)
520  {  {
521      CHM_SP chx = AS_CHM_SP__(x);      CHM_SP chx = AS_CHM_SP(x); /* << does diagU2N() when needed */
522      int rsize = (isNull(i)) ? -1 : LENGTH(i),      int rsize = (isNull(i)) ? -1 : LENGTH(i),
523          csize = (isNull(j)) ? -1 : LENGTH(j);          csize = (isNull(j)) ? -1 : LENGTH(j);
524      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
# Line 510  Line 529 
529      if (csize >= 0 && !isInteger(j))      if (csize >= 0 && !isInteger(j))
530          error(_("Index j must be NULL or integer"));          error(_("Index j must be NULL or integer"));
531    
532      return chm_sparse_to_SEXP(cholmod_l_submatrix(chx, INTEGER(i), rsize,      if (chx->stype) /* symmetricMatrix */
533                                                  INTEGER(j), csize,          /* for now, cholmod_submatrix() only accepts "generalMatrix" */
534            chx = cholmod_l_copy(chx, /* stype: */ 0, chx->xtype, &c);
535    
536        return chm_sparse_to_SEXP(cholmod_l_submatrix(chx,
537                                    (rsize < 0) ? NULL : INTEGER(i), rsize,
538                                    (csize < 0) ? NULL : INTEGER(j), csize,
539                                                  TRUE, TRUE, &c),                                                  TRUE, TRUE, &c),
540                                1, 0, Rkind, "",                                1, 0, Rkind, "",
541                                /* FIXME: drops dimnames */ R_NilValue);                                /* FIXME: drops dimnames */ R_NilValue);

Legend:
Removed from v.2491  
changed lines
  Added in v.2586

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