RCPP警告:对"exp"的调用含糊不清

编程入门 行业动态 更新时间:2024-10-06 10:34:51
本文介绍了RCPP警告:对"exp"的调用含糊不清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个Rcpp代码,如下所示:

I am writing a Rcpp code as below:

// [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::depends(BH)]] // [[Rcpp::plugins(cpp11)]] #include <RcppArmadillo.h> #include <boost/random.hpp> #include <boost/random/uniform_real_distribution.hpp> #include <math.h> using namespace Rcpp; using namespace std; // [[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); }

.

但是它表明调用'exp'是模棱两可的".为什么会收到此消息,我将如何解决?

But it shows that "Call to 'exp' is ambiguous". Why do I get this message and how will I solve it?

当我进入sessionInfo()时:

While I get in sessionInfo():

R version 3.2.4 (2016-03-10) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.12.6 (unknown) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Rcpp_0.12.4 loaded via a namespace (and not attached): [1] colorspace_1.2-6 scales_0.4.0 plyr_1.8.3 tools_3.2.4 inline_0.3.14 gtable_0.2.0 rstan_2.9.0-3 [8] gridExtra_2.2.1 ggplot2_2.1.0 grid_3.2.4 munsell_0.4.3 stats4_3.2.4

推荐答案

我建议OP将其关闭或删除.这个问题只是展示了一些允许但不建议使用的C ++用法:

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

  • 包括了额外的标头:数学标头 已由Rcpp引入(由RcppArmadillo引入)
  • 您永远都不需要两者 cmath 和 math.h ,而且如此处所述,您也不需要
  • 我们通常建议不要无条件地平整所有名称空间
  • 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

这样,您的代码看起来像这样(仍然包含未使用的C ++ 11调用,但没有害处):

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>

更多推荐

RCPP警告:对"exp"的调用含糊不清

本文发布于:2023-11-26 10:12:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不清   RCPP   quot   exp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!