SCM

SCM Repository

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

Annotation of /pkg/src/lgTMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : bates 732 /* Logical, sparse matrices in triplet form */
2 : bates 692 #include "lgTMatrix.h"
3 :    
4 :     SEXP lgTMatrix_validate(SEXP x)
5 :     {
6 :     SEXP
7 :     islot = GET_SLOT(x, Matrix_iSym),
8 :     jslot = GET_SLOT(x, Matrix_jSym),
9 :     dimslot = GET_SLOT(x, Matrix_DimSym);
10 :     int j,
11 :     *dims = INTEGER(dimslot),
12 :     ncol, nrow, nnz = length(islot),
13 :     *xj = INTEGER(jslot),
14 :     *xi = INTEGER(islot);
15 :    
16 :     if (length(jslot) != nnz)
17 :     return mkString(_("lengths of slots i and j must match"));
18 :     if (length(dimslot) != 2)
19 :     return mkString(_("slot Dim must have length 2"));
20 :     nrow = dims[0]; ncol = dims[1];
21 :     for (j = 0; j < nnz; j++) {
22 :     if (xi[j] < 0 || xi[j] >= nrow)
23 :     return mkString(_("all row indices must be between 0 and nrow-1"));
24 :     if (xj[j] < 0 || xj[j] >= ncol)
25 :     return mkString(_("all column indices must be between 0 and ncol-1"));
26 :     }
27 :     return ScalarLogical(1);
28 :     }
29 : bates 732
30 :     SEXP lgTMatrix_as_lgCMatrix(SEXP x)
31 :     {
32 :     SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("lgCMatrix"))),
33 :     xDim = GET_SLOT(x, Matrix_DimSym),
34 :     xiP = GET_SLOT(x, Matrix_iSym);
35 :     int m = INTEGER(xDim)[0], n = INTEGER(xDim)[1], nz = length(xiP);
36 :    
37 :     SET_SLOT(ans, Matrix_DimSym, duplicate(xDim));
38 :     SET_SLOT(ans, Matrix_DimNamesSym,
39 :     duplicate(GET_SLOT(x, Matrix_DimNamesSym)));
40 :     triplet_to_col(m, n, nz, INTEGER(xiP),
41 :     INTEGER(GET_SLOT(x, Matrix_jSym)), (double *) NULL,
42 :     INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, n + 1)),
43 :     INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP, nz)),
44 :     (double *) NULL);
45 :     UNPROTECT(1);
46 :     return ans;
47 :     }

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