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 2889, Thu Aug 8 21:06:22 2013 UTC revision 3011, Mon Oct 6 17:00:48 2014 UTC
# Line 86  Line 86 
86      double *bx;      double *bx;
87      R_CheckStack();      R_CheckStack();
88    
89      if (*adims != n || nrhs < 1 || *adims < 1 || *adims != adims[1])      if (adims[0] != n || n != adims[1])
90          error(_("Dimensions of system to be solved are inconsistent"));          error(_("Dimensions of system to be solved are inconsistent"));
91      Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2)), bdims, 2);      Memcpy(INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2)), bdims, 2);
92      /* FIXME: copy dimnames or Dimnames as well */      // dimnames:
93        SEXP dn = PROTECT(allocVector(VECSXP, 2));
94        SET_VECTOR_ELT(dn, 0, duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 1)));
95        SET_VECTOR_ELT(dn, 1, duplicate(cl // b can be "Matrix" or not:
96                                        ? VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)
97                                        : getAttrib(b, R_DimNamesSymbol)));
98        SET_SLOT(ans, Matrix_DimNamesSym, dn);
99        UNPROTECT(1);
100        if(n >= 1 && nrhs >=1) {
101      bx = Memcpy(REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, n * nrhs)),      bx = Memcpy(REAL(ALLOC_SLOT(ans, Matrix_xSym, REALSXP, n * nrhs)),
102                  REAL(cl ? GET_SLOT(b, Matrix_xSym):b), n * nrhs);                  REAL(cl ? GET_SLOT(b, Matrix_xSym):b), n * nrhs);
103      for (j = 0; j < nrhs; j++)      for (j = 0; j < nrhs; j++)
104          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);
105        }
106      RETURN(ans);      RETURN(ans);
107  }  }
108    
# Line 104  Line 113 
113      R_CheckStack();      R_CheckStack();
114      if (A->m != A->n || B->n < 1 || A->n < 1 || A->n != B->m)      if (A->m != A->n || B->n < 1 || A->n < 1 || A->n != B->m)
115          error(_("Dimensions of system to be solved are inconsistent"));          error(_("Dimensions of system to be solved are inconsistent"));
116      // *before* Calloc()ing below [memory leak]!      // *before* Calloc()ing below [memory leak]! -- FIXME: 0-extent should work
117    
118      int *xp = INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, (B->n) + 1)),      int *xp = INTEGER(ALLOC_SLOT(ans, Matrix_pSym, INTSXP, (B->n) + 1)),
119          xnz = 10 * B->p[B->n];  /* initial estimate of nnz in x */          xnz = 10 * B->p[B->n];  /* initial estimate of nnz in x */
# Line 113  Line 122 
122      double *tx = Calloc(xnz, double), *wrk = Calloc(  A->n, double);      double *tx = Calloc(xnz, double), *wrk = Calloc(  A->n, double);
123    
124      slot_dup(ans, b, Matrix_DimSym);      slot_dup(ans, b, Matrix_DimSym);
125      SET_DimNames(ans, b);  
126      xp[0] = 0;      xp[0] = 0;
127      for (k = 0; k < B->n; k++) {      for (k = 0; k < B->n; k++) {
128          int top = cs_spsolve (A, B, k, xi, wrk, (int *)NULL, lo);          int top = cs_spsolve (A, B, k, xi, wrk, (int *)NULL, lo);
# Line 143  Line 152 
152      Free(ti);  Free(tx);      Free(ti);  Free(tx);
153      Free(wrk); Free(xi);      Free(wrk); Free(xi);
154    
155        // dimnames:
156        SEXP dn = PROTECT(allocVector(VECSXP, 2));
157        SET_VECTOR_ELT(dn, 0, duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 1)));
158        SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));
159        SET_SLOT(ans, Matrix_DimNamesSym, dn);
160        UNPROTECT(1);
161    
162      RETURN(ans);      RETURN(ans);
163  }  }
164  #undef RETURN  #undef RETURN

Legend:
Removed from v.2889  
changed lines
  Added in v.3011

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