1 |
#include "dense.h" |
#include "dense.h" |
2 |
|
#include "Mutils.h" |
3 |
#include "chm_common.h" |
#include "chm_common.h" |
4 |
|
|
5 |
/** |
/** |
246 |
return ans; |
return ans; |
247 |
} |
} |
248 |
|
|
|
/* FIXME: 'dense_' really still means 'ddense_' .. : */ |
|
249 |
SEXP dense_to_Csparse(SEXP x) |
SEXP dense_to_Csparse(SEXP x) |
250 |
{ |
{ |
251 |
cholmod_dense *chxd = as_cholmod_dense(PROTECT(mMatrix_as_dgeMatrix(x))); |
cholmod_dense *chxd = as_cholmod_dense(PROTECT(mMatrix_as_geMatrix(x))); |
252 |
|
/* cholmod_dense_to_sparse() in CHOLMOD/Core/ does work for all 'xtypes' |
253 |
|
including "nMatrix", but cannot keep symmetric / triangular, hence the |
254 |
|
as_geMatrix() above. |
255 |
|
Note that this is already a *waste* for symmetric matrices; |
256 |
|
However, we could conceivable use an enhanced cholmod_dense_to_sparse(), |
257 |
|
with an extra boolean argument for symmetry. |
258 |
|
*/ |
259 |
cholmod_sparse *chxs = cholmod_dense_to_sparse(chxd, 1, &c); |
cholmod_sparse *chxs = cholmod_dense_to_sparse(chxd, 1, &c); |
260 |
int Rkind = 0; /* FIXME : Real_kind(x) does not work: |
int Rkind = (chxd->xtype == CHOLMOD_REAL) ? Real_KIND(x) : 0; |
|
* (chxd->xtype == CHOLMOD_REAL) ? Real_kind(x) : 0; */ |
|
261 |
|
|
262 |
Free(chxd); UNPROTECT(1); |
Free(chxd); UNPROTECT(1); |
263 |
return chm_sparse_to_SEXP(chxs, 1, 0, Rkind, "", |
/* chm_sparse_to_SEXP() *could* deal with symmetric |
264 |
|
* if chxs had such an stype; and we should be able to use uplo below */ |
265 |
|
return chm_sparse_to_SEXP(chxs, 1, 0/*TODO: uplo_P(x) if x has an uplo slot*/, |
266 |
|
Rkind, "", |
267 |
isMatrix(x) ? getAttrib(x, R_DimNamesSymbol) |
isMatrix(x) ? getAttrib(x, R_DimNamesSymbol) |
268 |
: GET_SLOT(x, Matrix_DimNamesSym)); |
: GET_SLOT(x, Matrix_DimNamesSym)); |
269 |
} |
} |