SCM

SCM Repository

[matrix] Diff of /branches/Matrix-mer2/src/dgCMatrix.c
ViewVC logotype

Diff of /branches/Matrix-mer2/src/dgCMatrix.c

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

revision 492, Thu Feb 3 14:24:03 2005 UTC revision 679, Wed Mar 30 14:42:36 2005 UTC
# Line 14  Line 14 
14    
15      nrow = dims[0];      nrow = dims[0];
16      if (length(islot) != length(xslot))      if (length(islot) != length(xslot))
17          return ScalarString(mkChar("lengths of slots i and x must match"));          return mkString(_("lengths of slots i and x must match"));
18      if (length(pslot) <= 0)      if (length(pslot) <= 0)
19          return ScalarString(mkChar("slot p must have length > 0"));          return mkString(_("slot p must have length > 0"));
20      if (xp[0] != 0)      if (xp[0] != 0)
21          return ScalarString(mkChar("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])
23          return ScalarString(          return mkString(_("last element of slot p must match length of slots i and x"));
             mkChar(  
                 "last element of slot p must match length of slots i and x"));  
24      for (j = 0; j < ncol; j++) {      for (j = 0; j < ncol; j++) {
25          if (xp[j] > xp[j+1])          if (xp[j] > xp[j+1])
26              return ScalarString(mkChar("slot p must be non-decreasing"));              return mkString(_("slot p must be non-decreasing"));
27      }      }
28      for (j = 0; j < length(islot); j++) {      for (j = 0; j < length(islot); j++) {
29          if (xi[j] < 0 || xi[j] >= nrow)          if (xi[j] < 0 || xi[j] >= nrow)
30              return ScalarString(              return mkString(_("all row indices must be between 0 and nrow-1"));
                 mkChar("all row indices must be between 0 and nrow-1"));  
31      }      }
32      if (csc_unsorted_columns(ncol, xp, xi)) {      if (csc_unsorted_columns(ncol, xp, xi)) {
33          csc_sort_columns(ncol, xp, xi, REAL(xslot));          csc_sort_columns(ncol, xp, xi, REAL(xslot));
# Line 152  Line 149 
149      triplet_to_col(nrow, nrow, ntrip, iVal, jVal, xVal,      triplet_to_col(nrow, nrow, ntrip, iVal, jVal, xVal,
150                     ansp, itmp, xtmp);                     ansp, itmp, xtmp);
151      nnz = ansp[nrow];      nnz = ansp[nrow];
152      SET_SLOT(ans, Matrix_uploSym, ScalarString(mkChar("L")));      SET_SLOT(ans, Matrix_uploSym, mkString("L"));
153      SET_SLOT(ans, Matrix_iSym, allocVector(INTSXP, nnz));      SET_SLOT(ans, Matrix_iSym, allocVector(INTSXP, nnz));
154      SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, nnz));      SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, nnz));
155      Memcpy(INTEGER(GET_SLOT(ans, Matrix_iSym)), itmp, nnz);      Memcpy(INTEGER(GET_SLOT(ans, Matrix_iSym)), itmp, nnz);
# Line 175  Line 172 
172          *ydims;          *ydims;
173      double *xx = REAL(GET_SLOT(x, Matrix_xSym));      double *xx = REAL(GET_SLOT(x, Matrix_xSym));
174    
175      if (!(isMatrix(y) && isReal(y))) error("y must be a numeric matrix");      if (!(isMatrix(y) && isReal(y))) error(_("y must be a numeric matrix"));
176      ydims = INTEGER(getAttrib(y, R_DimSymbol));      ydims = INTEGER(getAttrib(y, R_DimSymbol));
177      if (xnrow != ydims[0]) error("x and y must have the same number of rows");      if (xnrow != ydims[0]) error(_("x and y must have the same number of rows"));
178      ans = PROTECT(allocMatrix(REALSXP, xncol, ydims[1]));      ans = PROTECT(allocMatrix(REALSXP, xncol, ydims[1]));
179      for (j = 0; j < ydims[1]; j++) {      for (j = 0; j < ydims[1]; j++) {
180          int i; double *ypt = REAL(y) + j * ydims[0];          int i; double *ypt = REAL(y) + j * ydims[0];
# Line 193  Line 190 
190      return ans;      return ans;
191  }  }
192    
193  SEXP csc_to_dgTMatrix(SEXP x)  SEXP compressed_to_dgTMatrix(SEXP x, SEXP colP)
194  {  {
195      SEXP      int col = asLogical(colP);
196          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgTMatrix"))),      SEXP indSym = col ? Matrix_iSym : Matrix_jSym;
197          dimslot = GET_SLOT(x, Matrix_DimSym),      SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgTMatrix"))),
198          islot = GET_SLOT(x, Matrix_iSym),          indP = GET_SLOT(x, indSym),
199          pslot = GET_SLOT(x, Matrix_pSym);          pP = GET_SLOT(x, Matrix_pSym);
200      int *dims = INTEGER(dimslot), j, jj,      int npt = length(pP) - 1;
         *xp = INTEGER(pslot), *yj;  
201    
202      SET_SLOT(ans, Matrix_iSym, duplicate(islot));      SET_SLOT(ans, Matrix_DimSym, duplicate(GET_SLOT(x, Matrix_DimSym)));
     SET_SLOT(ans, Matrix_DimSym, duplicate(dimslot));  
203      SET_SLOT(ans, Matrix_xSym, duplicate(GET_SLOT(x, Matrix_xSym)));      SET_SLOT(ans, Matrix_xSym, duplicate(GET_SLOT(x, Matrix_xSym)));
204      SET_SLOT(ans, Matrix_jSym, allocVector(INTSXP, length(islot)));      SET_SLOT(ans, indSym, duplicate(indP));
205      yj = INTEGER(GET_SLOT(ans, Matrix_jSym));      expand_cmprPt(npt, INTEGER(pP),
206      jj = 0;                    INTEGER(ALLOC_SLOT(ans, col ? Matrix_jSym : Matrix_iSym,
207      for (j = 0; j < dims[1]; j++) {                                       INTSXP, length(indP))));
         while (jj < xp[j + 1]) {  
             yj[jj] = j;  
             jj++;  
         }  
     }  
208      UNPROTECT(1);      UNPROTECT(1);
209      return ans;      return ans;
210  }  }
# Line 275  Line 265 
265      double *vx;      double *vx;
266    
267      if (!(isMatrix(A) && isReal(A)))      if (!(isMatrix(A) && isReal(A)))
268          error("A must be a numeric matrix");          error(_("A must be a numeric matrix"));
269      nrow = adims[0]; ncol = adims[1];      nrow = adims[0]; ncol = adims[1];
270      SET_SLOT(val, Matrix_factorSym, allocVector(VECSXP, 0));      SET_SLOT(val, Matrix_factorSym, allocVector(VECSXP, 0));
271      SET_SLOT(val, Matrix_DimSym, allocVector(INTSXP, 2));      SET_SLOT(val, Matrix_DimSym, allocVector(INTSXP, 2));
# Line 357  Line 347 
347      int *adims, *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym)),      int *adims, *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym)),
348          nnz = length(islot);          nnz = length(islot);
349    
350      SET_SLOT(ans, Matrix_DimSym, allocVector(INTSXP, 2));      adims = INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2));
     adims = INTEGER(GET_SLOT(ans, Matrix_DimSym));  
351      adims[0] = xdims[1]; adims[1] = xdims[0];      adims[0] = xdims[1]; adims[1] = xdims[0];
352      SET_SLOT(ans, Matrix_factorSym, allocVector(VECSXP, 0));      csc_compTr(xdims[0], xdims[1], nnz,
353      SET_SLOT(ans, Matrix_pSym, allocVector(INTSXP, xdims[0] + 1));                 INTEGER(GET_SLOT(x, Matrix_pSym)), INTEGER(islot),
     SET_SLOT(ans, Matrix_iSym, allocVector(INTSXP, nnz));  
     SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, nnz));  
     csc_components_transpose(xdims[0], xdims[1], nnz,  
                              INTEGER(GET_SLOT(x, Matrix_pSym)),  
                              INTEGER(islot),  
354                               REAL(GET_SLOT(x, Matrix_xSym)),                               REAL(GET_SLOT(x, Matrix_xSym)),
355                               INTEGER(GET_SLOT(ans, Matrix_pSym)),                 INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, xdims[0] + 1)),
356                               INTEGER(GET_SLOT(ans, Matrix_iSym)),                 INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP, nnz)),
357                               REAL(GET_SLOT(ans, Matrix_xSym)));                 REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, nnz)));
358      UNPROTECT(1);      UNPROTECT(1);
359      return ans;      return ans;
360  }  }
# Line 386  Line 370 
370      SEXP val;      SEXP val;
371    
372      if (bdim[0] != r)      if (bdim[0] != r)
373          error("Matrices of sizes (%d,%d) and (%d,%d) cannot be multiplied",          error(_("Matrices of sizes (%d,%d) and (%d,%d) cannot be multiplied"),
374                m, r, bdim[0], n);                m, r, bdim[0], n);
375      val = PROTECT(allocMatrix(REALSXP, m, n));      val = PROTECT(allocMatrix(REALSXP, m, n));
376      for (j = 0; j < n; j++) {   /* across columns of b */      for (j = 0; j < n; j++) {   /* across columns of b */
# Line 416  Line 400 
400      SET_SLOT(val, Matrix_DimSym, duplicate(tmp));      SET_SLOT(val, Matrix_DimSym, duplicate(tmp));
401      ncol = INTEGER(tmp)[1];      ncol = INTEGER(tmp)[1];
402      if (!(isInteger(perm) && length(perm) == ncol))      if (!(isInteger(perm) && length(perm) == ncol))
403          error("perm must be an integer vector of length %d",          error(_("perm must be an integer vector of length %d"),
404                ncol);                ncol);
405      prm = INTEGER(perm);      prm = INTEGER(perm);
406      if (!R_ldl_valid_perm(ncol, prm))      if (!R_ldl_valid_perm(ncol, prm))
407          error("perm is not a valid 0-based permutation");          error(_("perm is not a valid 0-based permutation"));
408      iperm = Calloc(ncol, int);      iperm = Calloc(ncol, int);
409      for (j = 0; j < ncol; j++) iperm[prm[j]] = j;      for (j = 0; j < ncol; j++) iperm[prm[j]] = j;
410      tmp = GET_SLOT(x, Matrix_pSym);      tmp = GET_SLOT(x, Matrix_pSym);

Legend:
Removed from v.492  
changed lines
  Added in v.679

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