I need to perform calculations for each matrix entry in an Rcpp::List
. The list contains an arbitrary combination of dense and sparse matrices. This list is passed to C++ from R. My question here concerns both approaches to implementation, and efficiency. My current thought is to loop over each element of the list, check for its type (dense or sparse) and generate an arma::mat
or arma::sp_mat
for the element, and use it for calculations, preferably without copying. I am confused about the following:
- How to check whether the type of matrix is dense or sparse from
Rcpp::List[d]
whered
is an index ? - I am able to use the advanced constructor for arma::mat via
NumericMatrix
that avoids copying (as below), but I am not sure how to go about doing the same witharma::sp_mat
. These matrices are large, and I want to avoid copying.
<code>Rcpp::NumericMatrix Ad = RcppListObject[d];
arma::mat ad=arma::mat( Ad.begin(), Ad.nrow(), Ad.ncol(), false );
//any needed calculations based on the d^{th} entry uses `ad`.
</code>
<code>Rcpp::NumericMatrix Ad = RcppListObject[d];
arma::mat ad=arma::mat( Ad.begin(), Ad.nrow(), Ad.ncol(), false );
//any needed calculations based on the d^{th} entry uses `ad`.
</code>
Rcpp::NumericMatrix Ad = RcppListObject[d];
arma::mat ad=arma::mat( Ad.begin(), Ad.nrow(), Ad.ncol(), false );
//any needed calculations based on the d^{th} entry uses `ad`.
- Closely related to 2, there are a variety of calculations I will need to do with the
d^{th}
matrix in the List, at different points of the algorithm. Do I have to do the two steps noted in point 2 every time before I can do computations with it, or is there a more efficient route? ( For example, canarma::field
help, and handle a combination ofarma::mat
&arma::sp_mat
matrices without copying? )
Thank you very much!