SCM

SCM Repository

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

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

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

revision 1658, Wed Nov 1 17:43:46 2006 UTC revision 1659, Wed Nov 1 17:50:15 2006 UTC
# Line 143  Line 143 
143    
144  SEXP Csparse_Csparse_prod(SEXP a, SEXP b)  SEXP Csparse_Csparse_prod(SEXP a, SEXP b)
145  {  {
146      cholmod_sparse *cha = as_cholmod_sparse(a),      cholmod_sparse
147            *cha = as_cholmod_sparse(a),
148          *chb = as_cholmod_sparse(b);          *chb = as_cholmod_sparse(b);
149      cholmod_sparse *chc = cholmod_ssmult(cha, chb, 0, cha->xtype, 1, &c);      cholmod_sparse *chc = cholmod_ssmult(cha, chb, 0, cha->xtype, 1, &c);
150      SEXP dn = allocVector(VECSXP, 2);      SEXP dn = allocVector(VECSXP, 2);
# Line 156  Line 157 
157      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);
158  }  }
159    
160  SEXP Csparse_Csparse_crossprod(SEXP a, SEXP b)  SEXP Csparse_Csparse_crossprod(SEXP a, SEXP b, SEXP trans)
161  {  {
162      cholmod_sparse *cha = as_cholmod_sparse(a),      int tr = asLogical(trans);
163        cholmod_sparse
164            *cha = as_cholmod_sparse(a),
165          *chb = as_cholmod_sparse(b);          *chb = as_cholmod_sparse(b);
166      cholmod_sparse *chta = cholmod_transpose(cha, 1, &c);      cholmod_sparse *chTr, *chc;
     cholmod_sparse *chc = cholmod_ssmult(chta, chb, 0, cha->xtype, 1, &c);  
167      SEXP dn = allocVector(VECSXP, 2);      SEXP dn = allocVector(VECSXP, 2);
168    
169      Free(cha); Free(chb); cholmod_free_sparse(&chta, &c);  /*     cholmod_sparse *chTr = cholmod_transpose(cha, 1, &c); */
170    /*     cholmod_sparse *chc = cholmod_ssmult(chTr, chb, 0, cha->xtype, 1, &c); */
171    
172        if (tr)
173            chTr = cholmod_transpose(chb, chb->xtype, &c);
174        else
175            chTr = cholmod_transpose(cha, cha->xtype, &c);
176        chc = cholmod_ssmult((tr) ? cha : chTr, (tr) ? chTr : chb,
177                             0, cha->xtype, 1, &c);
178    
179        Free(cha); Free(chb); cholmod_free_sparse(&chTr, &c);
180    
181      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
182                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 1)));                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), (tr) ? 0 : 1)));
183      SET_VECTOR_ELT(dn, 1,      SET_VECTOR_ELT(dn, 1,
184                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), (tr) ? 0 : 1)));
185      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chc, 1, 0, 0, "", dn);
186  }  }
187    
# Line 200  Line 213 
213      return chm_dense_to_SEXP(chc, 1, 0);      return chm_dense_to_SEXP(chc, 1, 0);
214  }  }
215    
216    /* Computes   x'x  or  x x'  -- see Csparse_Csparse_crossprod above for  x'y and x y' */
217  SEXP Csparse_crossprod(SEXP x, SEXP trans, SEXP triplet)  SEXP Csparse_crossprod(SEXP x, SEXP trans, SEXP triplet)
218  {  {
219      int trip = asLogical(triplet),      int trip = asLogical(triplet),

Legend:
Removed from v.1658  
changed lines
  Added in v.1659

root@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