2017-11-09 3 views
2

私はRcppを使い始めました。私は2つの数値ベクトルを取り、その和集合を計算し数値ベクトルを返す単純なプログラムを持っています。リスティングは(test.cpp)の下に貼り付けられます。実装されていないタイプ 'builtin' in 'coerceToReal' [Rcpp]

#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' 

とプログラムがクラッシュ任意のアイデアの数を増やしますか?ポインタや参照をありがとう。

+0

それは私のためにうまくいく...あなたのシステム仕様は何ですか? –

+0

@JosephWood Linuc Ubuntuボックス、16 GB RAM。 – Andrej

答えて

2

NumericVectorIntegerVectorで置き換えてください。 またはstd::vector<double>で作業してください。

+0

それは今働くようです!私は 'NumericVector'sを' IntegerVector'sに置き換えました。 – Andrej

+1

私はこれがうれしいですが、まだ少し混乱しています。数値が「整数」の 'class(s​​ample(20000))== class(s​​ample(1000000))'のように小さい場合、なぜ最初のケースで動作するのでしょうか?コンパイラは、最初のケースではまだ不平を言っているはずです。 –

+1

私は問題がR/Rcppの部分にないと思う([this](http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2011-June/002546.html)を参照)) 。ある時点で変換が行われている必要があります。私は本当にわからない。 –

関連する問題