RcppArmadillo sample on armadillo vector classes

家住魔仙堡 提交于 2019-11-29 17:21:52

In case anyone runs into this problem in the future, the problem seems to have something to do with multiple definitions of the sample function in the namespaces being used. Specifically typing out the namespaces where the required function is defined solves the problem. In particular, the sample function needs to be called from Rcpp::RcppArmadillo.

The following code works as desired.

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

// [[Rcpp::export]]
arma::uvec sample_index(const int &size){
    arma::uvec sequence = arma::linspace<arma::uvec>(0, size-1, size);
    arma::uvec out = Rcpp::RcppArmadillo::sample(sequence, size, false);
    return out;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!