SCM

SCM Repository

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

Diff of /pkg/src/dsCMatrix.c

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

revision 582, Mon Feb 28 18:15:21 2005 UTC revision 741, Tue May 17 17:44:02 2005 UTC
# Line 2  Line 2 
2    
3  SEXP dsCMatrix_validate(SEXP obj)  SEXP dsCMatrix_validate(SEXP obj)
4  {  {
5      SEXP uplo = GET_SLOT(obj, Matrix_uploSym);      SEXP val = check_scalar_string(GET_SLOT(obj, Matrix_uploSym),
6                                       "LU", "uplo");
7      int *Dim = INTEGER(GET_SLOT(obj, Matrix_DimSym));      int *Dim = INTEGER(GET_SLOT(obj, Matrix_DimSym));
     char *val;  
8    
9      if (length(uplo) != 1)      if (isString(val)) return val;
         return mkString(_("uplo slot must have length 1"));  
     val = CHAR(STRING_ELT(uplo, 0));  
     if (strlen(val) != 1)  
         return mkString(_("uplo[1] must have string length 1"));  
     if (*val != 'U' && *val != 'L')  
         return mkString(_("uplo[1] must be \"U\" or \"L\""));  
10      if (Dim[0] != Dim[1])      if (Dim[0] != Dim[1])
11          return mkString(_("Symmetric matrix must be square"));          return mkString(_("Symmetric matrix must be square"));
12      csc_check_column_sorting(obj);      csc_check_column_sorting(obj);
# Line 44  Line 38 
38      SET_SLOT(val, Matrix_uploSym, mkString("L"));      SET_SLOT(val, Matrix_uploSym, mkString("L"));
39      SET_SLOT(val, Matrix_diagSym, mkString("U"));      SET_SLOT(val, Matrix_diagSym, mkString("U"));
40      SET_SLOT(val, Matrix_DimSym, duplicate(GET_SLOT(x, Matrix_DimSym)));      SET_SLOT(val, Matrix_DimSym, duplicate(GET_SLOT(x, Matrix_DimSym)));
41      SET_SLOT(val, Matrix_ParentSym, allocVector(INTSXP, n));      Parent = INTEGER(ALLOC_SLOT(val, Matrix_ParentSym, INTSXP, n));
42      Parent = INTEGER(GET_SLOT(val, Matrix_ParentSym));      Lp = INTEGER(ALLOC_SLOT(val, Matrix_pSym, INTSXP, n + 1));
43      SET_SLOT(val, Matrix_pSym, allocVector(INTSXP, n + 1));      P = INTEGER(ALLOC_SLOT(val, Matrix_permSym, INTSXP, n));
     Lp = INTEGER(GET_SLOT(val, Matrix_pSym));  
     SET_SLOT(val, Matrix_permSym, allocVector(INTSXP, n));  
     P = INTEGER(GET_SLOT(val, Matrix_permSym));  
44      if (piv) {      if (piv) {
45          SEXP trip = PROTECT(dsCMatrix_to_dgTMatrix(x));          SEXP trip = PROTECT(dsCMatrix_to_dgTMatrix(x));
46          SEXP Ti = GET_SLOT(trip, Matrix_iSym);          SEXP Ti = GET_SLOT(trip, Matrix_iSym);
# Line 95  Line 86 
86      return set_factors(xorig, val, "Cholesky");      return set_factors(xorig, val, "Cholesky");
87  }  }
88    
89  SEXP dsCMatrix_matrix_solve(SEXP a, SEXP b)  SEXP dsCMatrix_matrix_solve(SEXP a, SEXP b, SEXP classed)
90  {  {
91        int cl = asLogical(classed);
92      SEXP Chol = get_factors(a, "Cholesky"), perm,      SEXP Chol = get_factors(a, "Cholesky"), perm,
93          val = PROTECT(duplicate(b));          bdP = cl ? GET_SLOT(b, Matrix_DimSym) : getAttrib(b, R_DimSymbol),
94            val = PROTECT(NEW_OBJECT(MAKE_CLASS("dgeMatrix")));
95      int *adims = INTEGER(GET_SLOT(a, Matrix_DimSym)),      int *adims = INTEGER(GET_SLOT(a, Matrix_DimSym)),
96          *bdims = INTEGER(getAttrib(b, R_DimSymbol)),          *bdims = INTEGER(bdP),
97          *Li, *Lp, j, n = adims[1], ncol = bdims[1], piv;          *Li, *Lp, j, piv;
98      double *Lx, *D, *in = REAL(b), *out = REAL(val), *tmp = (double *) NULL;      int n = adims[1], ncol = bdims[1];
99        double *Lx, *D, *in = REAL(cl ? GET_SLOT(b, Matrix_xSym) : b),
100            *out = REAL(ALLOC_SLOT(val, Matrix_xSym, REALSXP, n * ncol)),
101            *tmp = (double *) NULL;
102    
103      if (!(isReal(b) && isMatrix(b)))      if (!cl && !(isReal(b) && isMatrix(b)))
104          error(_("Argument b must be a numeric matrix"));          error(_("Argument b must be a numeric matrix"));
105      if (*adims != *bdims || bdims[1] < 1 || *adims < 1)      if (*adims != *bdims || ncol < 1 || *adims < 1)
106          error(_("Dimensions of system to be solved are inconsistent"));          error(_("Dimensions of system to be solved are inconsistent"));
107      if (Chol == R_NilValue) Chol = dsCMatrix_chol(a, ScalarLogical(1));      if (Chol == R_NilValue) Chol = dsCMatrix_chol(a, ScalarLogical(1));
108        SET_SLOT(val, Matrix_DimSym, duplicate(bdP));
109      perm = GET_SLOT(Chol, Matrix_permSym);      perm = GET_SLOT(Chol, Matrix_permSym);
110      piv = length(perm);      piv = length(perm);
111      if (piv) tmp = Calloc(n, double);      if (piv) tmp = Calloc(n, double);
# Line 136  Line 133 
133    
134  SEXP ssc_transpose(SEXP x)  SEXP ssc_transpose(SEXP x)
135  {  {
136      SEXP      SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dsCMatrix"))),
         ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dsCMatrix"))),  
137          islot = GET_SLOT(x, Matrix_iSym);          islot = GET_SLOT(x, Matrix_iSym);
138      int nnz = length(islot),      int nnz = length(islot), *adims,
         *adims = INTEGER(GET_SLOT(ans, Matrix_DimSym)),  
139          *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym));          *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym));
140    
141        adims = INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2));
142      adims[0] = xdims[1]; adims[1] = xdims[0];      adims[0] = xdims[1]; adims[1] = xdims[0];
143      if (CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0] == 'U')      if (CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0] == 'U')
144          SET_SLOT(ans, Matrix_uploSym, mkString("L"));          SET_SLOT(ans, Matrix_uploSym, mkString("L"));
145      SET_SLOT(ans, Matrix_pSym, allocVector(INTSXP, xdims[0] + 1));      else
146      SET_SLOT(ans, Matrix_iSym, allocVector(INTSXP, nnz));          SET_SLOT(ans, Matrix_uploSym, mkString("U"));
147      SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, nnz));      csc_compTr(xdims[0], xdims[1], nnz,
148      csc_components_transpose(xdims[0], xdims[1], nnz,                 INTEGER(GET_SLOT(x, Matrix_pSym)), INTEGER(islot),
                              INTEGER(GET_SLOT(x, Matrix_pSym)),  
                              INTEGER(islot),  
149                               REAL(GET_SLOT(x, Matrix_xSym)),                               REAL(GET_SLOT(x, Matrix_xSym)),
150                               INTEGER(GET_SLOT(ans, Matrix_pSym)),                 INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, xdims[0] + 1)),
151                               INTEGER(GET_SLOT(ans, Matrix_iSym)),                 INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP, nnz)),
152                               REAL(GET_SLOT(ans, Matrix_xSym)));                 REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, nnz)));
153      UNPROTECT(1);      UNPROTECT(1);
154      return ans;      return ans;
155  }  }

Legend:
Removed from v.582  
changed lines
  Added in v.741

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