RcppArmadillo中的负无穷大与正无穷大

RcppArmadillo中的负无穷大与正无穷大,r,rcpp,R,Rcpp,我正在尝试访问0.2.16()中引入RcppArmadillo的math::inf()函数。符号与犰狳中的符号不同。犰狳()引用无穷大为: datum::inf(); 我收到的错误是:“'math'尚未声明。” 我试图将数学声明为标题,但没有任何效果 如果我用其他值代替无穷大(即2或1),代码工作正常。然而,我需要能够表示无穷大 下面是我的代码: #include <RcppArmadillo.h> #include <math.h> // [[Rcpp::depend

我正在尝试访问0.2.16()中引入RcppArmadillo的math::inf()函数。符号与犰狳中的符号不同。犰狳()引用无穷大为:

datum::inf();
我收到的错误是:“'math'尚未声明。”

我试图将数学声明为标题,但没有任何效果

如果我用其他值代替无穷大(即2或1),代码工作正常。然而,我需要能够表示无穷大

下面是我的代码:

#include <RcppArmadillo.h>
#include <math.h>
// [[Rcpp::depends(RcppArmadillo)]]

using namespace Rcpp;
// [[Rcpp::export]]
void lovetest(arma::mat Y,arma::mat thetatilde){
  int n = Y.n_rows;
  arma::vec lb(n);
  arma::vec ub(n);
  for(int i = 0; i<n;i++){
    #equivalent to R command: subset(thetatilde[i,],Y[i,]==1)
    arma::vec Y1 = thetatilde.elem(find(Y.row(i) == 1));
    arma::vec Y0 = thetatilde.elem(find(Y.row(i) == 0));
    Rcpp::Rcout << "max(Y1) = " << max(Y1) << std::endl;
    Rcpp::Rcout << "min(Y1) = " << min(Y0) << std::endl;
    if(Y1.n_elem >0){
      lb(i) = max(Y1);
    }else{
      lb(i) = -1*math::inf(); //problem line due to math
    }
    if(Y0.n_elem >0){
      ub(i) = min(Y0);
    }else{
      ub(i) = math::inf(); //problem line due to math
    } 
  }
}
#包括
#包括
//[[Rcpp::depends(RcppArmadillo)]]
使用名称空间Rcpp;
//[[Rcpp::导出]]
空爱测试(arma::mat Y,arma::mat Thetalde){
int n=Y.n_行;
arma:vec-lb(n);
arma::vec-ub(n);

对于(inti=0;iClang)来说,这一点很明显:

test.cpp:20:18: error: use of undeclared identifier 'math'; did you mean 'arma::math'?
      lb(i) = -1*math::inf(); //problem line due to math
                 ^~~~
                 arma::math
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo/include/armadillo_bits/constants_compat.hpp:158:22: note: 'arma::math' declared here
typedef Math<double> math;
                     ^
test.cpp:20:18:错误:使用了未声明的标识符'math';您的意思是'arma::math'?
lb(i)=-1*数学::inf();//数学问题行
^~~~
阿玛:数学
/Library/Frameworks/R.framework/Versions/3.2/Resources/Library/RcppArmadillo/include/armadillo_bits/constants_compat.hpp:158:22:注意:此处声明了“arma::math”
类型定义数学;
^

您想要的是
arma::math::inf()
,而不是
math::inf()

您读错了文档:它是
datum::inf
,而不是
datum::inf()
。在Rcpp上下文中,您可以在它前面加上
arma::
,即
arma::datum::inf
。无论如何,使用
math::
是不受欢迎的——您为什么要在旧版本的犰狳身上使用这种方法?