[Rcpp-devel] [RcppArmadillo] Result of Rcpp Wrap() for Sparse Matrix
Douglas Bates
bates at stat.wisc.edu
Tue Jun 13 18:24:28 CEST 2017
On Tue, Jun 13, 2017 at 10:56 AM Binxiang Ni <binxiangni at gmail.com> wrote:
> Hi,
>
> I am working on fixing sparse matrix conversion for RcppArmadillo. Now a
> problem comes up to me: what kind of sparse matrix is expected to pass from
> Armadillo to R? That is, what should the result of wrap() be? dgCMatrix(if
> logical, lgCMatrix or ngCMatrix) or their original type?
>
What do you mean by "their original type"?
It seems that the correspondence is
Armadillo Matrix package
sp_mat <=> dgCMatrix
sp_cx_mat <=> zgCMatrix
sp_imat <=> igCMatrix
After that you are going to need to convert the values vector in the
Armadillo representation to a datatype available in R. (In fact there is
always an implicit conversion because the rowind and colptr vectors are
unsigned integers in Armadillo and integers in R. However that change is
just a cast of a pointer.)
I wouldn't worry about the logical values because LOGICAL in R is just a
32-bit integer. ngCMatrix in R is a pattern matrix which only stores the
positions of the non-zeros, not their values. These are used in the
symbolic phase of many sparse matrix operations, particularly
decompositions. The symbolic phase only uses the pattern of nonzeros. It
doesn't appear that there is a corresponding type in Armadillo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170613/eb1cd0ab/attachment.html>
More information about the Rcpp-devel
mailing list