Closed GabrielHoffman closed 1 month ago
Quick thought: Yes.
Sparse matrices are S4 objects, dense matrices are straight REAL (ie NumericMatrix in Rcpp). You would need to run-time switch around the SEXP. That is the way it is as only talks in terms of SEXP objects both in and out.
This whole nexus is hard and AFAIK one of the reasons Matrix is in S4 to allow the multitude of dense + sparse matrix and vector ops.
Did you make any progress? Would it be ok with you to close this as it seems a little out of scope.
I couldn't figure this out. Before you close, do you have a suggestion about the right place for this question? But I figure if you didn't know, its unlikely someone else would
Oh well, thanks for your help, Gabriel
I think it is a loaded / complicated topic and no I don't have a great alternative venue for it either. :crying_cat_face:
I am writing code using C++/armadillo, and then writing an interface to R with RcppArmadillo.
In this simple example, I want to multiply two matrices and I can use templates to handle cases where the matrices are any combination of
mat
andsp_mat
. This works fine at the C++/armadillo level:But I would like to export a function to R that handles any combination of
mat
andsp_mat
. I could to this "manually", and write an exported functionh_*()
for each combination ofmat
andsp_mat
. This works:But it quickly becomes unmanageable if I have multiple arguments that can be
mat
orsp_mat
, and of course my real application is more complicated that multiplying two matrices.I suspect there is a way to do this by having the arguments be of type
SEXP
orS4
, but I can't figure it out.Any thoughts?
Best, Gabriel