SCM

SCM Repository

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

Annotation of /pkg/src/lgCMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : bates 692 #include "lgCMatrix.h"
2 :    
3 : maechler 1660 #include "dgCMatrix.h"
4 : maechler 1661 /* validate: -> xCMatrix_validate() in ./dgCMatrix.c */
5 : bates 692
6 : maechler 866 SEXP lcsc_to_matrix(SEXP x)
7 :     {
8 : maechler 1945 SEXP ans, pslot = GET_SLOT(x, Matrix_pSym),
9 :     dn = GET_SLOT(x, Matrix_DimNamesSym);
10 : maechler 866 int j, ncol = length(pslot) - 1,
11 :     nrow = INTEGER(GET_SLOT(x, Matrix_DimSym))[0],
12 :     *xp = INTEGER(pslot),
13 :     *xi = INTEGER(GET_SLOT(x, Matrix_iSym));
14 : maechler 1570 int *xx = LOGICAL(GET_SLOT(x, Matrix_xSym)), *ax;
15 :    
16 :     ax = LOGICAL(ans = PROTECT(allocMatrix(LGLSXP, nrow, ncol)));
17 :     for (j = 0; j < (nrow * ncol); j++) ax[j] = 0;
18 :     for (j = 0; j < ncol; j++) {
19 :     int ind;
20 :     for (ind = xp[j]; ind < xp[j+1]; ind++)
21 :     ax[j * nrow + xi[ind]] = xx[ind];
22 :     }
23 : maechler 1945 if (!(isNull(VECTOR_ELT(dn,0)) && isNull(VECTOR_ELT(dn,1))))
24 :     setAttrib(ans, R_DimNamesSymbol, duplicate(dn));
25 : maechler 1570 UNPROTECT(1);
26 :     return ans;
27 :     }
28 :    
29 :     /* as above, '1' instead of 'x' slot: */
30 :     SEXP ncsc_to_matrix(SEXP x)
31 :     {
32 : maechler 1945 SEXP ans, pslot = GET_SLOT(x, Matrix_pSym),
33 :     dn = GET_SLOT(x, Matrix_DimNamesSym);
34 : maechler 1570 int j, ncol = length(pslot) - 1,
35 :     nrow = INTEGER(GET_SLOT(x, Matrix_DimSym))[0],
36 :     *xp = INTEGER(pslot),
37 :     *xi = INTEGER(GET_SLOT(x, Matrix_iSym));
38 : maechler 866 int *ax;
39 :    
40 :     ax = LOGICAL(ans = PROTECT(allocMatrix(LGLSXP, nrow, ncol)));
41 :     for (j = 0; j < (nrow * ncol); j++) ax[j] = 0;
42 :     for (j = 0; j < ncol; j++) {
43 :     int ind;
44 :     for (ind = xp[j]; ind < xp[j+1]; ind++)
45 :     ax[j * nrow + xi[ind]] = 1;
46 :     }
47 : maechler 1945 if (!(isNull(VECTOR_ELT(dn,0)) && isNull(VECTOR_ELT(dn,1))))
48 :     setAttrib(ans, R_DimNamesSymbol, duplicate(dn));
49 : maechler 866 UNPROTECT(1);
50 :     return ans;
51 :     }
52 :    
53 : maechler 1282 #ifdef _NEED_logical_to_csc_FIRST_
54 :     /* very parallel to matrix_to_csc() in ./dgCMatrix.c */
55 :     SEXP matrix_to_lcsc(SEXP A)
56 :     {
57 :     if (!(isMatrix(A) && isLogical(A)))
58 :     error(_("A must be a logical matrix"));
59 :     return logical_to_csc(LOGICAL(A),
60 :     INTEGER(getAttrib(A, R_DimSymbol)));
61 :     }
62 :     #endif

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