See More

#include using namespace Rcpp ; // #include // //' Finds the Euclidean distance between points. //' //' @param seq1 the array 1. //' @param seq2 the array 2. //' stops and the NAN is returned. //' @useDynLib jmotif //' @export // [[Rcpp::export]] double euclidean_dist(NumericVector seq1, NumericVector seq2) { if(seq1.length() == seq2.length()){ double res = 0.0; for(int i=0; i::quiet_NaN(); } } // this a faster version for the internal use // double _euclidean_dist(std::vector* seq1, std::vector* seq2) { double res = 0; for(unsigned i=0; isize(); i++){ res = res + (seq1->at(i) - seq2->at(i)) * (seq1->at(i) - seq2->at(i)); } return sqrt(res); } //' Finds the Euclidean distance between points, if distance is above the threshold, abandons the computation //' and returns NAN. //' //' @param seq1 the array 1. //' @param seq2 the array 2. //' @param upper_limit the max value after reaching which the distance computation //' stops and the NAN is returned. //' @useDynLib jmotif //' @export // [[Rcpp::export]] double early_abandoned_dist(NumericVector seq1, NumericVector seq2, double upper_limit) { if(seq1.length() == seq2.length()){ double limit = upper_limit; if(limit != std::numeric_limits::max()){ limit = upper_limit * upper_limit; } double res = 0.0; for(int i=0; i limit){ return std::numeric_limits::quiet_NaN(); } } return sqrt(res); } else { stop("arrays length are not equal"); return std::numeric_limits::quiet_NaN(); } }