SCM

SCM Repository

[matrix] Annotation of /pkg/src/dsTMatrix.c
ViewVC logotype

Annotation of /pkg/src/dsTMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 557 - (view) (download) (as text)

1 : bates 557 /* Sparse symmetric matrices in triplet format */
2 :     #include "dsTMatrix.h"
3 :    
4 :     SEXP dsTMatrix_validate(SEXP x)
5 :     {
6 :     SEXP xiP = GET_SLOT(x, Matrix_iSym),
7 :     xjP = GET_SLOT(x, Matrix_jSym),
8 :     xxP = GET_SLOT(x, Matrix_xSym);
9 :     int *dims = INTEGER(GET_SLOT(x, Matrix_DimSym));
10 :    
11 :     if (dims[0] != dims[1])
12 :     return mkString("dsTMatrix must have ncol == nrow");
13 :     if (length(xiP) != length(xjP) || length(xjP) != length(xxP))
14 :     return mkString("slots i, j and x must have the same length");
15 :     return ScalarLogical(1);
16 :     }
17 :    
18 :     SEXP dsTMatrix_as_dsyMatrix(SEXP x)
19 :     {
20 :     SEXP val = PROTECT(NEW_OBJECT(MAKE_CLASS("dsyMatrix"))),
21 :     DimP = GET_SLOT(x, Matrix_DimSym),
22 :     xiP = GET_SLOT(x, Matrix_iSym);
23 :     int k, n = INTEGER(DimP)[1], nnz = length(xiP);
24 :     int *xi = INTEGER(xiP), *xj = INTEGER(GET_SLOT(x, Matrix_jSym)),
25 :     sz = n * n;
26 :     double *tx = REAL(ALLOC_SLOT(val, Matrix_xSym, REALSXP, sz)),
27 :     *xx = REAL(GET_SLOT(x, Matrix_xSym));
28 :    
29 :     SET_SLOT(val, Matrix_DimSym, duplicate(DimP));
30 :     SET_SLOT(val, Matrix_uploSym, duplicate(GET_SLOT(x, Matrix_uploSym)));
31 :     AZERO(tx, sz);
32 :     for (k = 0; k < nnz; k++) tx[xi[k] + xj[k] * n] = xx[k];
33 :     UNPROTECT(1);
34 :     return val;
35 :     }

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge