سؤال

I'm trying to access the math::inf() function that was brought into RcppArmadillo in 0.2.16 (http://cran.r-project.org/web/packages/RcppArmadillo/news.html). The notation is different from what comes in Armadillo. Armadillo (http://arma.sourceforge.net/docs.html#constants) references infinity as:

datum::inf();

The error that I am receiving is: "'math' has not been declared."

I tried to declare math as a header to no avail.

If I substitute other values for infinity (i.e. 2 or 1), the code works fine. However, I need to be able to represent infinity.

Below is my code:

#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
    } 
  }
}
هل كانت مفيدة؟

المحلول

Clang makes it obvious:

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;
                     ^

You want arma::math::inf(), not math::inf().

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top