我正在研究R中的一个程序来计算最多1000个数据点的Gabriel图.我使用了我在网上找到的程序(GabrielGraph基于Bhattacharya等人,1981年第781-830行).
不幸的是,获得结果需要相当多的时间,所以我尝试使用Rcpp重新编程.为此,我写了几个小程序和一个叫做edge的大程序,用来计算Gabriel图的边缘.我也是Rcpp编程的新手,所以我可能做了比必要更复杂的事情,但我不知道如何做得更好.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double vecnorm(NumericVector x){
//to calculate the vectornorm sqrt(sum of (vector entries)^2)
double out;
out = sqrt(sum(pow(x,2.0)));
return out;
}
// [[Rcpp::export]]
NumericVector vektorzugriff(NumericMatrix xy,int i){
//to return a row of the Matrix xy
int col = xy.ncol();
NumericVector out(col);
for(int j=0; j<=col; j++){
out[j] = xy(i-1,j);
}
return out;
}
// [[Rcpp::export]]
IntegerVector vergl(NumericVector eins, NumericVector zwei){
//to see if two Vectors have any identical entries
IntegerVector out = …Run Code Online (Sandbox Code Playgroud)