SCM

SCM Repository

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

Annotation of /pkg/src/dgTMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 342 - (view) (download) (as text)
Original Path: pkg/src/triplet.c

1 : bates 10 /* Sparse matrices in triplet form */
2 :     #include "triplet.h"
3 :    
4 :     SEXP triplet_validate(SEXP x)
5 :     {
6 :     SEXP
7 :     islot = GET_SLOT(x, Matrix_iSym),
8 :     jslot = GET_SLOT(x, Matrix_jSym),
9 :     xslot = GET_SLOT(x, Matrix_xSym),
10 :     dimslot = GET_SLOT(x, Matrix_DimSym);
11 :     int j,
12 :     *dims = INTEGER(dimslot),
13 :     ncol, nrow, nnz = length(islot),
14 :     *xj = INTEGER(jslot),
15 :     *xi = INTEGER(islot);
16 :    
17 :     if (length(xslot) != nnz || length(jslot) != nnz)
18 :     return ScalarString(mkChar("lengths of slots i, j, and x must match"));
19 :     if (length(dimslot) != 2)
20 :     return ScalarString(mkChar("slot Dim must have length 2"));
21 :     nrow = dims[0]; ncol = dims[1];
22 :     for (j = 0; j < nnz; j++) {
23 :     if (xi[j] < 0 || xi[j] >= nrow)
24 :     return ScalarString(
25 :     mkChar("all row indices must be between 0 and nrow-1"));
26 :     if (xj[j] < 0 || xj[j] >= ncol)
27 :     return ScalarString(
28 :     mkChar("all column indices must be between 0 and ncol-1"));
29 :     }
30 :     return ScalarLogical(1);
31 :     }
32 : bates 70
33 :     SEXP triplet_to_geMatrix(SEXP x)
34 :     {
35 :     SEXP dd = GET_SLOT(x, Matrix_DimSym),
36 :     islot = GET_SLOT(x, Matrix_iSym),
37 :     ans = PROTECT(NEW_OBJECT(MAKE_CLASS("geMatrix")));
38 :    
39 :     int *dims = INTEGER(dd),
40 :     *xi = INTEGER(islot),
41 :     *xj = INTEGER(GET_SLOT(x, Matrix_jSym)),
42 :     i,
43 :     m = dims[0],
44 :     n = dims[1],
45 :     nnz = length(islot);
46 :     double
47 :     *vx,
48 :     *xx = REAL(GET_SLOT(x, Matrix_xSym));
49 :    
50 : bates 342 SET_SLOT(ans, Matrix_rcondSym, allocVector(REALSXP, 0));
51 :     SET_SLOT(ans, Matrix_factorization, allocVector(VECSXP, 0));
52 : bates 70 SET_SLOT(ans, Matrix_DimSym, duplicate(dd));
53 :     SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, m * n));
54 :     vx = REAL(GET_SLOT(ans, Matrix_xSym));
55 :     memset(vx, 0, sizeof(double) * m * n);
56 :     for (i = 0; i < nnz; i++) {
57 :     vx[xi[i] + xj[i] * m] += xx[i]; /* allow redundant entries in x */
58 :     }
59 :     UNPROTECT(1);
60 :     return ans;
61 :     }
62 :    

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