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 588, Wed Mar 2 18:19:51 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 275  Line 272 
272      double *vx;      double *vx;
273    
274      if (!(isMatrix(A) && isReal(A)))      if (!(isMatrix(A) && isReal(A)))
275          error("A must be a numeric matrix");          error(_("A must be a numeric matrix"));
276      nrow = adims[0]; ncol = adims[1];      nrow = adims[0]; ncol = adims[1];
277      SET_SLOT(val, Matrix_factorSym, allocVector(VECSXP, 0));      SET_SLOT(val, Matrix_factorSym, allocVector(VECSXP, 0));
278      SET_SLOT(val, Matrix_DimSym, allocVector(INTSXP, 2));      SET_SLOT(val, Matrix_DimSym, allocVector(INTSXP, 2));
# Line 357  Line 354 
354      int *adims, *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym)),      int *adims, *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym)),
355          nnz = length(islot);          nnz = length(islot);
356    
357      SET_SLOT(ans, Matrix_DimSym, allocVector(INTSXP, 2));      adims = INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2));
     adims = INTEGER(GET_SLOT(ans, Matrix_DimSym));  
358      adims[0] = xdims[1]; adims[1] = xdims[0];      adims[0] = xdims[1]; adims[1] = xdims[0];
359      SET_SLOT(ans, Matrix_factorSym, allocVector(VECSXP, 0));      csc_compTr(xdims[0], xdims[1], nnz,
360      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),  
361                               REAL(GET_SLOT(x, Matrix_xSym)),                               REAL(GET_SLOT(x, Matrix_xSym)),
362                               INTEGER(GET_SLOT(ans, Matrix_pSym)),                 INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, xdims[0] + 1)),
363                               INTEGER(GET_SLOT(ans, Matrix_iSym)),                 INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP, nnz)),
364                               REAL(GET_SLOT(ans, Matrix_xSym)));                 REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, nnz)));
365      UNPROTECT(1);      UNPROTECT(1);
366      return ans;      return ans;
367  }  }
# Line 386  Line 377 
377      SEXP val;      SEXP val;
378    
379      if (bdim[0] != r)      if (bdim[0] != r)
380          error("Matrices of sizes (%d,%d) and (%d,%d) cannot be multiplied",          error(_("Matrices of sizes (%d,%d) and (%d,%d) cannot be multiplied"),
381                m, r, bdim[0], n);                m, r, bdim[0], n);
382      val = PROTECT(allocMatrix(REALSXP, m, n));      val = PROTECT(allocMatrix(REALSXP, m, n));
383      for (j = 0; j < n; j++) {   /* across columns of b */      for (j = 0; j < n; j++) {   /* across columns of b */
# Line 416  Line 407 
407      SET_SLOT(val, Matrix_DimSym, duplicate(tmp));      SET_SLOT(val, Matrix_DimSym, duplicate(tmp));
408      ncol = INTEGER(tmp)[1];      ncol = INTEGER(tmp)[1];
409      if (!(isInteger(perm) && length(perm) == ncol))      if (!(isInteger(perm) && length(perm) == ncol))
410          error("perm must be an integer vector of length %d",          error(_("perm must be an integer vector of length %d"),
411                ncol);                ncol);
412      prm = INTEGER(perm);      prm = INTEGER(perm);
413      if (!R_ldl_valid_perm(ncol, prm))      if (!R_ldl_valid_perm(ncol, prm))
414          error("perm is not a valid 0-based permutation");          error(_("perm is not a valid 0-based permutation"));
415      iperm = Calloc(ncol, int);      iperm = Calloc(ncol, int);
416      for (j = 0; j < ncol; j++) iperm[prm[j]] = j;      for (j = 0; j < ncol; j++) iperm[prm[j]] = j;
417      tmp = GET_SLOT(x, Matrix_pSym);      tmp = GET_SLOT(x, Matrix_pSym);

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

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