0

In a parallel code with Rcpp, I convert a NumericVector variable to RcppParallel::RVector<double>. I also convert a NumericMatrix variable to RcppParallel::RMatrix<double>.

To speed up the code, I would like to use float variables instead of double. Hence, I would like to convert a NumericVector variable to something like RcppParallel::RVector<float> and a NumericMatrix variable to something like RcppParallel::RMatrix<float>.

Is it possible? If so, could you provide an example?

Emmanuel Hamel
  • 1,769
  • 7
  • 19
  • 1
    Because R itself only knows `double` you have to cast element by element, – Dirk Eddelbuettel Aug 25 '23 at 16:07
  • And be careful doing it is of course a lossy conversion from larger to smaller range / resolution just how not all int64_t values fit into an int (that is halt the size, just like float to double). – Dirk Eddelbuettel Aug 25 '23 at 16:14

0 Answers0