'coerceToReal' [Rcpp] 中未实现的类型 'builtin'
Unimplemented type 'builtin' in 'coerceToReal' [Rcpp]
我刚开始使用 Rcpp。我有一个简单的程序,它接受两个数值向量,计算它们的并集和 returns 一个数值向量。清单粘贴在下方 (test.cpp
)。
#include <Rcpp.h>
#include <algorithm>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector test(NumericVector x, NumericVector y) {
int n = x.size() + y.size();
std::vector<int> v(n);
std::vector<int>::iterator it;
std::sort(x.begin(), x.end());
std::sort(y.begin(), y.end());
it=std::set_union(x.begin(), x.end(), y.begin(), y.end(), v.begin());
v.resize(it-v.begin());
return wrap(v);
}
/*** R
x <- c(5,10,15,20,25)
y <- c(50,40,30,20,10)
test(x, y)
*/
当我尝试 运行 具有值
的程序时
x <- sample(20000)
y <- sample(20000)
test(x, y)
功能有效。但是当我增加值的数量时
x <- sample(1000000)
y <- sample(1000000)
test(x, y)
程序崩溃并输出
Error in .Primitive(".Call")(<pointer: 0x7f1819d8af20>, x, y) :
unimplemented type 'builtin' in 'coerceToReal'
知道发生了什么事吗?感谢您的指点或参考。
将您的 NumericVector
替换为 IntegerVector
。
或者使用 std::vector<double>
.
我刚开始使用 Rcpp。我有一个简单的程序,它接受两个数值向量,计算它们的并集和 returns 一个数值向量。清单粘贴在下方 (test.cpp
)。
#include <Rcpp.h>
#include <algorithm>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector test(NumericVector x, NumericVector y) {
int n = x.size() + y.size();
std::vector<int> v(n);
std::vector<int>::iterator it;
std::sort(x.begin(), x.end());
std::sort(y.begin(), y.end());
it=std::set_union(x.begin(), x.end(), y.begin(), y.end(), v.begin());
v.resize(it-v.begin());
return wrap(v);
}
/*** R
x <- c(5,10,15,20,25)
y <- c(50,40,30,20,10)
test(x, y)
*/
当我尝试 运行 具有值
的程序时x <- sample(20000)
y <- sample(20000)
test(x, y)
功能有效。但是当我增加值的数量时
x <- sample(1000000)
y <- sample(1000000)
test(x, y)
程序崩溃并输出
Error in .Primitive(".Call")(<pointer: 0x7f1819d8af20>, x, y) :
unimplemented type 'builtin' in 'coerceToReal'
知道发生了什么事吗?感谢您的指点或参考。
将您的 NumericVector
替换为 IntegerVector
。
或者使用 std::vector<double>
.