From 776149f9c7b4f27d832c1df36a0f63b472c007b6 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 4 Oct 2021 11:54:02 +0200 Subject: [PATCH] rename dists_proportional -> dists_categorical for #144 --- DESCRIPTION | 2 +- NAMESPACE | 4 +- R/RcppExports.R | 12 ++-- ...sts-proportional.R => dists-categorical.R} | 24 +++---- codemeta.json | 14 ++-- man/dodgr_dists_proportional.Rd | 69 ------------------- man/summary.dodgr_dists_proportional.Rd | 19 ----- src/Makevars | 2 +- src/Makevars.win | 2 +- src/RcppExports.cpp | 20 +++--- src/pathfinders.h | 6 +- src/run_sp.h | 10 +-- ...roportional.cpp => run_sp_categorical.cpp} | 40 +++++------ ...roportional.R => test-dists-categorical.R} | 26 +++---- 14 files changed, 78 insertions(+), 172 deletions(-) rename R/{dists-proportional.R => dists-categorical.R} (88%) delete mode 100644 man/dodgr_dists_proportional.Rd delete mode 100644 man/summary.dodgr_dists_proportional.Rd rename src/{run_sp_proportional.cpp => run_sp_categorical.cpp} (94%) rename tests/testthat/{test-dists-proportional.R => test-dists-categorical.R} (77%) diff --git a/DESCRIPTION b/DESCRIPTION index 0fc205e55..0b942dabd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dodgr Title: Distances on Directed Graphs -Version: 0.2.10.010 +Version: 0.2.10.011 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Andreas", "Petutschnig", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index dc9841cb9..39da4e502 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -S3method(summary,dodgr_dists_proportional) +S3method(summary,dodgr_dists_categorical) S3method(weight_streetnet,default) S3method(weight_streetnet,sc) S3method(weight_streetnet,sf) @@ -14,7 +14,7 @@ export(dodgr_components) export(dodgr_contract_graph) export(dodgr_distances) export(dodgr_dists) -export(dodgr_dists_proportional) +export(dodgr_dists_categorical) export(dodgr_flowmap) export(dodgr_flows_aggregate) export(dodgr_flows_disperse) diff --git a/R/RcppExports.R b/R/RcppExports.R index 5bb37d959..6c23bd87d 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -299,7 +299,7 @@ rcpp_get_paths <- function(graph, vert_map_in, fromi, toi_in, heap_type) { .Call(`_dodgr_rcpp_get_paths`, graph, vert_map_in, fromi, toi_in, heap_type) } -#' rcpp_get_sp_dists_proportional +#' rcpp_get_sp_dists_categorical #' #' The `graph` must have an `edge_type` column of non-negative integers, #' with 0 denoting edges which are not aggregated, and all other values @@ -308,11 +308,11 @@ rcpp_get_paths <- function(graph, vert_map_in, fromi, toi_in, heap_type) { #' Implemented in parallal form only; no single-threaded version, and #' only for AStar (so graphs must be spatial). #' @noRd -rcpp_get_sp_dists_proportional <- function(graph, vert_map_in, fromi, toi_in, heap_type, proportions_only) { - .Call(`_dodgr_rcpp_get_sp_dists_proportional`, graph, vert_map_in, fromi, toi_in, heap_type, proportions_only) +rcpp_get_sp_dists_categorical <- function(graph, vert_map_in, fromi, toi_in, heap_type, proportions_only) { + .Call(`_dodgr_rcpp_get_sp_dists_categorical`, graph, vert_map_in, fromi, toi_in, heap_type, proportions_only) } -#' rcpp_get_sp_dists_prop_threshold +#' rcpp_get_sp_dists_cat_threshold #' #' The `graph` must have an `edge_type` column of non-negative integers, #' with 0 denoting edges which are not aggregated, and all other values @@ -321,8 +321,8 @@ rcpp_get_sp_dists_proportional <- function(graph, vert_map_in, fromi, toi_in, he #' Implemented in parallal form only; no single-threaded version, and #' only for AStar (so graphs must be spatial). #' @noRd -rcpp_get_sp_dists_prop_threshold <- function(graph, vert_map_in, fromi, dlimit, heap_type) { - .Call(`_dodgr_rcpp_get_sp_dists_prop_threshold`, graph, vert_map_in, fromi, dlimit, heap_type) +rcpp_get_sp_dists_cat_threshold <- function(graph, vert_map_in, fromi, dlimit, heap_type) { + .Call(`_dodgr_rcpp_get_sp_dists_cat_threshold`, graph, vert_map_in, fromi, dlimit, heap_type) } #' rcpp_gen_hash diff --git a/R/dists-proportional.R b/R/dists-categorical.R similarity index 88% rename from R/dists-proportional.R rename to R/dists-categorical.R index e1612ed28..0ccd6fd95 100644 --- a/R/dists-proportional.R +++ b/R/dists-categorical.R @@ -1,13 +1,13 @@ -#' Proportional distances along different edge categories +#' Cumulative distances along different edge categories #' #' @inheritParams dodgr_dists #' @param graph `data.frame` or equivalent object representing the network #' graph which must have a column named "edge_type" which labels categories of -#' edge types along which proportional distances are to be aggregated (see +#' edge types along which categorical distances are to be aggregated (see #' Note). -#' @param proportions_only If `FALSE`, return full distance matrices for full +#' @param proportions_only If `FALSE`, return distance matrices for full #' distances and for each edge category; if `TRUE`, return single vector of -#' proportional distances, like current `summary` function applied to full +#' proportional distances, like the `summary` function applied to full #' results. See Note. #' @param dlimit If `TRUE`, and no value to `to` is given, distances are #' aggregated from each `from` point out to the specified distance limit (in @@ -33,7 +33,7 @@ #' calculations which would otherwise require distance matrices too large to be #' directly stored. #' @export -dodgr_dists_proportional <- function (graph, +dodgr_dists_categorical <- function (graph, from = NULL, to = NULL, proportions_only = FALSE, @@ -62,7 +62,7 @@ dodgr_dists_proportional <- function (graph, } is_spatial <- is_graph_spatial (graph) if (!is_spatial) - stop ("proportional distances only implemented for spatial graphs") + stop ("Categorical distances only implemented for spatial graphs") vert_map <- make_vert_map (graph, gr_cols, is_spatial) @@ -83,7 +83,7 @@ dodgr_dists_proportional <- function (graph, if (is.null (dlimit) & !is.null (to)) { - d <- rcpp_get_sp_dists_proportional (graph, + d <- rcpp_get_sp_dists_categorical (graph, vert_map, from_index$index, to_index$index, @@ -121,7 +121,7 @@ dodgr_dists_proportional <- function (graph, names (d) <- names (edge_type_table) res <- c (d0, d) - class (res) <- append (class (res), "dodgr_dists_proportional") + class (res) <- append (class (res), "dodgr_dists_categorical") } else { @@ -132,7 +132,7 @@ dodgr_dists_proportional <- function (graph, } } else { - d <- rcpp_get_sp_dists_prop_threshold (graph, + d <- rcpp_get_sp_dists_cat_threshold (graph, vert_map, from_index$index, dlimit, @@ -153,13 +153,13 @@ dodgr_dists_proportional <- function (graph, } -#' Transform a result from 'dodgr_dists_proportional' to summary statistics +#' Transform a result from 'dodgr_dists_categorical' to summary statistics #' -#' @param object A 'dodgr_dists_proportional' object +#' @param object A 'dodgr_dists_categorical' object #' @param ... Extra parameters currently not used #' @return The summary statistics (invisibly) #' @export -summary.dodgr_dists_proportional <- function (object, ...) { +summary.dodgr_dists_categorical <- function (object, ...) { d0 <- object$distances # first list item sum_d0 <- sum (d0, na.rm = TRUE) diff --git a/codemeta.json b/codemeta.json index 46eb31b59..846f3170a 100644 --- a/codemeta.json +++ b/codemeta.json @@ -10,7 +10,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.10.010", + "version": "0.2.10.11", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", @@ -371,10 +371,7 @@ ], "releaseNotes": "https://github.com/ATFutures/dodgr/blob/master/NEWS.md", "readme": "https://github.com/ATFutures/dodgr/blob/main/README.md", - "contIntegration": [ - "https://github.com/atfutures/dodgr/actions?query=workflow%3AR-CMD-check", - "https://codecov.io/gh/ATFutures/dodgr" - ], + "contIntegration": ["https://github.com/atfutures/dodgr/actions?query=workflow%3AR-CMD-check", "https://codecov.io/gh/ATFutures/dodgr"], "developmentStatus": "https://www.repostatus.org/#active", "keywords": [ "distance", @@ -403,15 +400,12 @@ "@type": "PublicationIssue", "datePublished": "2019", "isPartOf": { - "@type": [ - "PublicationVolume", - "Periodical" - ], + "@type": ["PublicationVolume", "Periodical"], "name": "Transport Findings" } } } ], "relatedLink": "https://CRAN.R-project.org/package=dodgr", - "fileSize": "12446.017KB" + "fileSize": "12403.894KB" } diff --git a/man/dodgr_dists_proportional.Rd b/man/dodgr_dists_proportional.Rd deleted file mode 100644 index 889028ed9..000000000 --- a/man/dodgr_dists_proportional.Rd +++ /dev/null @@ -1,69 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dists-proportional.R -\name{dodgr_dists_proportional} -\alias{dodgr_dists_proportional} -\title{Proportional distances along different edge categories} -\usage{ -dodgr_dists_proportional( - graph, - from = NULL, - to = NULL, - proportions_only = FALSE, - dlimit = NULL, - heap = "BHeap", - quiet = TRUE -) -} -\arguments{ -\item{graph}{\code{data.frame} or equivalent object representing the network -graph which must have a column named "edge_type" which labels categories of -edge types along which proportional distances are to be aggregated (see -Note).} - -\item{from}{Vector or matrix of points \strong{from} which route distances are to -be calculated (see Notes)} - -\item{to}{Vector or matrix of points \strong{to} which route distances are to be -calculated (see Notes)} - -\item{proportions_only}{If \code{FALSE}, return full distance matrices for full -distances and for each edge category; if \code{TRUE}, return single vector of -proportional distances, like current \code{summary} function applied to full -results. See Note.} - -\item{dlimit}{If \code{TRUE}, and no value to \code{to} is given, distances are -aggregated from each \code{from} point out to the specified distance limit (in -metres). The \code{proportions_only} argument has no effect when \code{dlimit = TRUE}.} - -\item{heap}{Type of heap to use in priority queue. Options include -Fibonacci Heap (default; \code{FHeap}), Binary Heap (\code{BHeap}), -\verb{Trinomial Heap (}TriHeap\verb{), Extended Trinomial Heap (}TriHeapExt\verb{, and 2-3 Heap (}Heap23`).} - -\item{quiet}{If \code{FALSE}, display progress messages on screen.} -} -\value{ -If \code{dlimit = FALSE}, a list of distance matrices of equal dimensions (length(from), -length(to)), the first of which ("distance") holds the final distances, while -the rest are one matrix for each unique value of "edge_type", holding the -distances traversed along those types of edges only. If \code{dlimit = TRUE}, a -single matrix of total distances along all ways from each point, along with -distances along each of the different kinds of ways specified in the -"edge_type" column of the input graph. -} -\description{ -Proportional distances along different edge categories -} -\note{ -The "edge_type" column in the graph can contain any kind of discrete or -categorical values, although integer values of 0 are not permissible. \code{NA} -values are ignored. The function requires one full distance -matrix to be stored for each category of "edge_type" (unless -\code{proportions_only = TRUE}). It is wise to keep numbers of discrete types as -low as possible, especially for large distance matrices. - -Setting the \code{proportions_only} flag to \code{TRUE} may be advantageous for -large jobs, because this avoids construction of the full matrices. This may -speed up calculations, but perhaps more importantly it may make possible -calculations which would otherwise require distance matrices too large to be -directly stored. -} diff --git a/man/summary.dodgr_dists_proportional.Rd b/man/summary.dodgr_dists_proportional.Rd deleted file mode 100644 index 6c11e6288..000000000 --- a/man/summary.dodgr_dists_proportional.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dists-proportional.R -\name{summary.dodgr_dists_proportional} -\alias{summary.dodgr_dists_proportional} -\title{Transform a result from 'dodgr_dists_proportional' to summary statistics} -\usage{ -\method{summary}{dodgr_dists_proportional}(object, ...) -} -\arguments{ -\item{object}{A 'dodgr_dists_proportional' object} - -\item{...}{Extra parameters currently not used} -} -\value{ -The summary statistics (invisibly) -} -\description{ -Transform a result from 'dodgr_dists_proportional' to summary statistics -} diff --git a/src/Makevars b/src/Makevars index 831c2b60d..fc96c3db8 100644 --- a/src/Makevars +++ b/src/Makevars @@ -8,7 +8,7 @@ OBJ_HEAPS = heaps/bheap.o heaps/fheap.o heaps/heap23.o \ heaps/triheap_ext.o heaps/triheap.o OBJ_SRC = centrality.o dgraph.o pathfinders.o dodgr-to-sf.o flows.o fund-cycles.o \ graph-contract.o graph.o graph-sample.o RcppExports.o run_sp.o \ - run_sp_proportional.o sc-as-network.o sf-as-network.o turn_penalty.o + run_sp_categorical.o sc-as-network.o sf-as-network.o turn_penalty.o OBJECTS = $(OBJ_HEAPS) $(OBJ_SRC) .PHONY: all clean diff --git a/src/Makevars.win b/src/Makevars.win index 7a93d54f9..d9dc78993 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -9,7 +9,7 @@ OBJ_HEAPS = heaps/bheap.o heaps/fheap.o heaps/heap23.o \ heaps/triheap_ext.o heaps/triheap.o OBJ_SRC = centrality.o dgraph.o pathfinders.o dodgr-to-sf.o flows.o fund-cycles.o \ graph-contract.o graph.o graph-sample.o RcppExports.o run_sp.o \ - run_sp_proportional.o sc-as-network.o sf-as-network.o turn_penalty.o + run_sp_categorical.o sc-as-network.o sf-as-network.o turn_penalty.o OBJECTS = $(OBJ_HEAPS) $(OBJ_SRC) .PHONY: all clean diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 26dc1d88c..614fd42b5 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -242,9 +242,9 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// rcpp_get_sp_dists_proportional -Rcpp::NumericMatrix rcpp_get_sp_dists_proportional(const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, Rcpp::IntegerVector toi_in, const std::string& heap_type, const bool proportions_only); -RcppExport SEXP _dodgr_rcpp_get_sp_dists_proportional(SEXP graphSEXP, SEXP vert_map_inSEXP, SEXP fromiSEXP, SEXP toi_inSEXP, SEXP heap_typeSEXP, SEXP proportions_onlySEXP) { +// rcpp_get_sp_dists_categorical +Rcpp::NumericMatrix rcpp_get_sp_dists_categorical(const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, Rcpp::IntegerVector toi_in, const std::string& heap_type, const bool proportions_only); +RcppExport SEXP _dodgr_rcpp_get_sp_dists_categorical(SEXP graphSEXP, SEXP vert_map_inSEXP, SEXP fromiSEXP, SEXP toi_inSEXP, SEXP heap_typeSEXP, SEXP proportions_onlySEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -254,13 +254,13 @@ BEGIN_RCPP Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type toi_in(toi_inSEXP); Rcpp::traits::input_parameter< const std::string& >::type heap_type(heap_typeSEXP); Rcpp::traits::input_parameter< const bool >::type proportions_only(proportions_onlySEXP); - rcpp_result_gen = Rcpp::wrap(rcpp_get_sp_dists_proportional(graph, vert_map_in, fromi, toi_in, heap_type, proportions_only)); + rcpp_result_gen = Rcpp::wrap(rcpp_get_sp_dists_categorical(graph, vert_map_in, fromi, toi_in, heap_type, proportions_only)); return rcpp_result_gen; END_RCPP } -// rcpp_get_sp_dists_prop_threshold -Rcpp::NumericMatrix rcpp_get_sp_dists_prop_threshold(const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, const double dlimit, const std::string& heap_type); -RcppExport SEXP _dodgr_rcpp_get_sp_dists_prop_threshold(SEXP graphSEXP, SEXP vert_map_inSEXP, SEXP fromiSEXP, SEXP dlimitSEXP, SEXP heap_typeSEXP) { +// rcpp_get_sp_dists_cat_threshold +Rcpp::NumericMatrix rcpp_get_sp_dists_cat_threshold(const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, const double dlimit, const std::string& heap_type); +RcppExport SEXP _dodgr_rcpp_get_sp_dists_cat_threshold(SEXP graphSEXP, SEXP vert_map_inSEXP, SEXP fromiSEXP, SEXP dlimitSEXP, SEXP heap_typeSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -269,7 +269,7 @@ BEGIN_RCPP Rcpp::traits::input_parameter< Rcpp::IntegerVector >::type fromi(fromiSEXP); Rcpp::traits::input_parameter< const double >::type dlimit(dlimitSEXP); Rcpp::traits::input_parameter< const std::string& >::type heap_type(heap_typeSEXP); - rcpp_result_gen = Rcpp::wrap(rcpp_get_sp_dists_prop_threshold(graph, vert_map_in, fromi, dlimit, heap_type)); + rcpp_result_gen = Rcpp::wrap(rcpp_get_sp_dists_cat_threshold(graph, vert_map_in, fromi, dlimit, heap_type)); return rcpp_result_gen; END_RCPP } @@ -340,8 +340,8 @@ static const R_CallMethodDef CallEntries[] = { {"_dodgr_rcpp_get_iso", (DL_FUNC) &_dodgr_rcpp_get_iso, 5}, {"_dodgr_rcpp_get_sp_dists", (DL_FUNC) &_dodgr_rcpp_get_sp_dists, 5}, {"_dodgr_rcpp_get_paths", (DL_FUNC) &_dodgr_rcpp_get_paths, 5}, - {"_dodgr_rcpp_get_sp_dists_proportional", (DL_FUNC) &_dodgr_rcpp_get_sp_dists_proportional, 6}, - {"_dodgr_rcpp_get_sp_dists_prop_threshold", (DL_FUNC) &_dodgr_rcpp_get_sp_dists_prop_threshold, 5}, + {"_dodgr_rcpp_get_sp_dists_categorical", (DL_FUNC) &_dodgr_rcpp_get_sp_dists_categorical, 6}, + {"_dodgr_rcpp_get_sp_dists_cat_threshold", (DL_FUNC) &_dodgr_rcpp_get_sp_dists_cat_threshold, 5}, {"_dodgr_rcpp_gen_hash", (DL_FUNC) &_dodgr_rcpp_gen_hash, 2}, {"_dodgr_rcpp_sf_as_network", (DL_FUNC) &_dodgr_rcpp_sf_as_network, 2}, {"_dodgr_rcpp_points_index_par", (DL_FUNC) &_dodgr_rcpp_points_index_par, 2}, diff --git a/src/pathfinders.h b/src/pathfinders.h index 3d9cecf1e..bc99e9054 100644 --- a/src/pathfinders.h +++ b/src/pathfinders.h @@ -86,7 +86,7 @@ class PathFinder { const bool *m_closed_vec, const size_t &v0, const std::vector &heur); - // with A* heuristic for dists-proportional + // with A* heuristic for dists-categorical void scan_edge_types_heur ( const DGraphEdge *edge, std::vector& d, @@ -96,7 +96,7 @@ class PathFinder { const bool *m_closed_vec, const size_t &v0, const std::vector &heur); - // run_sp_proportional for threshold dists + // run_sp_categorical for threshold dists void scan_edge_types ( const DGraphEdge *edge, std::vector& d, @@ -112,7 +112,7 @@ class PathFinder { std::vector& prev, const size_t v0, const std::vector &to_index); - void DijkstraLimit ( // run_sp_proportional + void DijkstraLimit ( // run_sp_categorical std::vector& d, std::vector& w, std::vector& prev, diff --git a/src/run_sp.h b/src/run_sp.h index 042888d1a..b6579a697 100644 --- a/src/run_sp.h +++ b/src/run_sp.h @@ -38,11 +38,11 @@ void make_vert_to_edge_maps (const std::vector &from, size_t get_chunk_size (const size_t nfrom); } // end namespace run_sp -namespace proportional { +namespace categorical { size_t num_edge_types (const std::vector &edge_type); -} // end namespace proportional +} // end namespace categorical Rcpp::NumericMatrix rcpp_get_sp_dists (const Rcpp::DataFrame graph, @@ -77,15 +77,15 @@ Rcpp::List rcpp_get_paths (const Rcpp::DataFrame graph, Rcpp::IntegerVector toi_in, const std::string& heap_type); -// in run_sp_proportional: -Rcpp::NumericMatrix rcpp_get_sp_dists_proportional (const Rcpp::DataFrame graph, +// in run_sp_categorical: +Rcpp::NumericMatrix rcpp_get_sp_dists_categorical (const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, Rcpp::IntegerVector toi_in, const std::string& heap_type, const bool proportions_only); -Rcpp::NumericMatrix rcpp_get_sp_dists_prop_threshold (const Rcpp::DataFrame graph, +Rcpp::NumericMatrix rcpp_get_sp_dists_cat_threshold (const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, const double dlimit, diff --git a/src/run_sp_proportional.cpp b/src/run_sp_categorical.cpp similarity index 94% rename from src/run_sp_proportional.cpp rename to src/run_sp_categorical.cpp index ca7abe47e..4bd70c7eb 100644 --- a/src/run_sp_proportional.cpp +++ b/src/run_sp_categorical.cpp @@ -1,4 +1,4 @@ -// Modified functions from run_sp.cpp to calculate proportional distances along +// Modified functions from run_sp.cpp to calculate categorical distances along // defined kinds of ways (issue #144) #include "run_sp.h" @@ -26,7 +26,7 @@ void inst_graph (std::shared_ptr g, size_t nedges, } // # nocov end -struct OneProportionalDist : public RcppParallel::Worker +struct OneCategoricalDist : public RcppParallel::Worker { RcppParallel::RVector dp_fromi; const std::vector toi; @@ -41,7 +41,7 @@ struct OneProportionalDist : public RcppParallel::Worker RcppParallel::RMatrix dout; // constructor - OneProportionalDist ( + OneCategoricalDist ( const RcppParallel::RVector fromi, const std::vector toi_in, const std::vector edge_type_in, @@ -104,9 +104,9 @@ struct OneProportionalDist : public RcppParallel::Worker }; -// Modified version of OneProportionalDist to aggregate only a vector of +// Modified version of OneCategoricalDist to aggregate only a vector of // distances, one value for each `from`. -struct OneProportion : public RcppParallel::Worker +struct OneCategory : public RcppParallel::Worker { RcppParallel::RVector dp_fromi; const std::vector toi; @@ -121,7 +121,7 @@ struct OneProportion : public RcppParallel::Worker RcppParallel::RMatrix dout; // constructor - OneProportion ( + OneCategory ( const RcppParallel::RVector fromi, const std::vector toi_in, const std::vector edge_type_in, @@ -186,9 +186,9 @@ struct OneProportion : public RcppParallel::Worker }; -// Modified version of OneProportion to aggregate vector of proportional +// Modified version of OneCategory to aggregate vector of categorical // distances out to a specified threshold, one value for each `from`. -struct OnePropThreshold : public RcppParallel::Worker +struct OneCatThreshold : public RcppParallel::Worker { RcppParallel::RVector dp_fromi; const std::vector edge_type; @@ -201,7 +201,7 @@ struct OnePropThreshold : public RcppParallel::Worker RcppParallel::RMatrix dout; // constructor - OnePropThreshold ( + OneCatThreshold ( const RcppParallel::RVector fromi, const std::vector edge_type_in, const size_t nverts_in, @@ -274,7 +274,7 @@ struct OnePropThreshold : public RcppParallel::Worker }; -size_t proportional::num_edge_types (const std::vector &edge_type) +size_t categorical::num_edge_types (const std::vector &edge_type) { std::unordered_set type_set; for (auto e: edge_type) @@ -472,7 +472,7 @@ void PF::PathFinder::scan_edge_types (const DGraphEdge *edge, } } -//' rcpp_get_sp_dists_proportional +//' rcpp_get_sp_dists_categorical //' //' The `graph` must have an `edge_type` column of non-negative integers, //' with 0 denoting edges which are not aggregated, and all other values @@ -482,7 +482,7 @@ void PF::PathFinder::scan_edge_types (const DGraphEdge *edge, //' only for AStar (so graphs must be spatial). //' @noRd // [[Rcpp::export]] -Rcpp::NumericMatrix rcpp_get_sp_dists_proportional (const Rcpp::DataFrame graph, +Rcpp::NumericMatrix rcpp_get_sp_dists_categorical (const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, Rcpp::IntegerVector toi_in, @@ -501,7 +501,7 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_proportional (const Rcpp::DataFrame graph, const std::vector wt = graph ["d_weighted"]; const std::vector edge_type = graph ["edge_type"]; - const size_t num_types = proportional::num_edge_types (edge_type); + const size_t num_types = categorical::num_edge_types (edge_type); const size_t nedges = static_cast (graph.nrow ()); std::map vert_map; @@ -532,15 +532,15 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_proportional (const Rcpp::DataFrame graph, size_t chunk_size = run_sp::get_chunk_size (nfrom); if (proportions_only) { - OneProportion one_dist (RcppParallel::RVector (fromi), toi, + OneCategory one_dist (RcppParallel::RVector (fromi), toi, edge_type, nverts, vx, vy, g, heap_type, num_types, RcppParallel::RMatrix (dout)); RcppParallel::parallelFor (0, nfrom, one_dist, chunk_size); } else { - OneProportionalDist one_dist (RcppParallel::RVector (fromi), toi, - edge_type, nverts, vx, vy, + OneCategoricalDist one_dist (RcppParallel::RVector (fromi), + toi, edge_type, nverts, vx, vy, g, heap_type, num_types, RcppParallel::RMatrix (dout)); RcppParallel::parallelFor (0, nfrom, one_dist, chunk_size); @@ -550,7 +550,7 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_proportional (const Rcpp::DataFrame graph, return (dout); } -//' rcpp_get_sp_dists_prop_threshold +//' rcpp_get_sp_dists_cat_threshold //' //' The `graph` must have an `edge_type` column of non-negative integers, //' with 0 denoting edges which are not aggregated, and all other values @@ -560,7 +560,7 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_proportional (const Rcpp::DataFrame graph, //' only for AStar (so graphs must be spatial). //' @noRd // [[Rcpp::export]] -Rcpp::NumericMatrix rcpp_get_sp_dists_prop_threshold (const Rcpp::DataFrame graph, +Rcpp::NumericMatrix rcpp_get_sp_dists_cat_threshold (const Rcpp::DataFrame graph, const Rcpp::DataFrame vert_map_in, Rcpp::IntegerVector fromi, const double dlimit, @@ -574,7 +574,7 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_prop_threshold (const Rcpp::DataFrame grap const std::vector wt = graph ["d_weighted"]; const std::vector edge_type = graph ["edge_type"]; - const size_t num_types = proportional::num_edge_types (edge_type); + const size_t num_types = categorical::num_edge_types (edge_type); const size_t nedges = static_cast (graph.nrow ()); std::map vert_map; @@ -595,7 +595,7 @@ Rcpp::NumericMatrix rcpp_get_sp_dists_prop_threshold (const Rcpp::DataFrame grap // Create parallel worker size_t chunk_size = run_sp::get_chunk_size (nfrom); - OnePropThreshold one_dist (RcppParallel::RVector (fromi), + OneCatThreshold one_dist (RcppParallel::RVector (fromi), edge_type, nverts, g, heap_type, num_types, dlimit, RcppParallel::RMatrix (dout)); diff --git a/tests/testthat/test-dists-proportional.R b/tests/testthat/test-dists-categorical.R similarity index 77% rename from tests/testthat/test-dists-proportional.R rename to tests/testthat/test-dists-categorical.R index 6db8b1625..125c676b5 100644 --- a/tests/testthat/test-dists-proportional.R +++ b/tests/testthat/test-dists-categorical.R @@ -1,4 +1,4 @@ -context("dodgr_dists_proportional") +context("dodgr_dists_categorical") test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") | identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage")) @@ -7,7 +7,7 @@ if (!test_all) { RcppParallel::setThreadOptions(numThreads = 2) } -test_that("proportional dists", { +test_that("categorical dists", { expect_silent(graph <- weight_streetnet(hampi)) @@ -17,20 +17,20 @@ test_that("proportional dists", { from <- sample(graph$from_id, size = nf) to <- sample(graph$to_id, size = nt) - expect_error (d <- dodgr_dists_proportional (graph, + expect_error (d <- dodgr_dists_categorical (graph, from, to), "graph must have a column named 'edge_type'") graph$edge_type <- 1L graph$edge_type [1] <- 0L - expect_error (d <- dodgr_dists_proportional (graph, + expect_error (d <- dodgr_dists_categorical (graph, from, to), "graphs with integer edge_type columns may not contain 0s") graph$edge_type <- graph$highway - expect_silent(d <- dodgr_dists_proportional(graph, from = from, to = to)) + expect_silent(d <- dodgr_dists_categorical(graph, from = from, to = to)) expect_type (d, "list") ntypes <- length (unique (graph$highway)) expect_length (d, ntypes + 1L) @@ -43,13 +43,13 @@ test_that("proportional dists", { expect_true (all (dims [2, ] == nt)) expect_message( - d2 <- dodgr_dists_proportional(graph, from = from, to = to, quiet = FALSE), + d2 <- dodgr_dists_categorical(graph, from = from, to = to, quiet = FALSE), "Calculating shortest paths ..." ) expect_identical(d, d2) }) -test_that("proportional dists summary", { +test_that("categorical dists summary", { expect_silent(graph <- weight_streetnet(hampi)) graph <- graph [graph$component == 1, ] @@ -60,7 +60,7 @@ test_that("proportional dists summary", { graph$edge_type <- graph$highway - expect_silent (d <- dodgr_dists_proportional (graph, from, to)) + expect_silent (d <- dodgr_dists_categorical (graph, from, to)) expect_message (ds <- summary (d)) expect_is (ds, "numeric") @@ -79,7 +79,7 @@ test_that ("proportions only", { graph$edge_type <- graph$highway - expect_silent (d <- dodgr_dists_proportional (graph, from, to)) + expect_silent (d <- dodgr_dists_categorical (graph, from, to)) d0 <- d$distances d <- d [-1] @@ -87,14 +87,14 @@ test_that ("proportions only", { numeric (1)) d1 <- dtypes / sum (colSums (d0)) - expect_silent (d2 <- dodgr_dists_proportional (graph, from, to, - proportions_only = TRUE)) + expect_silent (d2 <- dodgr_dists_categorical (graph, from, to, + proportions_only = TRUE)) # These will only be approximately equal: expect_true (mean (abs (d1 - d2)) > 0) expect_true (max (abs (d1 - d2)) < 0.01) # within 1% }) -test_that ("proportion threshold", { +test_that ("categorical threshold", { expect_silent(graph <- weight_streetnet(hampi)) graph <- graph [graph$component == 1, ] @@ -104,7 +104,7 @@ test_that ("proportion threshold", { graph$edge_type <- graph$highway - expect_silent (d <- dodgr_dists_proportional (graph, from, dlimit = 2000)) + expect_silent (d <- dodgr_dists_categorical (graph, from, dlimit = 2000)) expect_is (d, "data.frame") expect_equal (nrow (d), length (from))