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 2516, Mon Feb 1 13:27:27 2010 UTC pkg/Matrix/src/Csparse.c revision 2586, Sun Jul 25 02:32:06 2010 UTC
# Line 425  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 436  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 503  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 516  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.2516  
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