【发布时间】:2019-03-01 20:24:33
【问题描述】:
我目前正在努力使用RcppArmadillo 中提供的 sample() 命令。当我尝试运行下面的代码时,我收到错误 no matching function for call to sample 并且我已经在前面添加了额外的 Rcpp:: 命名空间,因为这在另一个 post 中运行良好。
我还尝试了其他几个容器类,但我总是遇到这个错误。下面是一些产生错误的代码。
任何帮助将不胜感激:)
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadilloExtensions/sample.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericMatrix example(arma::mat fprob,
int K) {
int t = fprob.n_rows;
IntegerVector choice_set = seq_len(K);
arma::mat states(t,1); states.fill(0);
arma::rowvec p0(K);
arma::rowvec alph(K);
double fit;
p0 = fprob.row(t-1);
fit = accu(p0);
alph = p0/fit;
states(t-1,1) = Rcpp::RcppArmadillo::sample(choice_set, 1, false, alph)[0];
return wrap(states);
}
【问题讨论】:
-
Rcpp::RcppArmadillo::sample?? -
我很确定这个问题也是重复的......所以如果有人有时间搜索它,我们可能会关闭它。