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

pkg/src/sscMatrix.c revision 478, Wed Feb 2 14:33:51 2005 UTC pkg/src/dsCMatrix.c revision 534, Tue Feb 8 08:59:31 2005 UTC
# Line 7  Line 7 
7      char *val;      char *val;
8    
9      if (length(uplo) != 1)      if (length(uplo) != 1)
10          return ScalarString(mkChar("uplo slot must have length 1"));          return mkString("uplo slot must have length 1");
11      val = CHAR(STRING_ELT(uplo, 0));      val = CHAR(STRING_ELT(uplo, 0));
12      if (strlen(val) != 1)      if (strlen(val) != 1)
13          return ScalarString(mkChar("uplo[1] must have string length 1"));          return mkString("uplo[1] must have string length 1");
14      if (toupper(*val) != 'U' && toupper(*val) != 'L')      if (*val != 'U' && *val != 'L')
15          return ScalarString(mkChar("uplo[1] must be \"U\" or \"L\""));          return mkString("uplo[1] must be \"U\" or \"L\"");
16      if (Dim[0] != Dim[1])      if (Dim[0] != Dim[1])
17          return ScalarString(mkChar("Symmetric matrix must be square"));          return mkString("Symmetric matrix must be square");
18      csc_check_column_sorting(obj);      csc_check_column_sorting(obj);
19      return ScalarLogical(1);      return ScalarLogical(1);
20  }  }
# Line 25  Line 25 
25      int *Ai = INTEGER(GET_SLOT(x, Matrix_iSym)),      int *Ai = INTEGER(GET_SLOT(x, Matrix_iSym)),
26          *Ap = INTEGER(pSlot),          *Ap = INTEGER(pSlot),
27          *Lp, *Parent, info,          *Lp, *Parent, info,
28          lo = toupper(CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0]) == 'L',          lo = CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0] == 'L',
29          n = length(pSlot)-1,          n = length(pSlot)-1,
30          nnz, piv = asLogical(pivot);          nnz, piv = asLogical(pivot);
31      SEXP val = PROTECT(NEW_OBJECT(MAKE_CLASS("sscChol")));      SEXP val = PROTECT(NEW_OBJECT(MAKE_CLASS("dCholCMatrix")));
32      int *P = (int *) NULL, *Pinv = (int *) NULL;      int *P, *Pinv;
33      double *Ax;      double *Ax;
34    
35        /* FIXME: Check if there is a Cholesky factorization.  If yes,
36           check if the permutation status matches that of the call.  If
37           so, return it. */
38    
39      if (lo) {      if (lo) {
40          x = PROTECT(ssc_transpose(x));          x = PROTECT(ssc_transpose(x));
41          Ai = INTEGER(GET_SLOT(x, Matrix_iSym));          Ai = INTEGER(GET_SLOT(x, Matrix_iSym));
42          Ap = INTEGER(GET_SLOT(x, Matrix_pSym));          Ap = INTEGER(GET_SLOT(x, Matrix_pSym));
43      }      }
44      SET_SLOT(val, Matrix_uploSym, ScalarString(mkChar("L")));      SET_SLOT(val, Matrix_uploSym, mkString("L"));
45      SET_SLOT(val, Matrix_diagSym, ScalarString(mkChar("N")));      SET_SLOT(val, Matrix_diagSym, mkString("U"));
46      SET_SLOT(val, Matrix_DimSym, duplicate(GET_SLOT(x, Matrix_DimSym)));      SET_SLOT(val, Matrix_DimSym, duplicate(GET_SLOT(x, Matrix_DimSym)));
47      SET_SLOT(val, Matrix_ParentSym, allocVector(INTSXP, n));      SET_SLOT(val, Matrix_ParentSym, allocVector(INTSXP, n));
48      Parent = INTEGER(GET_SLOT(val, Matrix_ParentSym));      Parent = INTEGER(GET_SLOT(val, Matrix_ParentSym));
49      SET_SLOT(val, Matrix_pSym, allocVector(INTSXP, n + 1));      SET_SLOT(val, Matrix_pSym, allocVector(INTSXP, n + 1));
50      Lp = INTEGER(GET_SLOT(val, Matrix_pSym));      Lp = INTEGER(GET_SLOT(val, Matrix_pSym));
51      Ax = REAL(GET_SLOT(x, Matrix_xSym));      SET_SLOT(val, Matrix_permSym, allocVector(INTSXP, n));
52        P = INTEGER(GET_SLOT(val, Matrix_permSym));
53      if (piv) {      if (piv) {
54          SEXP trip = PROTECT(dsCMatrix_to_dgTMatrix(x));          SEXP trip = PROTECT(dsCMatrix_to_dgTMatrix(x));
55          SEXP Ti = GET_SLOT(trip, Matrix_iSym);          SEXP Ti = GET_SLOT(trip, Matrix_iSym);
56    
57          /* determine the permutation with Metis */          /* determine the permutation with Metis */
58          Pinv = Calloc(n, int);          Pinv = Calloc(n, int);
         SET_SLOT(val, Matrix_permSym, allocVector(INTSXP, n));  
         P = INTEGER(GET_SLOT(val, Matrix_permSym));  
59          ssc_metis_order(n, Ap, Ai, P, Pinv);          ssc_metis_order(n, Ap, Ai, P, Pinv);
60          /* create a symmetrized form of x */          /* create a symmetrized form of x */
61          nnz = length(Ti);          nnz = length(Ti);
62          Ai = Calloc(nnz, int);          Ai = Calloc(nnz, int);
63          Ax = Calloc(nnz, double);          Ax = Calloc(nnz, double);
64          Ap = Calloc(n + 1, int);          Ap = Calloc(n + 1, int);
65          dgTMatrix_to_dgCMatrix(n, n, nnz, INTEGER(Ti),          triplet_to_col(n, n, nnz, INTEGER(Ti),
66                         INTEGER(GET_SLOT(trip, Matrix_jSym)),                         INTEGER(GET_SLOT(trip, Matrix_jSym)),
67                         REAL(GET_SLOT(trip, Matrix_xSym)),                         REAL(GET_SLOT(trip, Matrix_xSym)),
68                         Ap, Ai, Ax);                         Ap, Ai, Ax);
69            UNPROTECT(1);
70        } else {
71            int i;
72            for (i = 0; i < n; i++) P[i] = i;
73            Ax = REAL(GET_SLOT(x, Matrix_xSym));
74    
75      }      }
76      R_ldl_symbolic(n, Ap, Ai, Lp, Parent, P, Pinv);      R_ldl_symbolic(n, Ap, Ai, Lp, Parent, (piv) ? P : (int *)NULL,
77                       (piv) ? Pinv : (int *)NULL);
78      nnz = Lp[n];      nnz = Lp[n];
79      SET_SLOT(val, Matrix_iSym, allocVector(INTSXP, nnz));      SET_SLOT(val, Matrix_iSym, allocVector(INTSXP, nnz));
80      SET_SLOT(val, Matrix_xSym, allocVector(REALSXP, nnz));      SET_SLOT(val, Matrix_xSym, allocVector(REALSXP, nnz));
81      SET_SLOT(val, Matrix_DSym, allocVector(REALSXP, n));      SET_SLOT(val, Matrix_DSym, allocVector(REALSXP, n));
82      info = R_ldl_numeric(n, Ap, Ai, Ax,      info = R_ldl_numeric(n, Ap, Ai, Ax, Lp, Parent,
                        Lp, Parent,  
83                         INTEGER(GET_SLOT(val, Matrix_iSym)),                         INTEGER(GET_SLOT(val, Matrix_iSym)),
84                         REAL(GET_SLOT(val, Matrix_xSym)),                         REAL(GET_SLOT(val, Matrix_xSym)),
85                         REAL(GET_SLOT(val, Matrix_DSym)),                         REAL(GET_SLOT(val, Matrix_DSym)),
86                         P, Pinv);                           (piv) ? P : (int *)NULL,
87                             (piv) ? Pinv : (int *)NULL);
88      if (info != n)      if (info != n)
89          error("Leading minor of size %d (possibly after permutation) is indefinite",          error("Leading minor of size %d (possibly after permutation) is indefinite",
90                info + 1);                info + 1);
91      if (piv) {      if (piv) {
         UNPROTECT(1);  
92          Free(Pinv); Free(Ax); Free(Ai); Free(Ap);          Free(Pinv); Free(Ax); Free(Ai); Free(Ap);
93      }      }
94      UNPROTECT(lo ? 2 : 1);      UNPROTECT(lo ? 2 : 1);
# Line 135  Line 144 
144          *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym));          *xdims = INTEGER(GET_SLOT(x, Matrix_DimSym));
145    
146      adims[0] = xdims[1]; adims[1] = xdims[0];      adims[0] = xdims[1]; adims[1] = xdims[0];
147      if (toupper(CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0]) == 'U')      if (CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0] == 'U')
148          SET_SLOT(ans, Matrix_uploSym, ScalarString(mkChar("L")));          SET_SLOT(ans, Matrix_uploSym, mkString("L"));
149      SET_SLOT(ans, Matrix_pSym, allocVector(INTSXP, xdims[0] + 1));      SET_SLOT(ans, Matrix_pSym, allocVector(INTSXP, xdims[0] + 1));
150      SET_SLOT(ans, Matrix_iSym, allocVector(INTSXP, nnz));      SET_SLOT(ans, Matrix_iSym, allocVector(INTSXP, nnz));
151      SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, nnz));      SET_SLOT(ans, Matrix_xSym, allocVector(REALSXP, nnz));
# Line 205  Line 214 
214          *P = (int *) NULL, *Pinv = (int *) NULL;          *P = (int *) NULL, *Pinv = (int *) NULL;
215    
216    
217      if (toupper(CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0]) == 'L') {      if (CHAR(asChar(GET_SLOT(x, Matrix_uploSym)))[0] == 'L') {
218          x = PROTECT(ssc_transpose(x));          x = PROTECT(ssc_transpose(x));
219      } else {      } else {
220          x = PROTECT(duplicate(x));          x = PROTECT(duplicate(x));
# Line 227  Line 236 
236      Parent = INTEGER(VECTOR_ELT(ans, 0));      Parent = INTEGER(VECTOR_ELT(ans, 0));
237      SET_VECTOR_ELT(ans, 1, NEW_OBJECT(MAKE_CLASS("dtCMatrix")));      SET_VECTOR_ELT(ans, 1, NEW_OBJECT(MAKE_CLASS("dtCMatrix")));
238      tsc = VECTOR_ELT(ans, 1);      tsc = VECTOR_ELT(ans, 1);
239      SET_SLOT(tsc, Matrix_uploSym, ScalarString(mkChar("L")));      SET_SLOT(tsc, Matrix_uploSym, mkString("L"));
240      SET_SLOT(tsc, Matrix_diagSym, ScalarString(mkChar("U")));      SET_SLOT(tsc, Matrix_diagSym, mkString("U"));
241      SET_SLOT(tsc, Matrix_DimSym, Dims);      SET_SLOT(tsc, Matrix_DimSym, Dims);
242      SET_SLOT(tsc, Matrix_pSym, allocVector(INTSXP, n + 1));      SET_SLOT(tsc, Matrix_pSym, allocVector(INTSXP, n + 1));
243      Lp = INTEGER(GET_SLOT(tsc, Matrix_pSym));      Lp = INTEGER(GET_SLOT(tsc, Matrix_pSym));

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

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