Greetings and Salutations,
I'm trying to use the field object type instead of the list data type to avoid having to issue a copy command. I'm trying to do this to decrease the amount of time associated with when removing a matrix from the list to be operated on by a matrix already defined in armadillo's data structures. (e.g. removing arma::mat * as<arma::mat>(NumericMatrix)
).
Specifically, I'm trying to pass a field into a function and have it operated upon. The error message I receive upon compile is:
No matching constructor for initialization of 'arma::field< arma::Mat >'
This errors on the function definition: #include <RcppArmadillo.h>
NOTE: The objective is to be able to use Field
as an object in a function declaration. This function would NOT need to be accessed or called by R! Mainly, the function would act as a helper function to a larger RcppArmadillo function.
The code I am trying to use is:
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::export]]
arma::mat get_matrice_dimensions(arma::field<arma::mat> x) {
/* Get the length of the list */
unsigned int bin = x.n_elem;
/* Obtain matrix size for each element */
arma::mat storage(bin,2);
/* Temporary storage that does not need to be created each time */
arma::rowvec cur_elem_dims(2);
for(unsigned int i=0; i<bin; i++){
/* Get dimensions */
/* NumericMatrix uses .nrow(), .ncol() vs. .n_rows, .n_cols in arma */
cur_elem_dims(0) = x(i).n_rows;
cur_elem_dims(1) = x(i).n_cols;
/* Store dimensions */
storage.row(i) = cur_elem_dims;
}
/* Delete object */
cur_elem_dims.clear();
return storage;
}
I envision the following being passed into the function:
x = list(matrix(0,nrow=5,ncol=3),matrix(1,nrow=5,ncol=3))
get_matrice_dimensions(x)
It is easy enough to come up with support for
as<field<...>>
. I just sent a pull request with thisExporter
implementation:With this, I get: