Here is the code:
#include
#include
#include
#include
using namespace Rcpp;
// [[Rcpp::ex
The problem is solved by using throw
instead of assert
, Rcpp will actually put things in a proper try-catch block, which is super nice.
#include
#include
#include
#include
using namespace Rcpp;
// [[Rcpp::export]]
double eudist(NumericVector x, NumericVector y) {
int nx = x.size();
int ny = y.size();
Rcout << nx << '\n' << ny << std::endl;
if(nx != ny) {
throw std::invalid_argument("Two vectors are not of the same length!");
}
double dist=0;
for(int i = 0; i < nx; i++) {
dist += pow(x[i] - y[i], 2);
}
return sqrt(dist);
}