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 1660 - (view) (download) (as text)

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