Skip to content

Commit

Permalink
fix OneCategoricalDist parallel aggregator for #201
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed May 8, 2023
1 parent 2dd87fa commit 8a78c91
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dodgr
Title: Distances on Directed Graphs
Version: 0.2.20.015
Version: 0.2.20.016
Authors@R: c(
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ATFutures/dodgr",
"issueTracker": "https://github.com/ATFutures/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.2.20.015",
"version": "0.2.20.016",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
23 changes: 9 additions & 14 deletions src/run_sp_categorical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ struct OneCategoricalDist : public RcppParallel::Worker
// Parallel function operator
void operator() (std::size_t begin, std::size_t end)
{
const size_t nto = toi.size ();

for (std::size_t i = begin; i < end; i++)
{
std::shared_ptr<PF::PathFinder> pathfinder =
Expand All @@ -89,13 +87,11 @@ struct OneCategoricalDist : public RcppParallel::Worker

for (size_t j = 0; j < toi.size (); j++)
{
if (w [toi [j]] < INFINITE_DOUBLE)
{
for (size_t k = 0; k < num_edge_types; k++)
for (size_t k = 0; k <= num_edge_types; k++) {
const double dto = d [toi [j] + k * nverts];
if (dto < INFINITE_DOUBLE)
{
const double dto = d [toi [j] + k * nverts];
if (dto < INFINITE_DOUBLE)
dout (i, j + k * nto) = dto;
dout (i, j + k * toi.size ()) = dto;
}
}
}
Expand Down Expand Up @@ -573,7 +569,7 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_categorical (const Rcpp::DataFrame graph,
const std::vector <double> wt = graph ["d_weighted"];
const std::vector <size_t> edge_type = graph ["edge_type"];

const size_t num_types = categorical::get_num_edge_types (edge_type);
const size_t num_edge_types = categorical::get_num_edge_types (edge_type);

const size_t nedges = static_cast <size_t> (graph.nrow ());
std::map <std::string, size_t> vert_map;
Expand All @@ -591,9 +587,9 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_categorical (const Rcpp::DataFrame graph,

size_t ncol;
if (proportions_only)
ncol = num_types + 1L;
ncol = num_edge_types + 1L;
else
ncol = nto * (num_types + 1L);
ncol = nto * (num_edge_types + 1L);

Rcpp::NumericVector na_vec = Rcpp::NumericVector (nfrom * ncol,
Rcpp::NumericVector::get_na ());
Expand All @@ -606,18 +602,17 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_categorical (const Rcpp::DataFrame graph,
{
OneCategory one_dist (RcppParallel::RVector <int> (fromi), toi,
edge_type, nverts, vx, vy,
g, heap_type, num_types,
g, heap_type, num_edge_types,
RcppParallel::RMatrix <double> (dout));
RcppParallel::parallelFor (0, nfrom, one_dist, chunk_size);
} else
{
OneCategoricalDist one_dist (RcppParallel::RVector <int> (fromi),
toi, edge_type, nverts, vx, vy,
g, heap_type, num_types,
g, heap_type, num_edge_types,
RcppParallel::RMatrix <double> (dout));
RcppParallel::parallelFor (0, nfrom, one_dist, chunk_size);
}


return (dout);
}
Expand Down

0 comments on commit 8a78c91

Please sign in to comment.