-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split src match-points fns out to match-points.cpp for #103
- Loading branch information
Showing
10 changed files
with
125 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: dodgr | ||
Title: Distances on Directed Graphs | ||
Version: 0.2.14.076 | ||
Version: 0.2.14.077 | ||
Authors@R: c( | ||
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre")), | ||
person("Andreas", "Petutschnig", role = "aut"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "match-points.h" | ||
|
||
struct OnePointIndex : public RcppParallel::Worker | ||
{ | ||
const RcppParallel::RVector <double> xy_x, xy_y, pt_x, pt_y; | ||
const size_t nxy; | ||
RcppParallel::RVector <int> index; | ||
|
||
// constructor | ||
OnePointIndex ( | ||
const RcppParallel::RVector <double> xy_x_in, | ||
const RcppParallel::RVector <double> xy_y_in, | ||
const RcppParallel::RVector <double> pt_x_in, | ||
const RcppParallel::RVector <double> pt_y_in, | ||
const size_t nxy_in, | ||
Rcpp::IntegerVector index_in) : | ||
xy_x (xy_x_in), xy_y (xy_y_in), pt_x (pt_x_in), pt_y (pt_y_in), | ||
nxy (nxy_in), index (index_in) | ||
{ | ||
} | ||
|
||
// Parallel function operator | ||
void operator() (std::size_t begin, std::size_t end) | ||
{ | ||
for (std::size_t i = begin; i < end; i++) | ||
{ | ||
double dmin = INFINITE_DOUBLE; | ||
long int jmin = INFINITE_INT; | ||
for (size_t j = 0; j < nxy; j++) | ||
{ | ||
double dij = (xy_x [j] - pt_x [i]) * (xy_x [j] - pt_x [i]) + | ||
(xy_y [j] - pt_y [i]) * (xy_y [j] - pt_y [i]); | ||
if (dij < dmin) | ||
{ | ||
dmin = dij; | ||
jmin = static_cast <long int> (j); | ||
} | ||
} | ||
index [i] = static_cast <int> (jmin); | ||
} | ||
} | ||
|
||
}; | ||
|
||
//' rcpp_points_index_par | ||
//' | ||
//' Get index of nearest vertices to list of points | ||
//' | ||
//' @param graph Rcpp::DataFrame containing the graph | ||
//' @param pts Rcpp::DataFrame containing the routing points | ||
//' | ||
//' @return 0-indexed Rcpp::NumericVector index into graph of nearest points | ||
//' | ||
//' @noRd | ||
// [[Rcpp::export]] | ||
Rcpp::IntegerVector rcpp_points_index_par (const Rcpp::DataFrame &xy, | ||
Rcpp::DataFrame &pts) | ||
{ | ||
Rcpp::NumericVector ptx = pts ["x"]; | ||
Rcpp::NumericVector pty = pts ["y"]; | ||
|
||
Rcpp::NumericVector vtx = xy ["x"]; | ||
Rcpp::NumericVector vty = xy ["y"]; | ||
|
||
size_t npts = static_cast <size_t> (pts.nrow ()), | ||
nxy = static_cast <size_t> (xy.nrow ()); | ||
|
||
//Rcpp::IntegerVector index (n, Rcpp::IntegerVector::get_na ()); | ||
Rcpp::IntegerVector index (npts); | ||
// Create parallel worker | ||
OnePointIndex one_pt_indx (RcppParallel::RVector <double> (vtx), | ||
RcppParallel::RVector <double> (vty), | ||
RcppParallel::RVector <double> (ptx), | ||
RcppParallel::RVector <double> (pty), nxy, index); | ||
|
||
RcppParallel::parallelFor (0, npts, one_pt_indx); | ||
|
||
return index; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <string> | ||
#include <cmath> | ||
|
||
#include <Rcpp.h> | ||
// [[Rcpp::depends(RcppParallel)]] | ||
#include <RcppParallel.h> | ||
|
||
constexpr float INFINITE_FLOAT = std::numeric_limits<float>::max (); | ||
constexpr double INFINITE_DOUBLE = std::numeric_limits<double>::max (); | ||
constexpr int INFINITE_INT = std::numeric_limits<int>::max (); | ||
|
||
Rcpp::IntegerVector rcpp_points_index (const Rcpp::DataFrame &xy, | ||
Rcpp::DataFrame &pts); | ||
Rcpp::IntegerVector rcpp_points_index_par (const Rcpp::DataFrame &xy, | ||
Rcpp::DataFrame &pts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters