I'm trying out Rcpp / RcppArmadillo in RStudio with the following code:
#include <RcppArmadillo.h>
//[[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using std::exp;
using std::log1p;
// [[Rcpp::export]]
arma::vec log1pexp(arma::vec x) {
for(int ii = 0; ii < x.n_elem; ++ii){
if(x(ii) < 18.0){
x(ii) = log1p(exp(x(ii)));
} else{
x(ii) = x(ii) + exp(-x(ii));
}
}
return x;
}
RStudio says the calls to exp
are ambiguous. I've tried calling std::exp
in the code instead of using std::exp
but have no success. The code compiles without warnings through Rcpp::sourceCpp('filename.cpp')
. If I cast (float)x(ii)
in the code the warning disappears, but not if
I cast (double)x(ii)
.
Any insight appreciated, I'm pretty inexperienced with both C++ and RStudio.
Picture of what's going on
exp
, as (based on the declarations in the above code) this could refer to eitherexp
thestd::
namespace orexp
from theRcpp::
namespace (and possibly the C functionexp
from<math.h>
).