- Notifications
You must be signed in to change notification settings - Fork55
Description
It would nice if RcppArmadillo knew how to deal with all Matrix-objects inheriting fromCsparseMatrix (i.e. all Matrix classes in sorted compressed column-oriented form), not justdgCMatrix. ThengCMatrix-class doesn't have an x-slot, for example, because the entries are all TRUE/FALSE, so the current implementation ofas<arma::sp_mat> fails.
Of course it's usually possible to do a conversion todgCMatrix on the R-side, but that's messy -- right now, in R you have to do something like
as(as(X, "CsparseMatrix"), "dMatrix")
to every Matrix-object you're handing over to RcppArmadillo to be sort-of-safe that it ends up having the correct class -- but the above will still fail to create adgC-matrix if X inherits fromsymmetricMatrix, for example. You have to do the conversion in this roundabout way because, as Martin Maechler explicitly writes in the Matrix docs,as(X, <MatrixClass>) should only be used to convertX to "virtual Matrix super classes" likeCsparseMatrix and not actual classes likedgCMatrix, and there aren't any directas-methods to make adgCMatrix from, say, anngTMatrix or addiMatrix.
These conversions in R can be costly as the matrix gets copied around, it would be more efficient to create thesp_mat directly. If that is too difficult, the RcppArmadillo-converter could at least check the class of its input to give more informative/correct error messages.
Thanks for all your great work on these packages!