SCM

SCM Repository

[matrix] Diff of /pkg/Matrix/src/Csparse.c
ViewVC logotype

Diff of /pkg/Matrix/src/Csparse.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1657, Wed Nov 1 16:29:53 2006 UTC revision 1921, Sat Jun 23 18:08:17 2007 UTC
# Line 7  Line 7 
7      /* NB: we do *NOT* check a potential 'x' slot here, at all */      /* NB: we do *NOT* check a potential 'x' slot here, at all */
8      SEXP pslot = GET_SLOT(x, Matrix_pSym),      SEXP pslot = GET_SLOT(x, Matrix_pSym),
9          islot = GET_SLOT(x, Matrix_iSym);          islot = GET_SLOT(x, Matrix_iSym);
10      int j, k, ncol, nrow, sorted,      Rboolean sorted, strictly;
11        int j, k,
12          *dims = INTEGER(GET_SLOT(x, Matrix_DimSym)),          *dims = INTEGER(GET_SLOT(x, Matrix_DimSym)),
13            nrow = dims[0],
14            ncol = dims[1],
15          *xp = INTEGER(pslot),          *xp = INTEGER(pslot),
16          *xi = INTEGER(islot);          *xi = INTEGER(islot);
17    
     nrow = dims[0];  
     ncol = dims[1];  
18      if (length(pslot) != dims[1] + 1)      if (length(pslot) != dims[1] + 1)
19          return mkString(_("slot p must have length = ncol(.) + 1"));          return mkString(_("slot p must have length = ncol(.) + 1"));
20      if (xp[0] != 0)      if (xp[0] != 0)
21          return mkString(_("first element of slot p must be zero"));          return mkString(_("first element of slot p must be zero"));
22      if (length(islot) != xp[ncol])      if (length(islot) < xp[ncol]) /* allow larger slots from over-allocation!*/
23          return          return
24              mkString(_("last element of slot p must match length of slots i and x"));              mkString(_("last element of slot p must match length of slots i and x"));
25      for (j = 0; j < length(islot); j++) {      for (j = 0; j < length(islot); j++) {
26          if (xi[j] < 0 || xi[j] >= nrow)          if (xi[j] < 0 || xi[j] >= nrow)
27              return mkString(_("all row indices must be between 0 and nrow-1"));              return mkString(_("all row indices must be between 0 and nrow-1"));
28      }      }
29      sorted = TRUE;      sorted = TRUE; strictly = TRUE;
30      for (j = 0; j < ncol; j++) {      for (j = 0; j < ncol; j++) {
31          if (xp[j] > xp[j+1])          if (xp[j] > xp[j+1])
32              return mkString(_("slot p must be non-decreasing"));              return mkString(_("slot p must be non-decreasing"));
33          for (k = xp[j] + 1; k < xp[j + 1]; k++)          if(sorted)
34              if (xi[k] < xi[k - 1]) sorted = FALSE;              for (k = xp[j] + 1; k < xp[j + 1]; k++) {
35                    if (xi[k] < xi[k - 1])
36                        sorted = FALSE;
37                    else if (xi[k] == xi[k - 1])
38                        strictly = FALSE;
39                }
40      }      }
41      if (!sorted) {      if (!sorted) {
42          cholmod_sparse *chx = as_cholmod_sparse(x);          cholmod_sparse *chx = as_cholmod_sparse(x);
43          cholmod_sort(chx, &c);          cholmod_sort(chx, &c);
44          Free(chx);          Free(chx);
45            /* Now re-check that row indices are *strictly* increasing
46             * (and not just increasing) within each column : */
47            for (j = 0; j < ncol; j++) {
48                for (k = xp[j] + 1; k < xp[j + 1]; k++)
49                    if (xi[k] == xi[k - 1])
50                        return mkString(_("slot i is not *strictly* increasing inside a column (even after cholmod_sort)"));
51            }
52    
53        } else if(!strictly) {  /* sorted, but not strictly */
54            return mkString(_("slot i is not *strictly* increasing inside a column"));
55      }      }
56      return ScalarLogical(1);      return ScalarLogical(1);
57  }  }
58    
59    /* Called from ../R/Csparse.R : */
60    /* Can only return [dln]geMatrix (no symm/triang);
61     * FIXME: replace by non-CHOLMOD code ! */
62  SEXP Csparse_to_dense(SEXP x)  SEXP Csparse_to_dense(SEXP x)
63  {  {
64      cholmod_sparse *chxs = as_cholmod_sparse(x);      cholmod_sparse *chxs = as_cholmod_sparse(x);
65        /* This loses the symmetry property, since cholmod_dense has none,
66         * BUT, much worse (FIXME!), it also transforms CHOLMOD_PATTERN ("n") matrices
67         * to numeric (CHOLMOD_REAL) ones : */
68      cholmod_dense *chxd = cholmod_sparse_to_dense(chxs, &c);      cholmod_dense *chxd = cholmod_sparse_to_dense(chxs, &c);
69        int Rkind = (chxs->xtype == CHOLMOD_PATTERN)? -1 : Real_kind(x);
70    
71      Free(chxs);      Free(chxs);
72      return chm_dense_to_SEXP(chxd, 1, Real_kind(x));      return chm_dense_to_SEXP(chxd, 1, Rkind, GET_SLOT(x, Matrix_DimNamesSym));
73  }  }
74    
75  SEXP Csparse_to_nz_pattern(SEXP x, SEXP tri)  SEXP Csparse_to_nz_pattern(SEXP x, SEXP tri)
# Line 54  Line 77 
77      cholmod_sparse *chxs = as_cholmod_sparse(x);      cholmod_sparse *chxs = as_cholmod_sparse(x);
78      cholmod_sparse      cholmod_sparse
79          *chxcp = cholmod_copy(chxs, chxs->stype, CHOLMOD_PATTERN, &c);          *chxcp = cholmod_copy(chxs, chxs->stype, CHOLMOD_PATTERN, &c);
80      int uploT = 0; char *diag = "";      int tr = asLogical(tri);
81    
82      Free(chxs);      Free(chxs);
83      if (asLogical(tri)) {       /* triangular sparse matrices */      return chm_sparse_to_SEXP(chxcp, 1,
84          uploT = (strcmp(CHAR(asChar(GET_SLOT(x, Matrix_uploSym))), "U")) ?                                tr ? ((*uplo_P(x) == 'U') ? 1 : -1) : 0,
85              -1 : 1;                                0, tr ? diag_P(x) : "",
         diag = CHAR(asChar(GET_SLOT(x, Matrix_diagSym)));  
     }  
     return chm_sparse_to_SEXP(chxcp, 1, uploT, 0, diag,  
86                                GET_SLOT(x, Matrix_DimNamesSym));                                GET_SLOT(x, Matrix_DimNamesSym));
87  }  }
88    
# Line 80  Line 100 
100  {  {
101      cholmod_sparse *chxs = as_cholmod_sparse(x);      cholmod_sparse *chxs = as_cholmod_sparse(x);
102      cholmod_triplet *chxt = cholmod_sparse_to_triplet(chxs, &c);      cholmod_triplet *chxt = cholmod_sparse_to_triplet(chxs, &c);
103      int uploT = 0;      int tr = asLogical(tri);
104      char *diag = "";      int Rkind = (chxs->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
     int Rkind = (chxs->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;  
105    
106      Free(chxs);      Free(chxs);
107      if (asLogical(tri)) {       /* triangular sparse matrices */      return chm_triplet_to_SEXP(chxt, 1,
108          uploT = (*uplo_P(x) == 'U') ? -1 : 1;                                 tr ? ((*uplo_P(x) == 'U') ? 1 : -1) : 0,
109          diag = diag_P(x);                                 Rkind, tr ? diag_P(x) : "",
     }  
     return chm_triplet_to_SEXP(chxt, 1, uploT, Rkind, diag,  
110                                 GET_SLOT(x, Matrix_DimNamesSym));                                 GET_SLOT(x, Matrix_DimNamesSym));
111  }  }
112    
# Line 97  Line 114 
114  SEXP Csparse_symmetric_to_general(SEXP x)  SEXP Csparse_symmetric_to_general(SEXP x)
115  {  {
116      cholmod_sparse *chx = as_cholmod_sparse(x), *chgx;      cholmod_sparse *chx = as_cholmod_sparse(x), *chgx;
117      int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
118    
119      if (!(chx->stype))      if (!(chx->stype))
120          error(_("Nonsymmetric matrix in Csparse_symmetric_to_general"));          error(_("Nonsymmetric matrix in Csparse_symmetric_to_general"));
# Line 111  Line 128 
128  SEXP Csparse_general_to_symmetric(SEXP x, SEXP uplo)  SEXP Csparse_general_to_symmetric(SEXP x, SEXP uplo)
129  {  {
130      cholmod_sparse *chx = as_cholmod_sparse(x), *chgx;      cholmod_sparse *chx = as_cholmod_sparse(x), *chgx;
131      int uploT = (*CHAR(asChar(uplo)) == 'U') ? -1 : 1;      int uploT = (*CHAR(asChar(uplo)) == 'U') ? 1 : -1;
132      int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
133    
134      chgx = cholmod_copy(chx, /* stype: */ uploT, chx->xtype, &c);      chgx = cholmod_copy(chx, /* stype: */ uploT, chx->xtype, &c);
135      /* xtype: pattern, "real", complex or .. */      /* xtype: pattern, "real", complex or .. */
# Line 123  Line 140 
140    
141  SEXP Csparse_transpose(SEXP x, SEXP tri)  SEXP Csparse_transpose(SEXP x, SEXP tri)
142  {  {
143        /* TODO: lgCMatrix & igC* currently go via double prec. cholmod -
144         *       since cholmod (& cs) lacks sparse 'int' matrices */
145      cholmod_sparse *chx = as_cholmod_sparse(x);      cholmod_sparse *chx = as_cholmod_sparse(x);
146      int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
147      cholmod_sparse *chxt = cholmod_transpose(chx, (int) chx->xtype, &c);      cholmod_sparse *chxt = cholmod_transpose(chx, (int) chx->xtype, &c);
148      SEXP dn = PROTECT(duplicate(GET_SLOT(x, Matrix_DimNamesSym))), tmp;      SEXP dn = PROTECT(duplicate(GET_SLOT(x, Matrix_DimNamesSym))), tmp;
149      int uploT = 0; char *diag = "";      int tr = asLogical(tri);
150    
151      Free(chx);      Free(chx);
152      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */
153      SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));      SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));
154      SET_VECTOR_ELT(dn, 1, tmp);      SET_VECTOR_ELT(dn, 1, tmp);
155      UNPROTECT(1);      UNPROTECT(1);
156      if (asLogical(tri)) {       /* triangular sparse matrices */      return chm_sparse_to_SEXP(chxt, 1, /* SWAP 'uplo' for triangular */
157          uploT = (*uplo_P(x) == 'U') ? -1 : 1;                                tr ? ((*uplo_P(x) == 'U') ? -1 : 1) : 0,
158          diag = diag_P(x);                                Rkind, tr ? diag_P(x) : "", dn);
     }  
     return chm_sparse_to_SEXP(chxt, 1, uploT, Rkind, diag, dn);  
159  }  }
160    
161  SEXP Csparse_Csparse_prod(SEXP a, SEXP b)  SEXP Csparse_Csparse_prod(SEXP a, SEXP b)
162  {  {
163      cholmod_sparse *cha = as_cholmod_sparse(a),      cholmod_sparse
164            *cha = as_cholmod_sparse(a),
165          *chb = as_cholmod_sparse(b);          *chb = as_cholmod_sparse(b);
166      cholmod_sparse *chc = cholmod_ssmult(cha, chb, 0, cha->xtype, 1, &c);      cholmod_sparse *chc = cholmod_ssmult(cha, chb, 0, cha->xtype, 1, &c);
167      SEXP dn = allocVector(VECSXP, 2);      SEXP dn = allocVector(VECSXP, 2);
# Line 156  Line 174 
174      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);
175  }  }
176    
177  SEXP Csparse_Csparse_crossprod(SEXP a, SEXP b)  SEXP Csparse_Csparse_crossprod(SEXP a, SEXP b, SEXP trans)
178  {  {
179      cholmod_sparse *cha = as_cholmod_sparse(a),      int tr = asLogical(trans);
180        cholmod_sparse
181            *cha = as_cholmod_sparse(a),
182          *chb = as_cholmod_sparse(b);          *chb = as_cholmod_sparse(b);
183      cholmod_sparse *chta = cholmod_transpose(cha, 1, &c);      cholmod_sparse *chTr, *chc;
     cholmod_sparse *chc = cholmod_ssmult(chta, chb, 0, cha->xtype, 1, &c);  
184      SEXP dn = allocVector(VECSXP, 2);      SEXP dn = allocVector(VECSXP, 2);
185    
186      Free(cha); Free(chb); cholmod_free_sparse(&chta, &c);  /*     cholmod_sparse *chTr = cholmod_transpose(cha, 1, &c); */
187    /*     cholmod_sparse *chc = cholmod_ssmult(chTr, chb, 0, cha->xtype, 1, &c); */
188    
189        if (tr)
190            chTr = cholmod_transpose(chb, chb->xtype, &c);
191        else
192            chTr = cholmod_transpose(cha, cha->xtype, &c);
193        chc = cholmod_ssmult((tr) ? cha : chTr, (tr) ? chTr : chb,
194                             0, cha->xtype, 1, &c);
195    
196        Free(cha); Free(chb); cholmod_free_sparse(&chTr, &c);
197    
198      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
199                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 1)));                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), (tr) ? 0 : 1)));
200      SET_VECTOR_ELT(dn, 1,      SET_VECTOR_ELT(dn, 1,
201                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), (tr) ? 0 : 1)));
202      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);
203  }  }
204    
205  SEXP Csparse_dense_prod(SEXP a, SEXP b)  SEXP Csparse_dense_prod(SEXP a, SEXP b)
206  {  {
207      cholmod_sparse *cha = as_cholmod_sparse(a);      cholmod_sparse *cha = as_cholmod_sparse(a);
208      cholmod_dense *chb = as_cholmod_dense(PROTECT(mMatrix_as_dgeMatrix(b)));      SEXP b_M = PROTECT(mMatrix_as_dgeMatrix(b));
209        cholmod_dense *chb = as_cholmod_dense(b_M);
210      cholmod_dense *chc =      cholmod_dense *chc =
211          cholmod_allocate_dense(cha->nrow, chb->ncol, cha->nrow, chb->xtype, &c);          cholmod_allocate_dense(cha->nrow, chb->ncol, cha->nrow, chb->xtype, &c);
212        SEXP dn = allocVector(VECSXP, 2);
213      double alpha[] = {1,0}, beta[] = {0,0};      double alpha[] = {1,0}, beta[] = {0,0};
214    
215      cholmod_sdmult(cha, 0, alpha, beta, chb, chc, &c);      cholmod_sdmult(cha, 0, alpha, beta, chb, chc, &c);
216      Free(cha); Free(chb);      Free(cha); Free(chb);
217      UNPROTECT(1);      UNPROTECT(1);
218      return chm_dense_to_SEXP(chc, 1, 0);      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
219                       duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 0)));
220        SET_VECTOR_ELT(dn, 1,
221                       duplicate(VECTOR_ELT(GET_SLOT(b_M, Matrix_DimNamesSym), 1)));
222        return chm_dense_to_SEXP(chc, 1, 0, dn);
223  }  }
224    
225  SEXP Csparse_dense_crossprod(SEXP a, SEXP b)  SEXP Csparse_dense_crossprod(SEXP a, SEXP b)
226  {  {
227      cholmod_sparse *cha = as_cholmod_sparse(a);      cholmod_sparse *cha = as_cholmod_sparse(a);
228      cholmod_dense *chb = as_cholmod_dense(PROTECT(mMatrix_as_dgeMatrix(b)));      SEXP b_M = PROTECT(mMatrix_as_dgeMatrix(b));
229        cholmod_dense *chb = as_cholmod_dense(b_M);
230      cholmod_dense *chc =      cholmod_dense *chc =
231          cholmod_allocate_dense(cha->ncol, chb->ncol, cha->ncol, chb->xtype, &c);          cholmod_allocate_dense(cha->ncol, chb->ncol, cha->ncol, chb->xtype, &c);
232        SEXP dn = allocVector(VECSXP, 2);
233      double alpha[] = {1,0}, beta[] = {0,0};      double alpha[] = {1,0}, beta[] = {0,0};
234    
235      cholmod_sdmult(cha, 1, alpha, beta, chb, chc, &c);      cholmod_sdmult(cha, 1, alpha, beta, chb, chc, &c);
236      Free(cha); Free(chb);      Free(cha); Free(chb);
237      UNPROTECT(1);      UNPROTECT(1);
238      return chm_dense_to_SEXP(chc, 1, 0);      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
239                       duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 1)));
240        SET_VECTOR_ELT(dn, 1,
241                       duplicate(VECTOR_ELT(GET_SLOT(b_M, Matrix_DimNamesSym), 1)));
242        return chm_dense_to_SEXP(chc, 1, 0, dn);
243  }  }
244    
245    /* Computes   x'x  or  x x'  -- see Csparse_Csparse_crossprod above for  x'y and x y' */
246  SEXP Csparse_crossprod(SEXP x, SEXP trans, SEXP triplet)  SEXP Csparse_crossprod(SEXP x, SEXP trans, SEXP triplet)
247  {  {
248      int trip = asLogical(triplet),      int trip = asLogical(triplet),
# Line 228  Line 271 
271                                  /* create dimnames */                                  /* create dimnames */
272      SET_VECTOR_ELT(dn, 0,      SET_VECTOR_ELT(dn, 0,
273                     duplicate(VECTOR_ELT(GET_SLOT(x, Matrix_DimNamesSym),                     duplicate(VECTOR_ELT(GET_SLOT(x, Matrix_DimNamesSym),
274                                          (tr) ? 1 : 0)));                                          (tr) ? 0 : 1)));
275      SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));      SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));
276      UNPROTECT(1);      UNPROTECT(1);
277      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);
# Line 239  Line 282 
282      cholmod_sparse *chx = as_cholmod_sparse(x),      cholmod_sparse *chx = as_cholmod_sparse(x),
283          *ans = cholmod_copy(chx, chx->stype, chx->xtype, &c);          *ans = cholmod_copy(chx, chx->stype, chx->xtype, &c);
284      double dtol = asReal(tol);      double dtol = asReal(tol);
285      int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
286    
287      if(!cholmod_drop(dtol, ans, &c))      if(!cholmod_drop(dtol, ans, &c))
288          error(_("cholmod_drop() failed"));          error(_("cholmod_drop() failed"));
289      Free(chx);      Free(chx);
290      /* FIXME: currently drops dimnames */      return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "",
291      return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "", R_NilValue);                                GET_SLOT(x, Matrix_DimNamesSym));
292  }  }
293    
294    
# Line 276  Line 319 
319  SEXP Csparse_band(SEXP x, SEXP k1, SEXP k2)  SEXP Csparse_band(SEXP x, SEXP k1, SEXP k2)
320  {  {
321      cholmod_sparse *chx = as_cholmod_sparse(x), *ans;      cholmod_sparse *chx = as_cholmod_sparse(x), *ans;
322      int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
323    
324      ans = cholmod_band(chx, asInteger(k1), asInteger(k2), chx->xtype, &c);      ans = cholmod_band(chx, asInteger(k1), asInteger(k2), chx->xtype, &c);
325      Free(chx);      Free(chx);
326      return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "", R_NilValue);      return chm_sparse_to_SEXP(ans, 1, 0, Rkind, "",
327                                  GET_SLOT(x, Matrix_DimNamesSym));
328  }  }
329    
330  SEXP Csparse_diagU2N(SEXP x)  SEXP Csparse_diagU2N(SEXP x)
331  {  {
332        if (*diag_P(x) != 'U') {/* "trivially fast" when there's no 'diag' slot at all */
333            return (x);
334        }
335        else {
336      cholmod_sparse *chx = as_cholmod_sparse(x);      cholmod_sparse *chx = as_cholmod_sparse(x);
337      cholmod_sparse *eye = cholmod_speye(chx->nrow, chx->ncol, chx->xtype, &c);      cholmod_sparse *eye = cholmod_speye(chx->nrow, chx->ncol, chx->xtype, &c);
338      double one[] = {1, 0};      double one[] = {1, 0};
339      cholmod_sparse *ans = cholmod_add(chx, eye, one, one, TRUE, TRUE, &c);      cholmod_sparse *ans = cholmod_add(chx, eye, one, one, TRUE, TRUE, &c);
340      int uploT = (strcmp(CHAR(asChar(GET_SLOT(x, Matrix_uploSym))), "U")) ?          int uploT = (*uplo_P(x) == 'U') ? 1 : -1;
341          -1 : 1;          int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
     int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;  
342    
343      Free(chx); cholmod_free_sparse(&eye, &c);      Free(chx); cholmod_free_sparse(&eye, &c);
344      return chm_sparse_to_SEXP(ans, 1, uploT, Rkind, "N",      return chm_sparse_to_SEXP(ans, 1, uploT, Rkind, "N",
345                                duplicate(GET_SLOT(x, Matrix_DimNamesSym)));                                    GET_SLOT(x, Matrix_DimNamesSym));
346        }
347  }  }
348    
349  SEXP Csparse_submatrix(SEXP x, SEXP i, SEXP j)  SEXP Csparse_submatrix(SEXP x, SEXP i, SEXP j)
# Line 303  Line 351 
351      cholmod_sparse *chx = as_cholmod_sparse(x);      cholmod_sparse *chx = as_cholmod_sparse(x);
352      int rsize = (isNull(i)) ? -1 : LENGTH(i),      int rsize = (isNull(i)) ? -1 : LENGTH(i),
353          csize = (isNull(j)) ? -1 : LENGTH(j);          csize = (isNull(j)) ? -1 : LENGTH(j);
354      int Rkind = (chx->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
355    
356      if (rsize >= 0 && !isInteger(i))      if (rsize >= 0 && !isInteger(i))
357          error(_("Index i must be NULL or integer"));          error(_("Index i must be NULL or integer"));
358      if (csize >= 0 && !isInteger(j))      if (csize >= 0 && !isInteger(j))
359          error(_("Index j must be NULL or integer"));          error(_("Index j must be NULL or integer"));
360    
361      return chm_sparse_to_SEXP(cholmod_submatrix(chx, INTEGER(i), rsize,      return chm_sparse_to_SEXP(cholmod_submatrix(chx, INTEGER(i), rsize,
362                                                  INTEGER(j), csize,                                                  INTEGER(j), csize,
363                                                  TRUE, TRUE, &c),                                                  TRUE, TRUE, &c),
364                                1, 0, Rkind, "", R_NilValue);                                1, 0, Rkind, "",
365                                  /* FIXME: drops dimnames */ R_NilValue);
366  }  }

Legend:
Removed from v.1657  
changed lines
  Added in v.1921

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge