SCM

SCM Repository

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

Diff of /pkg/Matrix/src/dtCMatrix.c

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

revision 2217, Thu Jul 17 20:20:26 2008 UTC revision 2220, Thu Jul 17 21:37:21 2008 UTC
# Line 76  Line 76 
76    
77  #undef RETURN  #undef RETURN
78    
 SEXP dtCMatrix_solve(SEXP a)  
 {  
     SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dtCMatrix")));  
     CSP A = AS_CSP(Csparse_diagU2N(a));  
     CSP eye = csp_eye(A->n);  
     int *bp = INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, (A->n) + 1)),  
         bnz = 10 * A->n,        /* initial estimate of nnz in b */  
         lo = uplo_P(a)[0] == 'L', top;  
     /* These arrays must use Calloc because of possible Realloc */  
     int *ti = Calloc(bnz, int), pos = 0;  
     double *tx = Calloc(bnz, double);  
     double  *wrk = Alloca(A->n, double);  
     int *xi = Alloca(2*A->n, int);      /* for cs_reach */  
     R_CheckStack();  
   
     slot_dup(ans, a, Matrix_DimSym);  
     SET_DimNames(ans, a);  
     slot_dup(ans, a, Matrix_uploSym);  
     slot_dup(ans, a, Matrix_diagSym);  
     bp[0] = 0;  
     for (int k = 0; k < A->n; k++)  
         col_spsolve(A, eye, k, xi, wrk, (int*)NULL, lo, bnz, pos, bp, ti, tx);  
     nz = bp[A->n];  
     Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP,  nz)), ti, nz);  
     Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, nz)), tx, nz);  
   
     Free(ti); Free(tx); cs_spfree(u);  
     UNPROTECT(1);  
     return ans;  
 }  
   
 #endif  
   
79  SEXP dtCMatrix_matrix_solve(SEXP a, SEXP b, SEXP classed)  SEXP dtCMatrix_matrix_solve(SEXP a, SEXP b, SEXP classed)
80  {  {
81      int cl = asLogical(classed);      int cl = asLogical(classed);
# Line 171  Line 138 
138                  tx[pos] = wrk[xi[p]];                  tx[pos] = wrk[xi[p]];
139              }              }
140      }      }
141      xnz = xp[A->n];      xnz = xp[B->n];
142      Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP,  xnz)), ti, xnz);      Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_iSym, INTSXP,  xnz)), ti, xnz);
143      Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, xnz)), tx, xnz);      Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, xnz)), tx, xnz);
144    

Legend:
Removed from v.2217  
changed lines
  Added in v.2220

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge