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 2586, Sun Jul 25 02:32:06 2010 UTC revision 2770, Mon Mar 5 13:41:23 2012 UTC
# Line 74  Line 74 
74      }      }
75  }  }
76    
 #undef RETURN  
   
77  SEXP dtCMatrix_matrix_solve(SEXP a, SEXP b, SEXP classed)  SEXP dtCMatrix_matrix_solve(SEXP a, SEXP b, SEXP classed)
78  {  {
79      int cl = asLogical(classed);      int cl = asLogical(classed);
# Line 96  Line 94 
94                  REAL(cl ? GET_SLOT(b, Matrix_xSym):b), n * nrhs);                  REAL(cl ? GET_SLOT(b, Matrix_xSym):b), n * nrhs);
95      for (j = 0; j < nrhs; j++)      for (j = 0; j < nrhs; j++)
96          lo ? cs_lsolve(A, bx + n * j) : cs_usolve(A, bx + n * j);          lo ? cs_lsolve(A, bx + n * j) : cs_usolve(A, bx + n * j);
97      UNPROTECT(1);      RETURN(ans);
     return ans;  
98  }  }
99    
100  SEXP dtCMatrix_sparse_solve(SEXP a, SEXP b)  SEXP dtCMatrix_sparse_solve(SEXP a, SEXP b)
101  {  {
102      SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));      SEXP ans = PROTECT(NEW_OBJECT(MAKE_CLASS("dgCMatrix")));
103      CSP A = AS_CSP(a), B = AS_CSP(b);      CSP A = AS_CSP(a), B = AS_CSP(b);
104        R_CheckStack();
105        if (A->m != A->n || B->n < 1 || A->n < 1 || A->n != B->m)
106            error(_("Dimensions of system to be solved are inconsistent"));
107        // *before* Calloc()ing below [memory leak]!
108    
109      int *xp = INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, (B->n) + 1)),      int *xp = INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, (B->n) + 1)),
110          xnz = 10 * B->p[B->n];  /* initial estimate of nnz in x */          xnz = 10 * B->p[B->n];  /* initial estimate of nnz in x */
111      int *ti = Calloc(xnz, int), k, lo = uplo_P(a)[0] == 'L', pos = 0;      int *ti = Calloc(xnz, int), k, lo = uplo_P(a)[0] == 'L', pos = 0;
112      double *tx = Calloc(xnz, double);      double *tx = Calloc(xnz, double);
113      double  *wrk = Alloca(A->n, double);      double  *wrk = Calloc(A->n, double);
114      int *xi = Alloca(2*A->n, int);      /* for cs_reach */      int *xi = Calloc(2*A->n, int);      /* for cs_reach */
     R_CheckStack();  
115    
     if (A->m != A->n || B->n < 1 || A->n < 1 || A->n != B->m)  
         error(_("Dimensions of system to be solved are inconsistent"));  
116      slot_dup(ans, b, Matrix_DimSym);      slot_dup(ans, b, Matrix_DimSym);
117      SET_DimNames(ans, b);      SET_DimNames(ans, b);
118      xp[0] = 0;      xp[0] = 0;
# Line 143  Line 142 
142      Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, xnz)), tx, xnz);      Memcpy(   REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, xnz)), tx, xnz);
143    
144      Free(ti); Free(tx);      Free(ti); Free(tx);
145      UNPROTECT(1);      Free(wrk); Free(xi);
146      return ans;  
147        RETURN(ans);
148  }  }
149    #undef RETURN
150    

Legend:
Removed from v.2586  
changed lines
  Added in v.2770

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