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 3018, Sat Oct 11 17:52:10 2014 UTC revision 3072, Fri Mar 27 15:10:48 2015 UTC
# Line 101  Line 101 
101      return ScalarLogical(1);      return ScalarLogical(1);
102  }  }
103    
104    /**
105  /* Called from ../R/Csparse.R : */   * From a CsparseMatrix, produce a dense one.
106  /* Can only return [dln]geMatrix (no symm/triang);   * Directly deals with symmetric, triangular and general.
107   * FIXME: replace by non-CHOLMOD code ! */   * Called from ../R/Csparse.R's  C2dense()
108  SEXP Csparse_to_dense(SEXP x)   *
109     * @param x a CsparseMatrix: currently all 9 of  "[dln][gst]CMatrix"
110     * @param symm_or_tri integer (NA, < 0, > 0, = 0) specifying the knowledge of the caller about x:
111     *      NA  : unknown => will be determined
112     *      = 0 : "generalMatrix" (not symm or tri);
113     *      < 0 : "triangularMatrix"
114     *      > 0 : "symmetricMatrix"
115     *
116     * @return a "denseMatrix"
117     */
118    SEXP Csparse_to_dense(SEXP x, SEXP symm_or_tri)
119  {  {
120      CHM_SP chxs = AS_CHM_SP__(x);      Rboolean is_sym, is_tri;
121      /* This loses the symmetry property, since cholmod_dense has none,      int is_sym_or_tri = asInteger(symm_or_tri),
122            ctype = 0; // <- default = "dgC"
123        static const char *valid[] = { MATRIX_VALID_Csparse, ""};
124        if(is_sym_or_tri == NA_INTEGER) { // find if  is(x, "symmetricMatrix") :
125            ctype = Matrix_check_class_etc(x, valid);
126            is_sym = (ctype % 3 == 1);
127            is_tri = (ctype % 3 == 2);
128        } else {
129            is_sym = is_sym_or_tri > 0;
130            is_tri = is_sym_or_tri < 0;
131            // => both are FALSE  iff  is_.. == 0
132            if(is_sym || is_tri)
133                ctype = Matrix_check_class_etc(x, valid);
134        }
135        CHM_SP chxs = AS_CHM_SP__(x);// -> chxs->stype = +- 1 <==> symmetric
136        R_CheckStack();
137        if(is_tri && *diag_P(x) == 'U') { // ==>  x := diagU2N(x), directly for chxs
138            CHM_SP eye = cholmod_speye(chxs->nrow, chxs->ncol, chxs->xtype, &c);
139            double one[] = {1, 0};
140            CHM_SP ans = cholmod_add(chxs, eye, one, one,
141                                     /* values: */ ((ctype / 3) != 2), // TRUE iff not "nMatrix"
142                                     TRUE, &c);
143            cholmod_free_sparse(&eye, &c);
144            chxs = cholmod_copy_sparse(ans, &c);
145            cholmod_free_sparse(&ans, &c);
146        }
147        /* The following loses the symmetry property, since cholmod_dense has none,
148       * BUT, much worse (FIXME!), it also transforms CHOLMOD_PATTERN ("n") matrices       * BUT, much worse (FIXME!), it also transforms CHOLMOD_PATTERN ("n") matrices
149       * to numeric (CHOLMOD_REAL) ones : */       * to numeric (CHOLMOD_REAL) ones {and we "revert" via chm_dense_to_SEXP()}: */
150      CHM_DN chxd = cholmod_sparse_to_dense(chxs, &c);      CHM_DN chxd = cholmod_sparse_to_dense(chxs, &c);
151      int Rkind = (chxs->xtype == CHOLMOD_PATTERN)? -1 : Real_kind(x);      int Rkind = (chxs->xtype == CHOLMOD_PATTERN)? -1 : Real_kind(x);
     R_CheckStack();  
152    
153      return chm_dense_to_SEXP(chxd, 1, Rkind, GET_SLOT(x, Matrix_DimNamesSym));      SEXP ans = chm_dense_to_SEXP(chxd, 1, Rkind, GET_SLOT(x, Matrix_DimNamesSym),
154                                     /* transp: */ FALSE);
155        // -> a [dln]geMatrix
156        if(is_sym) { // ==> want  [dln]syMatrix
157            const char cl1 = class_P(ans)[0];
158            PROTECT(ans);
159            SEXP aa = PROTECT(NEW_OBJECT(MAKE_CLASS((cl1 == 'd') ? "dsyMatrix" :
160                                                    ((cl1 == 'l') ? "lsyMatrix" : "nsyMatrix"))));
161            // No need to duplicate() as slots of ans are freshly allocated and ans will not be used
162            SET_SLOT(aa, Matrix_xSym,       GET_SLOT(ans, Matrix_xSym));
163            SET_SLOT(aa, Matrix_DimSym,     GET_SLOT(ans, Matrix_DimSym));
164            SET_SLOT(aa, Matrix_DimNamesSym,GET_SLOT(ans, Matrix_DimNamesSym));
165            SET_SLOT(aa, Matrix_uploSym, mkString((chxs->stype > 0) ? "U" : "L"));
166            UNPROTECT(2);
167            return aa;
168        }
169        else if(is_tri) { // ==> want  [dln]trMatrix
170            const char cl1 = class_P(ans)[0];
171            PROTECT(ans);
172            SEXP aa = PROTECT(NEW_OBJECT(MAKE_CLASS((cl1 == 'd') ? "dtrMatrix" :
173                                                    ((cl1 == 'l') ? "ltrMatrix" : "ntrMatrix"))));
174            // No need to duplicate() as slots of ans are freshly allocated and ans will not be used
175            SET_SLOT(aa, Matrix_xSym,       GET_SLOT(ans, Matrix_xSym));
176            SET_SLOT(aa, Matrix_DimSym,     GET_SLOT(ans, Matrix_DimSym));
177            SET_SLOT(aa, Matrix_DimNamesSym,GET_SLOT(ans, Matrix_DimNamesSym));
178            slot_dup(aa, x, Matrix_uploSym);
179            /* already by NEW_OBJECT(..) above:
180               SET_SLOT(aa, Matrix_diagSym, mkString("N")); */
181            UNPROTECT(2);
182            return aa;
183        }
184        else
185            return ans;
186  }  }
187    
188  // FIXME: do not go via CHM (should not be too hard, to just *drop* the x-slot, right?  // FIXME: do not go via CHM (should not be too hard, to just *drop* the x-slot, right?
189  SEXP Csparse_to_nz_pattern(SEXP x, SEXP tri)  SEXP Csparse2nz(SEXP x, Rboolean tri)
190  {  {
191      CHM_SP chxs = AS_CHM_SP__(x);      CHM_SP chxs = AS_CHM_SP__(x);
192      CHM_SP chxcp = cholmod_copy(chxs, chxs->stype, CHOLMOD_PATTERN, &c);      CHM_SP chxcp = cholmod_copy(chxs, chxs->stype, CHOLMOD_PATTERN, &c);
     int tr = asLogical(tri);  
193      R_CheckStack();      R_CheckStack();
194    
195      return chm_sparse_to_SEXP(chxcp, 1/*do_free*/,      return chm_sparse_to_SEXP(chxcp, 1/*do_free*/,
196                                tr ? ((*uplo_P(x) == 'U') ? 1 : -1) : 0,                                tri ? ((*uplo_P(x) == 'U') ? 1 : -1) : 0,
197                                0, tr ? diag_P(x) : "",                                /* Rkind: pattern */ 0,
198                                  /* diag = */ tri ? diag_P(x) : "",
199                                GET_SLOT(x, Matrix_DimNamesSym));                                GET_SLOT(x, Matrix_DimNamesSym));
200  }  }
201    SEXP Csparse_to_nz_pattern(SEXP x, SEXP tri)
202    {
203        int tr_ = asLogical(tri);
204        if(tr_ == NA_LOGICAL) {
205            warning(_("Csparse_to_nz_pattern(x, tri = NA): 'tri' is taken as TRUE"));
206            tr_ = TRUE;
207        }
208        return Csparse2nz(x, (Rboolean) tr_);
209    }
210    
211  // n.CMatrix --> [dli].CMatrix  (not going through CHM!)  // n.CMatrix --> [dli].CMatrix  (not going through CHM!)
212  SEXP nz_pattern_to_Csparse(SEXP x, SEXP res_kind)  SEXP nz_pattern_to_Csparse(SEXP x, SEXP res_kind)
213  {  {
214      return nz2Csparse(x, asInteger(res_kind));      return nz2Csparse(x, asInteger(res_kind));
215  }  }
216    
217  // n.CMatrix --> [dli].CMatrix  (not going through CHM!)  // n.CMatrix --> [dli].CMatrix  (not going through CHM!)
218    // NOTE: use chm_MOD_xtype(() to change type of  'cholmod_sparse' matrix
219  SEXP nz2Csparse(SEXP x, enum x_slot_kind r_kind)  SEXP nz2Csparse(SEXP x, enum x_slot_kind r_kind)
220  {  {
221      const char *cl_x = class_P(x);      const char *cl_x = class_P(x);
# Line 186  Line 264 
264      return ans;      return ans;
265  }  }
266    
267  SEXP Csparse_to_matrix(SEXP x, SEXP chk)  SEXP Csparse_to_matrix(SEXP x, SEXP chk, SEXP symm)
268  {  {
269      return chm_dense_to_matrix(cholmod_sparse_to_dense(AS_CHM_SP2(x, asLogical(chk)), &c),      int is_sym = asLogical(symm);
270                                 1 /*do_free*/, GET_SLOT(x, Matrix_DimNamesSym));      if(is_sym == NA_LOGICAL) { // find if  is(x, "symmetricMatrix") :
271            static const char *valid[] = { MATRIX_VALID_Csparse, ""};
272            int ctype = Matrix_check_class_etc(x, valid);
273            is_sym = (ctype % 3 == 1);
274        }
275        return chm_dense_to_matrix(
276            cholmod_sparse_to_dense(AS_CHM_SP2(x, asLogical(chk)), &c),
277            1 /*do_free*/,
278            (is_sym
279             ? symmetric_DimNames(GET_SLOT(x, Matrix_DimNamesSym))
280             :                    GET_SLOT(x, Matrix_DimNamesSym)));
281  }  }
282    
283  SEXP Csparse_to_vector(SEXP x)  SEXP Csparse_to_vector(SEXP x)
284  {  {
285      return chm_dense_to_vector(cholmod_sparse_to_dense(AS_CHM_SP__(x), &c), 1);      return chm_dense_to_vector(cholmod_sparse_to_dense(AS_CHM_SP__(x), &c), 1);
# Line 210  Line 299 
299                                 GET_SLOT(x, Matrix_DimNamesSym));                                 GET_SLOT(x, Matrix_DimNamesSym));
300  }  }
301    
302  /* this used to be called  sCMatrix_to_gCMatrix(..)   [in ./dsCMatrix.c ]: */  SEXP Csparse_to_tCsparse(SEXP x, SEXP uplo, SEXP diag)
303    {
304        CHM_SP chxs = AS_CHM_SP__(x);
305        int Rkind = (chxs->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
306        R_CheckStack();
307        return chm_sparse_to_SEXP(chxs, /* dofree = */ 0,
308                                  /* uploT = */ (*CHAR(asChar(uplo)) == 'U')? 1: -1,
309                                   Rkind, /* diag = */ CHAR(STRING_ELT(diag, 0)),
310                                   GET_SLOT(x, Matrix_DimNamesSym));
311    }
312    
313    SEXP Csparse_to_tTsparse(SEXP x, SEXP uplo, SEXP diag)
314    {
315        CHM_SP chxs = AS_CHM_SP__(x);
316        CHM_TR chxt = cholmod_sparse_to_triplet(chxs, &c);
317        int Rkind = (chxs->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
318        R_CheckStack();
319        return chm_triplet_to_SEXP(chxt, 1,
320                                  /* uploT = */ (*CHAR(asChar(uplo)) == 'U')? 1: -1,
321                                   Rkind, /* diag = */ CHAR(STRING_ELT(diag, 0)),
322                                   GET_SLOT(x, Matrix_DimNamesSym));
323    }
324    
325    
326  SEXP Csparse_symmetric_to_general(SEXP x)  SEXP Csparse_symmetric_to_general(SEXP x)
327  {  {
328      CHM_SP chx = AS_CHM_SP__(x), chgx;      CHM_SP chx = AS_CHM_SP__(x), chgx;
# Line 222  Line 334 
334      chgx = cholmod_copy(chx, /* stype: */ 0, chx->xtype, &c);      chgx = cholmod_copy(chx, /* stype: */ 0, chx->xtype, &c);
335      /* xtype: pattern, "real", complex or .. */      /* xtype: pattern, "real", complex or .. */
336      return chm_sparse_to_SEXP(chgx, 1, 0, Rkind, "",      return chm_sparse_to_SEXP(chgx, 1, 0, Rkind, "",
337                                GET_SLOT(x, Matrix_DimNamesSym));                                symmetric_DimNames(GET_SLOT(x, Matrix_DimNamesSym)));
338  }  }
339    
340  SEXP Csparse_general_to_symmetric(SEXP x, SEXP uplo)  SEXP Csparse_general_to_symmetric(SEXP x, SEXP uplo, SEXP sym_dmns)
341  {  {
342      int *adims = INTEGER(GET_SLOT(x, Matrix_DimSym)), n = adims[0];      int *adims = INTEGER(GET_SLOT(x, Matrix_DimSym)), n = adims[0];
343      if(n != adims[1]) {      if(n != adims[1]) {
# Line 233  Line 345 
345          return R_NilValue; /* -Wall */          return R_NilValue; /* -Wall */
346      }      }
347      CHM_SP chx = AS_CHM_SP__(x), chgx;      CHM_SP chx = AS_CHM_SP__(x), chgx;
348      int uploT = (*CHAR(STRING_ELT(uplo,0)) == 'U') ? 1 : -1;      int uploT = (*CHAR(asChar(uplo)) == 'U') ? 1 : -1;
349      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;      int Rkind = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0;
350      R_CheckStack();      R_CheckStack();
351      chgx = cholmod_copy(chx, /* stype: */ uploT, chx->xtype, &c);      chgx = cholmod_copy(chx, /* stype: */ uploT, chx->xtype, &c);
352    
353        SEXP dns = GET_SLOT(x, Matrix_DimNamesSym);
354        if(asLogical(sym_dmns))
355            dns = symmetric_DimNames(dns);
356        else if((!isNull(VECTOR_ELT(dns, 0)) &&
357                 !isNull(VECTOR_ELT(dns, 1))) ||
358                !isNull(getAttrib(dns, R_NamesSymbol))) {
359            /* symmetrize them if both are not NULL
360             * or names(dimnames(.)) is asymmetric : */
361            dns = PROTECT(duplicate(dns));
362            if(!equal_string_vectors(VECTOR_ELT(dns, 0),
363                                     VECTOR_ELT(dns, 1))) {
364                if(uploT == 1)
365                    SET_VECTOR_ELT(dns, 0, VECTOR_ELT(dns,1));
366                else
367                    SET_VECTOR_ELT(dns, 1, VECTOR_ELT(dns,0));
368            }
369            SEXP nms_dns = getAttrib(dns, R_NamesSymbol);
370            if(!isNull(nms_dns) &&  // names(dimnames(.)) :
371               !R_compute_identical(STRING_ELT(nms_dns, 0),
372                                    STRING_ELT(nms_dns, 1), 16)) {
373                if(uploT == 1)
374                    SET_STRING_ELT(nms_dns, 0, STRING_ELT(nms_dns,1));
375                else
376                    SET_STRING_ELT(nms_dns, 1, STRING_ELT(nms_dns,0));
377                setAttrib(dns, R_NamesSymbol, nms_dns);
378            }
379            UNPROTECT(1);
380        }
381      /* xtype: pattern, "real", complex or .. */      /* xtype: pattern, "real", complex or .. */
382      return chm_sparse_to_SEXP(chgx, 1, 0, Rkind, "",      return chm_sparse_to_SEXP(chgx, 1, 0, Rkind, "", dns);
                               GET_SLOT(x, Matrix_DimNamesSym));  
383  }  }
384    
385  SEXP Csparse_transpose(SEXP x, SEXP tri)  SEXP Csparse_transpose(SEXP x, SEXP tri)
# Line 256  Line 396 
396      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */      tmp = VECTOR_ELT(dn, 0);    /* swap the dimnames */
397      SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));      SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));
398      SET_VECTOR_ELT(dn, 1, tmp);      SET_VECTOR_ELT(dn, 1, tmp);
399        if(!isNull(tmp = getAttrib(dn, R_NamesSymbol))) { // swap names(dimnames(.)):
400            SEXP nms_dns = PROTECT(allocVector(VECSXP, 2));
401            SET_VECTOR_ELT(nms_dns, 1, STRING_ELT(tmp, 0));
402            SET_VECTOR_ELT(nms_dns, 0, STRING_ELT(tmp, 1));
403            setAttrib(dn, R_NamesSymbol, nms_dns);
404            UNPROTECT(1);
405        }
406      UNPROTECT(1);      UNPROTECT(1);
407      return chm_sparse_to_SEXP(chxt, 1, /* SWAP 'uplo' for triangular */      return chm_sparse_to_SEXP(chxt, 1, /* SWAP 'uplo' for triangular */
408                                tr ? ((*uplo_P(x) == 'U') ? -1 : 1) : 0,                                tr ? ((*uplo_P(x) == 'U') ? -1 : 1) : 0,
409                                Rkind, tr ? diag_P(x) : "", dn);                                Rkind, tr ? diag_P(x) : "", dn);
410  }  }
411    
412  SEXP Csparse_Csparse_prod(SEXP a, SEXP b)  /* NOTA BENE:  cholmod_ssmult(A,B, ...) ->  ./CHOLMOD/MatrixOps/cholmod_ssmult.c
413     * ---------  computes a patter*n* matrix __always_ when
414     * *one* of A or B is pattern*n*, because of this (line 73-74):
415       ---------------------------------------------------------------------------
416        values = values &&
417            (A->xtype != CHOLMOD_PATTERN) && (B->xtype != CHOLMOD_PATTERN) ;
418       ---------------------------------------------------------------------------
419     * ==> Often need to copy the patter*n* to a *l*ogical matrix first !!!
420     */
421    
422    SEXP Csparse_Csparse_prod(SEXP a, SEXP b, SEXP bool_arith)
423  {  {
424      CHM_SP      CHM_SP
425          cha = AS_CHM_SP(a),          cha = AS_CHM_SP(a),
426          chb = AS_CHM_SP(b),          chb = AS_CHM_SP(b), chc;
         chc = cholmod_ssmult(cha, chb, /*out_stype:*/ 0,  
                                /* values:= is_numeric (T/F) */ cha->xtype > 0,  
                                /*out sorted:*/ 1, &c);  
     const char *cl_a = class_P(a), *cl_b = class_P(b);  
     char diag[] = {'\0', '\0'};  
     int uploT = 0;  
     SEXP dn = PROTECT(allocVector(VECSXP, 2));  
427      R_CheckStack();      R_CheckStack();
428        // const char *cl_a = class_P(a), *cl_b = class_P(b);
429        static const char *valid_tri[] = { MATRIX_VALID_tri_Csparse, "" };
430        char diag[] = {'\0', '\0'};
431        int uploT = 0, nprot = 1,
432            do_bool = asLogical(bool_arith); // TRUE / NA / FALSE
433        Rboolean
434            a_is_n = (cha->xtype == CHOLMOD_PATTERN),
435            b_is_n = (chb->xtype == CHOLMOD_PATTERN),
436            force_num = (do_bool == FALSE),
437            maybe_bool= (do_bool == NA_LOGICAL);
438    
439  #ifdef DEBUG_Matrix_verbose  #ifdef DEBUG_Matrix_verbose
440      Rprintf("DBG Csparse_C*_prod(%s, %s)\n", cl_a, cl_b);      Rprintf("DBG Csparse_C*_prod(%s, %s)\n", class_P(a), class_P(b));
441  #endif  #endif
442    
443        if(a_is_n && (force_num || (maybe_bool && !b_is_n))) {
444            /* coerce 'a' to  double;
445             * have no CHOLMOD function (pattern -> logical) --> use "our" code */
446            SEXP da = PROTECT(nz2Csparse(a, x_double)); nprot++;
447            cha = AS_CHM_SP(da);
448            R_CheckStack();
449            a_is_n = FALSE;
450        }
451        else if(b_is_n && (force_num || (maybe_bool && !a_is_n))) {
452            // coerce 'b' to  double
453            SEXP db = PROTECT(nz2Csparse(b, x_double)); nprot++;
454            chb = AS_CHM_SP(db);
455            R_CheckStack();
456            b_is_n = FALSE;
457        }
458        chc = cholmod_ssmult(cha, chb, /*out_stype:*/ 0,
459                             /* values : */ do_bool != TRUE,
460                             /* sorted = TRUE: */ 1, &c);
461    
462      /* Preserve triangularity and even unit-triangularity if appropriate.      /* Preserve triangularity and even unit-triangularity if appropriate.
463       * Note that in that case, the multiplication itself should happen       * Note that in that case, the multiplication itself should happen
464       * faster.  But there's no support for that in CHOLMOD */       * faster.  But there's no support for that in CHOLMOD */
465    
466      /* UGLY hack -- rather should have (fast!) C-level version of      if(Matrix_check_class_etc(a, valid_tri) >= 0 &&
467       *       is(a, "triangularMatrix") etc */         Matrix_check_class_etc(b, valid_tri) >= 0)
     if (cl_a[1] == 't' && cl_b[1] == 't')  
         /* FIXME: fails for "Cholesky","BunchKaufmann"..*/  
468          if(*uplo_P(a) == *uplo_P(b)) { /* both upper, or both lower tri. */          if(*uplo_P(a) == *uplo_P(b)) { /* both upper, or both lower tri. */
469              uploT = (*uplo_P(a) == 'U') ? 1 : -1;              uploT = (*uplo_P(a) == 'U') ? 1 : -1;
470              if(*diag_P(a) == 'U' && *diag_P(b) == 'U') { /* return UNIT-triag. */              if(*diag_P(a) == 'U' && *diag_P(b) == 'U') { /* return UNIT-triag. */
# Line 297  Line 474 
474              }              }
475              else diag[0]= 'N';              else diag[0]= 'N';
476          }          }
477    
478        SEXP dn = PROTECT(allocVector(VECSXP, 2));
479      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
480                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 0)));                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 0)));
481      SET_VECTOR_ELT(dn, 1,      SET_VECTOR_ELT(dn, 1,
482                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), 1)));
483      UNPROTECT(1);      UNPROTECT(nprot);
484      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);
485  }  }
486    
487  SEXP Csparse_Csparse_crossprod(SEXP a, SEXP b, SEXP trans)  /* trans = FALSE:  crossprod(a,b)
488     * trans = TRUE : tcrossprod(a,b) */
489    SEXP Csparse_Csparse_crossprod(SEXP a, SEXP b, SEXP trans, SEXP bool_arith)
490  {  {
491      int tr = asLogical(trans);      int tr = asLogical(trans), nprot = 1,
492            do_bool = asLogical(bool_arith); // TRUE / NA / FALSE
493      CHM_SP      CHM_SP
494          cha = AS_CHM_SP(a),          cha = AS_CHM_SP(a),
495          chb = AS_CHM_SP(b),          chb = AS_CHM_SP(b),
496          chTr, chc;          chTr, chc;
497      const char *cl_a = class_P(a), *cl_b = class_P(b);      R_CheckStack();
498        static const char *valid_tri[] = { MATRIX_VALID_tri_Csparse, "" };
499      char diag[] = {'\0', '\0'};      char diag[] = {'\0', '\0'};
500      int uploT = 0;      int uploT = 0;
501      SEXP dn = PROTECT(allocVector(VECSXP, 2));      Rboolean
502      R_CheckStack();          a_is_n = (cha->xtype == CHOLMOD_PATTERN),
503            b_is_n = (chb->xtype == CHOLMOD_PATTERN),
504            force_num = (do_bool == FALSE),
505            maybe_bool= (do_bool == NA_LOGICAL);
506    
507        if(a_is_n && (force_num || (maybe_bool && !b_is_n))) {
508            // coerce 'a' to  double
509            SEXP da = PROTECT(nz2Csparse(a, x_double)); nprot++;
510            cha = AS_CHM_SP(da);
511            R_CheckStack();
512            // a_is_n = FALSE;
513        }
514        else if(b_is_n && (force_num || (maybe_bool && !a_is_n))) {
515            // coerce 'b' to  double
516            SEXP db = PROTECT(nz2Csparse(b, x_double)); nprot++;
517            chb = AS_CHM_SP(db);
518            R_CheckStack();
519            // b_is_n = FALSE;
520        }
521        else if(do_bool == TRUE) { // Want boolean arithmetic: sufficient if *one* is pattern:
522            if(!a_is_n && !b_is_n) {
523                // coerce 'a' to pattern
524                SEXP da = PROTECT(Csparse2nz(a, /* tri = */
525                                             Matrix_check_class_etc(a, valid_tri) >= 0)); nprot++;
526                cha = AS_CHM_SP(da);
527                R_CheckStack();
528                // a_is_n = TRUE;
529            }
530        }
531      chTr = cholmod_transpose((tr) ? chb : cha, chb->xtype, &c);      chTr = cholmod_transpose((tr) ? chb : cha, chb->xtype, &c);
532      chc = cholmod_ssmult((tr) ? cha : chTr, (tr) ? chTr : chb,      chc = cholmod_ssmult((tr) ? cha : chTr, (tr) ? chTr : chb,
533                           /*out_stype:*/ 0, cha->xtype, /*out sorted:*/ 1, &c);                           /*out_stype:*/ 0, /* values : */ do_bool != TRUE,
534                             /* sorted = TRUE: */ 1, &c);
535      cholmod_free_sparse(&chTr, &c);      cholmod_free_sparse(&chTr, &c);
536    
537      /* Preserve triangularity and unit-triangularity if appropriate;      /* Preserve triangularity and unit-triangularity if appropriate;
538       * see Csparse_Csparse_prod() for comments */       * see Csparse_Csparse_prod() for comments */
539      if (cl_a[1] == 't' && cl_b[1] == 't')      if(Matrix_check_class_etc(a, valid_tri) >= 0 &&
540           Matrix_check_class_etc(b, valid_tri) >= 0)
541          if(*uplo_P(a) != *uplo_P(b)) { /* one 'U', the other 'L' */          if(*uplo_P(a) != *uplo_P(b)) { /* one 'U', the other 'L' */
542              uploT = (*uplo_P(b) == 'U') ? 1 : -1;              uploT = (*uplo_P(b) == 'U') ? 1 : -1;
543              if(*diag_P(a) == 'U' && *diag_P(b) == 'U') { /* return UNIT-triag. */              if(*diag_P(a) == 'U' && *diag_P(b) == 'U') { /* return UNIT-triag. */
# Line 334  Line 546 
546              }              }
547              else diag[0]= 'N';              else diag[0]= 'N';
548          }          }
549    
550        SEXP dn = PROTECT(allocVector(VECSXP, 2));
551      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
552                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), (tr) ? 0 : 1)));                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym),
553                                            (tr) ? 0 : 1)));
554      SET_VECTOR_ELT(dn, 1,      SET_VECTOR_ELT(dn, 1,
555                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym), (tr) ? 0 : 1)));                     duplicate(VECTOR_ELT(GET_SLOT(b, Matrix_DimNamesSym),
556      UNPROTECT(1);                                          (tr) ? 0 : 1)));
557        UNPROTECT(nprot);
558      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);      return chm_sparse_to_SEXP(chc, 1, uploT, /*Rkind*/0, diag, dn);
559  }  }
560    
561  SEXP Csparse_dense_prod(SEXP a, SEXP b)  /**
562     * All (dense * sparse)  Matrix products and cross products
563     *
564     *   f( f(<Csparse>)  %*%  f(<dense>) )   for  f in {t(), identity()}
565     *
566     * @param a CsparseMatrix  (n x m)
567     * @param b numeric vector, matrix, or denseMatrix (m x k) or (k x m)  if `transp` is '2' or 'B'
568     * @param transp character.
569     *        = " " : nothing transposed {apart from a}
570     *        = "2" : "transpose 2nd arg": use  t(b) instead of b (= 2nd argument)
571     *        = "c" : "transpose c":       Return  t(c) instead of c
572     *        = "B" : "transpose both":    use t(b) and return t(c) instead of c
573     * NB: For "2", "c", "B", need to transpose a *dense* matrix, B or C --> chm_transpose_dense()
574     *
575     * @return a dense matrix, the matrix product c = g(a,b) :
576     *
577     *                                                Condition (R)   Condition (C)
578     *   R notation            Math notation          cross  transp   t.a t.b t.ans
579     *   ~~~~~~~~~~~~~~~~~     ~~~~~~~~~~~~~~~~~~     ~~~~~~~~~~~~~   ~~~~~~~~~~~~~
580     *   c <-   a %*%   b      C :=      A B            .       " "    .   .   .
581     *   c <-   a %*% t(b)     C :=      A B'           .       "2"    .   |   .
582     *   c <- t(a %*%   b)     C := (A B)'  = B'A'      .       "c"    .   .   |
583     *   c <- t(a %*% t(b))    C := (A B')' = B A'      .       "B"    .   |   |
584     *
585     *   c <-   t(a) %*%   b   C :=      A'B           TRUE     " "    |   .   .
586     *   c <-   t(a) %*% t(b)  C :=      A'B'          TRUE     "2"    |   |   .
587     *   c <- t(t(a) %*%   b)  C := (A'B)'  = B'A      TRUE     "c"    |   .   |
588     *   c <- t(t(a) %*% t(b)) C := (A'B')' = B A      TRUE     "B"    |   |   |
589     */
590    SEXP Csp_dense_products(SEXP a, SEXP b,
591                            Rboolean transp_a, Rboolean transp_b, Rboolean transp_ans)
592  {  {
593      CHM_SP cha = AS_CHM_SP(a);      CHM_SP cha = AS_CHM_SP(a);
594      SEXP b_M = PROTECT(mMatrix_as_dgeMatrix2(b, // transpose_if_vector =      int a_nc = transp_a ? cha->nrow : cha->ncol,
595                                               cha->ncol == 1));          a_nr = transp_a ? cha->ncol : cha->nrow;
596      CHM_DN chb = AS_CHM_DN(b_M);      Rboolean
597      CHM_DN chc = cholmod_allocate_dense(cha->nrow, chb->ncol, cha->nrow,          maybe_transp_b = (a_nc == 1),
598                                          chb->xtype, &c);          b_is_vector = FALSE;
599      SEXP dn = PROTECT(allocVector(VECSXP, 2));      /* NOTE: trans_b {<--> "use t(b) instead of b" }
600           ----  "interferes" with the  case automatic treatment of *vector* b.
601           In that case,  t(b) or b is used "whatever make more sense",
602           according to the general R philosophy of treating vectors in matrix products.
603        */
604    
605        /* repeating a "cheap part" of  mMatrix_as_dgeMatrix2(b, .)  to see if
606         * we have a vector that we might 'transpose_if_vector' : */
607        static const char *valid[] = {"_NOT_A_CLASS_", MATRIX_VALID_ddense, ""};
608        /* int ctype = Matrix_check_class_etc(b, valid);
609         * if (ctype > 0)   /.* a ddenseMatrix object */
610        if (Matrix_check_class_etc(b, valid) < 0) {
611            // not a ddenseM*:  is.matrix() or vector:
612            b_is_vector = !isMatrix(b);
613        }
614    
615        if(b_is_vector) {
616            /* determine *if* we want/need to transpose at all:
617             * if (length(b) == ncol(A)) have match: use dim = c(n, 1) (<=> do *not* transp);
618             *  otherwise, try to transpose: ok  if (ncol(A) == 1) [see also above]:  */
619            maybe_transp_b = (LENGTH(b) != a_nc);
620            // Here, we transpose already in mMatrix_as_dge*()  ==> don't do it later:
621            transp_b = FALSE;
622        }
623        SEXP b_M = PROTECT(mMatrix_as_dgeMatrix2(b, maybe_transp_b));
624    
625        CHM_DN chb = AS_CHM_DN(b_M), b_t;
626        R_CheckStack();
627        int ncol_b;
628        if(transp_b) { // transpose b:
629            b_t = cholmod_allocate_dense(chb->ncol, chb->nrow, chb->ncol, chb->xtype, &c);
630            chm_transpose_dense(b_t, chb);
631            ncol_b = b_t->ncol;
632        } else
633            ncol_b = chb->ncol;
634        // Result C {with dim() before it may be transposed}:
635        CHM_DN chc = cholmod_allocate_dense(a_nr, ncol_b, a_nr, chb->xtype, &c);
636      double one[] = {1,0}, zero[] = {0,0};      double one[] = {1,0}, zero[] = {0,0};
637      int nprot = 2;      int nprot = 2;
638      R_CheckStack();  
639      /* Tim Davis, please FIXME:  currently (2010-11) *fails* when  a  is a pattern matrix:*/      /* Tim Davis, please FIXME:  currently (2010-11) *fails* when  a  is a pattern matrix:*/
640      if(cha->xtype == CHOLMOD_PATTERN) {      if(cha->xtype == CHOLMOD_PATTERN) {
641          /* warning(_("Csparse_dense_prod(): cholmod_sdmult() not yet implemented for pattern./ ngCMatrix" */          /* warning(_("Csparse_dense_prod(): cholmod_sdmult() not yet implemented for pattern./ ngCMatrix" */
# Line 365  Line 647 
647          SEXP da = PROTECT(nz2Csparse(a, x_double)); nprot++;          SEXP da = PROTECT(nz2Csparse(a, x_double)); nprot++;
648          cha = AS_CHM_SP(da);          cha = AS_CHM_SP(da);
649      }      }
650      cholmod_sdmult(cha, 0, one, zero, chb, chc, &c);  
651      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      /* cholmod_sdmult(A, transp, alpha, beta, X,  Y,  &c): depending on transp == 0 / != 0:
652                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 0)));       *  Y := alpha*(A*X) + beta*Y or alpha*(A'*X) + beta*Y;  here, alpha = 1, beta = 0:
653      SET_VECTOR_ELT(dn, 1,       *  Y := A*X  or  A'*X
654                     duplicate(VECTOR_ELT(GET_SLOT(b_M, Matrix_DimNamesSym), 1)));       *                       NB: always  <sparse> %*% <dense> !
655         */
656        cholmod_sdmult(cha, transp_a, one, zero, (transp_b ? b_t : chb), /* -> */ chc, &c);
657    
658        SEXP dn = PROTECT(allocVector(VECSXP, 2));  /* establish dimnames */
659        SET_VECTOR_ELT(dn, transp_ans ? 1 : 0,
660                       duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), transp_a ? 1 : 0)));
661        SET_VECTOR_ELT(dn, transp_ans ? 0 : 1,
662                       duplicate(VECTOR_ELT(GET_SLOT(b_M, Matrix_DimNamesSym),
663                                            transp_b ? 0 : 1)));
664        if(transp_b) cholmod_free_dense(&b_t, &c);
665      UNPROTECT(nprot);      UNPROTECT(nprot);
666      return chm_dense_to_SEXP(chc, 1, 0, dn);      return chm_dense_to_SEXP(chc, 1, 0, dn, transp_ans);
667  }  }
668    
669  SEXP Csparse_dense_crossprod(SEXP a, SEXP b)  
670    SEXP Csparse_dense_prod(SEXP a, SEXP b, SEXP transp)
671  {  {
672      CHM_SP cha = AS_CHM_SP(a);      return
673      SEXP b_M = PROTECT(mMatrix_as_dgeMatrix2(b, // transpose_if_vector =          Csp_dense_products(a, b,
674                                               cha->nrow == 1));                  /* transp_a = */ FALSE,
675      CHM_DN chb = AS_CHM_DN(b_M);                  /* transp_b   = */ (*CHAR(asChar(transp)) == '2' || *CHAR(asChar(transp)) == 'B'),
676      CHM_DN chc = cholmod_allocate_dense(cha->ncol, chb->ncol, cha->ncol,                  /* transp_ans = */ (*CHAR(asChar(transp)) == 'c' || *CHAR(asChar(transp)) == 'B'));
                                         chb->xtype, &c);  
     SEXP dn = PROTECT(allocVector(VECSXP, 2)); int nprot = 2;  
     double one[] = {1,0}, zero[] = {0,0};  
     R_CheckStack();  
     // -- see Csparse_dense_prod() above :  
     if(cha->xtype == CHOLMOD_PATTERN) {  
         SEXP da = PROTECT(nz2Csparse(a, x_double)); nprot++;  
         cha = AS_CHM_SP(da);  
677      }      }
678      cholmod_sdmult(cha, 1, one, zero, chb, chc, &c);  
679      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */  SEXP Csparse_dense_crossprod(SEXP a, SEXP b, SEXP transp)
680                     duplicate(VECTOR_ELT(GET_SLOT(a, Matrix_DimNamesSym), 1)));  {
681      SET_VECTOR_ELT(dn, 1,      return
682                     duplicate(VECTOR_ELT(GET_SLOT(b_M, Matrix_DimNamesSym), 1)));          Csp_dense_products(a, b,
683      UNPROTECT(nprot);                  /* transp_a = */ TRUE,
684      return chm_dense_to_SEXP(chc, 1, 0, dn);                  /* transp_b   = */ (*CHAR(asChar(transp)) == '2' || *CHAR(asChar(transp)) == 'B'),
685                    /* transp_ans = */ (*CHAR(asChar(transp)) == 'c' || *CHAR(asChar(transp)) == 'B'));
686  }  }
687    
688    
689  /* Computes   x'x  or  x x' -- *also* for Tsparse (triplet = TRUE)  /* Computes   x'x  or  x x' -- *also* for Tsparse (triplet = TRUE)
690     see Csparse_Csparse_crossprod above for  x'y and x y' */     see Csparse_Csparse_crossprod above for  x'y and x y' */
691  SEXP Csparse_crossprod(SEXP x, SEXP trans, SEXP triplet)  SEXP Csparse_crossprod(SEXP x, SEXP trans, SEXP triplet, SEXP bool_arith)
692  {  {
693      int trip = asLogical(triplet),      int tripl = asLogical(triplet),
694          tr   = asLogical(trans); /* gets reversed because _aat is tcrossprod */          tr   = asLogical(trans), /* gets reversed because _aat is tcrossprod */
695            do_bool = asLogical(bool_arith); // TRUE / NA / FALSE
696  #ifdef AS_CHM_DIAGU2N_FIXED_FINALLY  #ifdef AS_CHM_DIAGU2N_FIXED_FINALLY
697      CHM_TR cht = trip ? AS_CHM_TR(x) : (CHM_TR) NULL;      CHM_TR cht = tripl ? AS_CHM_TR(x) : (CHM_TR) NULL;  int nprot = 1;
698  #else /* workaround needed:*/  #else /* workaround needed:*/
699      SEXP xx = PROTECT(Tsparse_diagU2N(x));      SEXP xx = PROTECT(Tsparse_diagU2N(x));
700      CHM_TR cht = trip ? AS_CHM_TR__(xx) : (CHM_TR) NULL;      CHM_TR cht = tripl ? AS_CHM_TR__(xx) : (CHM_TR) NULL; int nprot = 2;
701  #endif  #endif
702      CHM_SP chcp, chxt,      CHM_SP chcp, chxt,
703          chx = (trip ?          chx = (tripl ?
704                 cholmod_triplet_to_sparse(cht, cht->nnz, &c) :                 cholmod_triplet_to_sparse(cht, cht->nnz, &c) :
705                 AS_CHM_SP(x));                 AS_CHM_SP(x));
706      SEXP dn = PROTECT(allocVector(VECSXP, 2));      SEXP dn = PROTECT(allocVector(VECSXP, 2));
707      R_CheckStack();      R_CheckStack();
708        Rboolean
709            x_is_n = (chx->xtype == CHOLMOD_PATTERN),
710            force_num = (do_bool == FALSE);
711    
712        if(x_is_n && force_num) {
713            // coerce 'x' to  double
714            SEXP dx = PROTECT(nz2Csparse(x, x_double)); nprot++;
715            chx = AS_CHM_SP(dx);
716            R_CheckStack();
717        }
718        else if(do_bool == TRUE && !x_is_n) { // Want boolean arithmetic; need patter[n]
719            // coerce 'x' to pattern
720            static const char *valid_tri[] = { MATRIX_VALID_tri_Csparse, "" };
721            SEXP dx = PROTECT(Csparse2nz(x, /* tri = */
722                                         Matrix_check_class_etc(x, valid_tri) >= 0)); nprot++;
723            chx = AS_CHM_SP(dx);
724            R_CheckStack();
725        }
726    
727      if (!tr) chxt = cholmod_transpose(chx, chx->xtype, &c);      if (!tr) chxt = cholmod_transpose(chx, chx->xtype, &c);
728      chcp = cholmod_aat((!tr) ? chxt : chx, (int *) NULL, 0, chx->xtype, &c);  
729        chcp = cholmod_aat((!tr) ? chxt : chx, (int *) NULL, 0,
730                           /* mode: */ chx->xtype, &c);
731      if(!chcp) {      if(!chcp) {
732          UNPROTECT(1);          UNPROTECT(1);
733          error(_("Csparse_crossprod(): error return from cholmod_aat()"));          error(_("Csparse_crossprod(): error return from cholmod_aat()"));
734      }      }
735      cholmod_band_inplace(0, chcp->ncol, chcp->xtype, chcp, &c);      cholmod_band_inplace(0, chcp->ncol, chcp->xtype, chcp, &c);
736      chcp->stype = 1;      chcp->stype = 1; // symmetric
737      if (trip) cholmod_free_sparse(&chx, &c);      if (tripl) cholmod_free_sparse(&chx, &c);
738      if (!tr) cholmod_free_sparse(&chxt, &c);      if (!tr) cholmod_free_sparse(&chxt, &c);
739      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */      SET_VECTOR_ELT(dn, 0,       /* establish dimnames */
740                     duplicate(VECTOR_ELT(GET_SLOT(x, Matrix_DimNamesSym),                     duplicate(VECTOR_ELT(GET_SLOT(x, Matrix_DimNamesSym),
741                                          (tr) ? 0 : 1)));                                          (tr) ? 0 : 1)));
742      SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));      SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));
743  #ifdef AS_CHM_DIAGU2N_FIXED_FINALLY      UNPROTECT(nprot);
744      UNPROTECT(1);      // FIXME: uploT for symmetric ?
 #else  
     UNPROTECT(2);  
 #endif  
745      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);      return chm_sparse_to_SEXP(chcp, 1, 0, 0, "", dn);
746  }  }
747    
# Line 463  Line 768 
768    
769  SEXP Csparse_horzcat(SEXP x, SEXP y)  SEXP Csparse_horzcat(SEXP x, SEXP y)
770  {  {
771      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);  #define CSPARSE_CAT(_KIND_)                                             \
772      int Rk_x = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0,      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);                  \
773          Rk_y = (chy->xtype != CHOLMOD_PATTERN) ? Real_kind(y) : 0,      R_CheckStack();                                                     \
774          Rkind = /* logical if both x and y are */ (Rk_x == 1 && Rk_y == 1) ? 1 : 0;      int Rk_x = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : -3,     \
775      R_CheckStack();          Rk_y = (chy->xtype != CHOLMOD_PATTERN) ? Real_kind(y) : -3, Rkind; \
776        if(Rk_x == -3 || Rk_y == -3) { /* at least one of them is patter"n" */ \
777            if(Rk_x == -3 && Rk_y == -3) { /* fine */                       \
778            } else { /* only one is a patter"n"                             \
779                      * "Bug" in cholmod_horzcat()/vertcat(): returns patter"n" matrix if one of them is */ \
780                Rboolean ok;                                                \
781                if(Rk_x == -3) {                                            \
782                    ok = chm_MOD_xtype(CHOLMOD_REAL, chx, &c); Rk_x = 0;    \
783                } else if(Rk_y == -3) {                                     \
784                    ok = chm_MOD_xtype(CHOLMOD_REAL, chy, &c); Rk_y = 0;    \
785                } else                                                      \
786                    error(_("Impossible Rk_x/Rk_y in Csparse_%s(), please report"), _KIND_); \
787                if(!ok)                                                     \
788                    error(_("chm_MOD_xtype() was not successful in Csparse_%s(), please report"), \
789                          _KIND_);                                          \
790            }                                                               \
791        }                                                                   \
792        Rkind = /* logical if both x and y are */ (Rk_x == 1 && Rk_y == 1) ? 1 : 0
793    
794        CSPARSE_CAT("horzcat");
795        // TODO: currently drops dimnames - and we fix at R level;
796    
     /* TODO: currently drops dimnames - and we fix at R level */  
797      return chm_sparse_to_SEXP(cholmod_horzcat(chx, chy, 1, &c),      return chm_sparse_to_SEXP(cholmod_horzcat(chx, chy, 1, &c),
798                                1, 0, Rkind, "", R_NilValue);                                1, 0, Rkind, "", R_NilValue);
799  }  }
800    
801  SEXP Csparse_vertcat(SEXP x, SEXP y)  SEXP Csparse_vertcat(SEXP x, SEXP y)
802  {  {
803      CHM_SP chx = AS_CHM_SP__(x), chy = AS_CHM_SP__(y);      CSPARSE_CAT("vertcat");
804      int Rk_x = (chx->xtype != CHOLMOD_PATTERN) ? Real_kind(x) : 0,      // TODO: currently drops dimnames - and we fix at R level;
         Rk_y = (chy->xtype != CHOLMOD_PATTERN) ? Real_kind(y) : 0,  
         Rkind = /* logical if both x and y are */ (Rk_x == 1 && Rk_y == 1) ? 1 : 0;  
     R_CheckStack();  
805    
     /* TODO: currently drops dimnames - and we fix at R level */  
806      return chm_sparse_to_SEXP(cholmod_vertcat(chx, chy, 1, &c),      return chm_sparse_to_SEXP(cholmod_vertcat(chx, chy, 1, &c),
807                                1, 0, Rkind, "", R_NilValue);                                1, 0, Rkind, "", R_NilValue);
808  }  }
# Line 886  Line 1206 
1206      cholmod_free_triplet(&T, &c);      cholmod_free_triplet(&T, &c);
1207      /* copy the information to the SEXP */      /* copy the information to the SEXP */
1208      ans = PROTECT(NEW_OBJECT(MAKE_CLASS(cls)));      ans = PROTECT(NEW_OBJECT(MAKE_CLASS(cls)));
1209  /* FIXME: This has been copied from chm_sparse_to_SEXP in chm_common.c */  // FIXME: This has been copied from chm_sparse_to_SEXP in  chm_common.c
1210      /* allocate and copy common slots */      /* allocate and copy common slots */
1211      nnz = cholmod_nnz(A, &c);      nnz = cholmod_nnz(A, &c);
1212      dims = INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2));      dims = INTEGER(ALLOC_SLOT(ans, Matrix_DimSym, INTSXP, 2));

Legend:
Removed from v.3018  
changed lines
  Added in v.3072

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