Rcpp warning: Call to 'exp' is ambiguous

前端 未结 1 1646
感动是毒
感动是毒 2021-01-27 02:19

I am writing a Rcpp code as below:

// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]

#include 
#in         


        
相关标签:
1条回答
  • 2021-01-27 03:25

    I suggest this to be closed or deleted by OP. The question simply exhibits some allowed-but-not-recommended C++ usage:

    • extra headers included: the math headers are already brought in by Rcpp (which is brought in by RcppArmadillo)
    • you never ever need both cmath and math.h, and as stated here you do not need either
    • we generally recommend against flattening all namespaces unconditionally

    With this, your code looks like this (still containing a call for C++11 which is not used, but does no harm):

    // [[Rcpp::depends(RcppArmadillo)]]
    // [[Rcpp::depends(BH)]]
    // [[Rcpp::plugins(cpp11)]]
    
    #include <RcppArmadillo.h>
    #include <boost/random.hpp>
    #include <boost/random/uniform_real_distribution.hpp>
    
    // [[Rcpp::export]]
    double ks(const double k, const double alpha, const double  mag, const double M0){
        double ksres;
        ksres=  k* std::exp ( alpha*(mag-M0) );
        return(ksres);
    }
    
    /*** R
    ks(1.0, 2.0, 3.0, 4.0)
    */
    

    This compiles without any warning whatsoever on my box (with stringent compiler warnings turned on, output not shown here) and runs as expected too:

    R> Rcpp::sourceCpp("/tmp/soQ.cpp")
    
    R> ks(1.0, 2.0, 3.0, 4.0)
    [1] 0.135335
    R> 
    
    0 讨论(0)
提交回复
热议问题