Is there any reason why I should prefer Rcpp::NumericVectorover std::vector<double>?
For example, two functions below
Rcpp::NumericVector foo(const Rcpp::NumericVector& x) {
Rcpp::NumericVector tmp(x.length());
for (int i = 0; i < x.length(); i++)
tmp[i] = x[i] + 1.0;
return tmp;
}
std::vector<double> bar(const std::vector<double>& x) {
std::vector<double> tmp(x.size());
for (int i = 0; i < x.size(); i++)
tmp[i] = x[i] + 1.0;
return tmp;
}
They are equivalent when considering their performance and benchmarks. I understand that Rcpp offers work with sugar and vectorized operations, but if it is only about taking the vector R as the input and return vector as the output, will there be any difference which one I use? Can use std::vector<double>lead to any possible problems when interacting with R?
source
share