Can I instantiate matrix in Armadillo and then set it to use auxiliary memory in a later line of code?

StackOverflow https://stackoverflow.com/questions/7872461

  •  11-02-2021
  •  | 
  •  

Question

I am using Armadillo with RcppArmadillo. Is it possible to declare a matrix with arma::mat A and then later assign some memory to this matrix that I have created before with arma::mat(aux_mem*, n_rows, n_cols, copy_aux_mem = true, strict = true) ?

The intention is to create an Armadillo matrix from an Rcpp::NumericMatrix but only if() a certain condition is met. Then later in the same function, I want to use that matrix but again only if() a condition is met.

Was it helpful?

Solution

Provided I understand what you are asking, the answer is probably yes. The boolean toggles at the end control whether new memory is allocated, or whether you re-use the existing object's memory.

Not sure what you mean by "assign some memory to this matrix". See the Writing R Extensions manual on what you can and cannot do if you want R to manage the memory--the key point is that for objects we return to R, we need to create them such that they became 'native' to R. And Rcpp does this, and RcppArmadillo lets you do it too.

Also: You may be better off asking these questions on the rcpp-devel list which Conrad, the author of Armadillo, also reads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top