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 2516, Mon Feb 1 13:27:27 2010 UTC revision 2519, Fri Feb 5 17:20:14 2010 UTC
# Line 503  Line 503 
503      }      }
504  }  }
505    
506    /**
507     * "Indexing" aka subsetting : Compute  x[i,j], also for vectors i and j
508     * Working via CHOLMOD_submatrix, see ./CHOLMOD/MatrixOps/cholmod_submatrix.c
509     * @param x CsparseMatrix
510     * @param i row     indices (0-origin), or NULL (R's)
511     * @param j columns indices (0-origin), or NULL
512     *
513     * @return x[i,j]  still CsparseMatrix --- currently, this loses dimnames
514     */
515  SEXP Csparse_submatrix(SEXP x, SEXP i, SEXP j)  SEXP Csparse_submatrix(SEXP x, SEXP i, SEXP j)
516  {  {
517      CHM_SP chx = AS_CHM_SP__(x);      CHM_SP chx = AS_CHM_SP(x); /* << does diagU2N() when needed */
518      int rsize = (isNull(i)) ? -1 : LENGTH(i),      int rsize = (isNull(i)) ? -1 : LENGTH(i),
519          csize = (isNull(j)) ? -1 : LENGTH(j);          csize = (isNull(j)) ? -1 : LENGTH(j);
520      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
# Line 516  Line 525 
525      if (csize >= 0 && !isInteger(j))      if (csize >= 0 && !isInteger(j))
526          error(_("Index j must be NULL or integer"));          error(_("Index j must be NULL or integer"));
527    
528      return chm_sparse_to_SEXP(cholmod_l_submatrix(chx, INTEGER(i), rsize,      if (chx->stype) /* symmetricMatrix */
529                                                  INTEGER(j), csize,          /* for now, cholmod_submatrix() only accepts "generalMatrix" */
530            chx = cholmod_l_copy(chx, /* stype: */ 0, chx->xtype, &c);
531    
532        return chm_sparse_to_SEXP(cholmod_l_submatrix(chx,
533                                    (rsize < 0) ? NULL : INTEGER(i), rsize,
534                                    (csize < 0) ? NULL : INTEGER(j), csize,
535                                                  TRUE, TRUE, &c),                                                  TRUE, TRUE, &c),
536                                1, 0, Rkind, "",                                1, 0, Rkind, "",
537                                /* FIXME: drops dimnames */ R_NilValue);                                /* FIXME: drops dimnames */ R_NilValue);

Legend:
Removed from v.2516  
changed lines
  Added in v.2519

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