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 477, Wed Feb 2 14:14:59 2005 UTC revision 478, Wed Feb 2 14:33:51 2005 UTC
# Line 1  Line 1 
1  #include "sscMatrix.h"  #include "dsCMatrix.h"
2    
3  SEXP sscMatrix_validate(SEXP obj)  SEXP dsCMatrix_validate(SEXP obj)
4  {  {
5      SEXP uplo = GET_SLOT(obj, Matrix_uploSym);      SEXP uplo = GET_SLOT(obj, Matrix_uploSym);
6      int *Dim = INTEGER(GET_SLOT(obj, Matrix_DimSym));      int *Dim = INTEGER(GET_SLOT(obj, Matrix_DimSym));
# Line 19  Line 19 
19      return ScalarLogical(1);      return ScalarLogical(1);
20  }  }
21    
22  SEXP sscMatrix_chol(SEXP x, SEXP pivot)  SEXP dsCMatrix_chol(SEXP x, SEXP pivot)
23  {  {
24      SEXP pSlot = GET_SLOT(x, Matrix_pSym), xorig = x;      SEXP pSlot = GET_SLOT(x, Matrix_pSym), xorig = x;
25      int *Ai = INTEGER(GET_SLOT(x, Matrix_iSym)),      int *Ai = INTEGER(GET_SLOT(x, Matrix_iSym)),
# Line 46  Line 46 
46      Lp = INTEGER(GET_SLOT(val, Matrix_pSym));      Lp = INTEGER(GET_SLOT(val, Matrix_pSym));
47      Ax = REAL(GET_SLOT(x, Matrix_xSym));      Ax = REAL(GET_SLOT(x, Matrix_xSym));
48      if (piv) {      if (piv) {
49          SEXP trip = PROTECT(sscMatrix_to_triplet(x));          SEXP trip = PROTECT(dsCMatrix_to_dgTMatrix(x));
50          SEXP Ti = GET_SLOT(trip, Matrix_iSym);          SEXP Ti = GET_SLOT(trip, Matrix_iSym);
51    
52          /* determine the permutation with Metis */          /* determine the permutation with Metis */
# Line 59  Line 59 
59          Ai = Calloc(nnz, int);          Ai = Calloc(nnz, int);
60          Ax = Calloc(nnz, double);          Ax = Calloc(nnz, double);
61          Ap = Calloc(n + 1, int);          Ap = Calloc(n + 1, int);
62          triplet_to_col(n, n, nnz, INTEGER(Ti),          dgTMatrix_to_dgCMatrix(n, n, nnz, INTEGER(Ti),
63                         INTEGER(GET_SLOT(trip, Matrix_jSym)),                         INTEGER(GET_SLOT(trip, Matrix_jSym)),
64                         REAL(GET_SLOT(trip, Matrix_xSym)),                         REAL(GET_SLOT(trip, Matrix_xSym)),
65                         Ap, Ai, Ax);                         Ap, Ai, Ax);
# Line 86  Line 86 
86      return set_factors(xorig, val, "Cholesky");      return set_factors(xorig, val, "Cholesky");
87  }  }
88    
89  SEXP sscMatrix_matrix_solve(SEXP a, SEXP b)  SEXP dsCMatrix_matrix_solve(SEXP a, SEXP b)
90  {  {
91      SEXP Chol = get_factors(a, "Cholesky"), perm,      SEXP Chol = get_factors(a, "Cholesky"), perm,
92          val = PROTECT(duplicate(b));          val = PROTECT(duplicate(b));
# Line 99  Line 99 
99          error("Argument b must be a numeric matrix");          error("Argument b must be a numeric matrix");
100      if (*adims != *bdims || bdims[1] < 1 || *adims < 1)      if (*adims != *bdims || bdims[1] < 1 || *adims < 1)
101          error("Dimensions of system to be solved are inconsistent");          error("Dimensions of system to be solved are inconsistent");
102      if (Chol == R_NilValue) Chol = sscMatrix_chol(a, ScalarLogical(1));      if (Chol == R_NilValue) Chol = dsCMatrix_chol(a, ScalarLogical(1));
103      perm = GET_SLOT(Chol, Matrix_permSym);      perm = GET_SLOT(Chol, Matrix_permSym);
104      piv = length(perm);      piv = length(perm);
105      if (piv) tmp = Calloc(n, double);      if (piv) tmp = Calloc(n, double);
# Line 120  Line 120 
120      return val;      return val;
121  }  }
122    
123  SEXP sscMatrix_inverse_factor(SEXP A)  SEXP dsCMatrix_inverse_factor(SEXP A)
124  {  {
125      return R_NilValue;          /* FIXME: Write this function. */      return R_NilValue;          /* FIXME: Write this function. */
126  }  }
# Line 128  Line 128 
128  SEXP ssc_transpose(SEXP x)  SEXP ssc_transpose(SEXP x)
129  {  {
130      SEXP      SEXP
131          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("sscMatrix"))),          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dsCMatrix"))),
132          islot = GET_SLOT(x, Matrix_iSym);          islot = GET_SLOT(x, Matrix_iSym);
133      int nnz = length(islot),      int nnz = length(islot),
134          *adims = INTEGER(GET_SLOT(ans, Matrix_DimSym)),          *adims = INTEGER(GET_SLOT(ans, Matrix_DimSym)),
# Line 151  Line 151 
151      return ans;      return ans;
152  }  }
153    
154  SEXP sscMatrix_to_triplet(SEXP x)  SEXP dsCMatrix_to_dgTMatrix(SEXP x)
155  {  {
156      SEXP      SEXP
157          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("tripletMatrix"))),          ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgTMatrix"))),
158          islot = GET_SLOT(x, Matrix_iSym),          islot = GET_SLOT(x, Matrix_iSym),
159          pslot = GET_SLOT(x, Matrix_pSym);          pslot = GET_SLOT(x, Matrix_pSym);
160      int *ai, *aj, *iv = INTEGER(islot),      int *ai, *aj, *iv = INTEGER(islot),
# Line 195  Line 195 
195      return ans;      return ans;
196  }  }
197    
198  SEXP sscMatrix_ldl_symbolic(SEXP x, SEXP doPerm)  SEXP dsCMatrix_ldl_symbolic(SEXP x, SEXP doPerm)
199  {  {
200      SEXP Ax, Dims = GET_SLOT(x, Matrix_DimSym),      SEXP Ax, Dims = GET_SLOT(x, Matrix_DimSym),
201          ans = PROTECT(allocVector(VECSXP, 3)), tsc;          ans = PROTECT(allocVector(VECSXP, 3)), tsc;
# Line 225  Line 225 
225      }      }
226      SET_VECTOR_ELT(ans, 0, allocVector(INTSXP, n));      SET_VECTOR_ELT(ans, 0, allocVector(INTSXP, n));
227      Parent = INTEGER(VECTOR_ELT(ans, 0));      Parent = INTEGER(VECTOR_ELT(ans, 0));
228      SET_VECTOR_ELT(ans, 1, NEW_OBJECT(MAKE_CLASS("tscMatrix")));      SET_VECTOR_ELT(ans, 1, NEW_OBJECT(MAKE_CLASS("dtCMatrix")));
229      tsc = VECTOR_ELT(ans, 1);      tsc = VECTOR_ELT(ans, 1);
230      SET_SLOT(tsc, Matrix_uploSym, ScalarString(mkChar("L")));      SET_SLOT(tsc, Matrix_uploSym, ScalarString(mkChar("L")));
231      SET_SLOT(tsc, Matrix_diagSym, ScalarString(mkChar("U")));      SET_SLOT(tsc, Matrix_diagSym, ScalarString(mkChar("U")));
# Line 247  Line 247 
247      return ans;      return ans;
248  }  }
249    
250  SEXP sscMatrix_metis_perm(SEXP x)  SEXP dsCMatrix_metis_perm(SEXP x)
251  {  {
252      SEXP pSlot = GET_SLOT(x, Matrix_pSym),      SEXP pSlot = GET_SLOT(x, Matrix_pSym),
253          ans = PROTECT(allocVector(VECSXP, 2));          ans = PROTECT(allocVector(VECSXP, 2));

Legend:
Removed from v.477  
changed lines
  Added in v.478

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