Open coatless opened 5 years ago
Yeah, so the offending piece of code is setting two dimensions and enforcing a matrix object return instead of a list. https://github.com/RcppCore/RcppArmadillo/blob/188beeae47cf354c4b00d8fdcdf6ec7255d36f92/inst/include/RcppArmadilloWrap.h#L133-L138
For anyone else who might stumble upon this issue - as I did - the following worked for me:
// [[Rcpp::export]]
Rcpp::List conv_arma_field_to_rcpp_list(int init_arma_mat = 5,
int dimensions = 6) {
arma::field<arma::Mat<double> > Field_obj(init_arma_mat);
for (unsigned int s = 0; s < init_arma_mat; s++) {
int rows_cols = arma::randi<int>(arma::distr_param(dimensions, dimensions));
Field_obj(s).zeros(rows_cols, rows_cols);
}
Rcpp::List list_obj = Rcpp::wrap( Rcpp::RcppArmadillo::FieldImporter< arma::Mat<double> >( Field_obj ) );
return list_obj;
}
# res = conv_arma_field_to_rcpp_list()
This should now be fixed, albeit behind a #define
that has to be turned on. See the new unit tests in tests_fields_new.R and the underlying C++ code (with the #define
) in fields_new.cpp.
Stumbled across an interesting hiccup in the exporter for
arma::field<T>
(the generic vector). In particular, the attributes associated with anarma::field<arma::mat>
shows asmatrix
under aclass(x)
call instead oflist
. The only way to obtain thelist
type is to use atypeof()
call.The class issue is shown under
d4
beingmatrix
instead oflist
.Moreover, the list is registering as a
matrix
withdim(x)
of N x 1 instead of alist
without dimensions.And the object structure: