The R Project SVN R-packages

Rev

Rev 4529 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4529 Rev 4549
Line 3... Line 3...
3
#include "dgCMatrix.h"
3
#include "dgCMatrix.h"
4
/* validate: -> xCMatrix_validate() in ./dgCMatrix.c */
4
/* validate: -> xCMatrix_validate() in ./dgCMatrix.c */
5
 
5
 
6
SEXP lcsc_to_matrix(SEXP x)
6
SEXP lcsc_to_matrix(SEXP x)
7
{
7
{
8
    SEXP ans, pslot = GET_SLOT(x, Matrix_pSym);
8
    SEXP ans, pslot = GET_SLOT(x, Matrix_pSym),
-
 
9
	dn = GET_SLOT(x, Matrix_DimNamesSym);
9
    int j, ncol = length(pslot) - 1,
10
    int j, ncol = length(pslot) - 1,
10
	nrow = INTEGER(GET_SLOT(x, Matrix_DimSym))[0],
11
	nrow = INTEGER(GET_SLOT(x, Matrix_DimSym))[0],
11
	*xp = INTEGER(pslot),
12
	*xp = INTEGER(pslot),
12
	*xi = INTEGER(GET_SLOT(x, Matrix_iSym));
13
	*xi = INTEGER(GET_SLOT(x, Matrix_iSym));
13
    int *xx = LOGICAL(GET_SLOT(x, Matrix_xSym)), *ax;
14
    int *xx = LOGICAL(GET_SLOT(x, Matrix_xSym)), *ax;
Line 17... Line 18...
17
    for (j = 0; j < ncol; j++) {
18
    for (j = 0; j < ncol; j++) {
18
	int ind;
19
	int ind;
19
	for (ind = xp[j]; ind < xp[j+1]; ind++)
20
	for (ind = xp[j]; ind < xp[j+1]; ind++)
20
	    ax[j * nrow + xi[ind]] = xx[ind];
21
	    ax[j * nrow + xi[ind]] = xx[ind];
21
    }
22
    }
-
 
23
    if (!(isNull(VECTOR_ELT(dn,0)) && isNull(VECTOR_ELT(dn,1))))
-
 
24
	setAttrib(ans, R_DimNamesSymbol, duplicate(dn));
22
    UNPROTECT(1);
25
    UNPROTECT(1);
23
    return ans;
26
    return ans;
24
}
27
}
25
 
28
 
26
/* as above,  '1' instead of 'x' slot: */
29
/* as above,  '1' instead of 'x' slot: */
27
SEXP ncsc_to_matrix(SEXP x)
30
SEXP ncsc_to_matrix(SEXP x)
28
{
31
{
29
    SEXP ans, pslot = GET_SLOT(x, Matrix_pSym);
32
    SEXP ans, pslot = GET_SLOT(x, Matrix_pSym),
-
 
33
	dn = GET_SLOT(x, Matrix_DimNamesSym);
30
    int j, ncol = length(pslot) - 1,
34
    int j, ncol = length(pslot) - 1,
31
	nrow = INTEGER(GET_SLOT(x, Matrix_DimSym))[0],
35
	nrow = INTEGER(GET_SLOT(x, Matrix_DimSym))[0],
32
	*xp = INTEGER(pslot),
36
	*xp = INTEGER(pslot),
33
	*xi = INTEGER(GET_SLOT(x, Matrix_iSym));
37
	*xi = INTEGER(GET_SLOT(x, Matrix_iSym));
34
    int *ax;
38
    int *ax;
Line 38... Line 42...
38
    for (j = 0; j < ncol; j++) {
42
    for (j = 0; j < ncol; j++) {
39
	int ind;
43
	int ind;
40
	for (ind = xp[j]; ind < xp[j+1]; ind++)
44
	for (ind = xp[j]; ind < xp[j+1]; ind++)
41
	    ax[j * nrow + xi[ind]] = 1;
45
	    ax[j * nrow + xi[ind]] = 1;
42
    }
46
    }
-
 
47
    if (!(isNull(VECTOR_ELT(dn,0)) && isNull(VECTOR_ELT(dn,1))))
-
 
48
	setAttrib(ans, R_DimNamesSymbol, duplicate(dn));
43
    UNPROTECT(1);
49
    UNPROTECT(1);
44
    return ans;
50
    return ans;
45
}
51
}
46
 
52
 
47
#ifdef _NEED_logical_to_csc_FIRST_
53
#ifdef _NEED_logical_to_csc_FIRST_