Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -1716,9 +1716,10 @@ diversity <- function(
#' scores are the same as authority scores.
#'
#' @param graph The input graph.
#' @param scale Logical, whether to scale the result to have a maximum
#' score of one. If no scaling is used then the result vector has unit length
#' in the Euclidean norm.
#' @param scale `r lifecycle::badge("superseded")` Logical, whether to scale
#' the result to have a maximum score of one, which the C core now always does.
#' With `FALSE`, the result vector is rescaled to unit length in the Euclidean norm,
#' except for graphs without (nonzero) edges, where all scores stay one.
#' @param weights Optional positive weight vector for calculating weighted
#' scores. If the graph has a `weight` edge attribute, then this is used
#' by default. Pass `NA` to ignore the weight attribute. This function
Expand Down
14 changes: 14 additions & 0 deletions R/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,20 @@ cluster_edge_betweenness <- function(
as.logical(modularity),
as.logical(membership)
)
# igraph 0.10 warned about weighted runs in the C core, which no longer does;
# only the first of its two warnings reached R.
if (!is.null(weights)) {
if (isTRUE(as.logical(membership))) {
cli::cli_warn(
"Membership vector will be selected based on the highest modularity score."
)
} else if (isTRUE(as.logical(modularity))) {
cli::cli_warn(paste(
"Modularity calculation with weighted edge betweenness community detection might not make sense --",
"modularity treats edge weights as similarities while edge betweenness treats them as distances."
))
}
}
if (igraph_opt("add.vertex.names") && is_named(graph)) {
res$names <- V(graph)$name
}
Expand Down
10 changes: 0 additions & 10 deletions R/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,6 @@ graph_center <- function(
)
}

# Upstream merged the weighted `_dijkstra` variants into the base functions,
# which take their weights argument (krlmlr/igraph@d8febb1): the
# `_dijkstra_impl()` names stay, as aliases with the same arguments.
average_path_length_dijkstra_impl <- average_path_length_impl
diameter_dijkstra_impl <- diameter_impl
eccentricity_dijkstra_impl <- eccentricity_impl
graph_center_dijkstra_impl <- graph_center_impl
pseudo_diameter_dijkstra_impl <- pseudo_diameter_impl
radius_dijkstra_impl <- radius_impl

#' @rdname distances
#' @inheritParams rlang::args_dots_empty
#' @param directed Whether to consider directed paths in directed graphs,
Expand Down
7 changes: 4 additions & 3 deletions man/hits_scores.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions src/rinterface_extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -6001,20 +6001,10 @@ SEXP Rx_igraph_community_edge_betweenness(SEXP graph, SEXP pweights,
* weights as path lengths for the betweenness, and to weigh the modularity
* that picks the membership. So the edges are removed by lengths, and the
* merges, modularity and membership come from
* igraph_community_eb_get_merges() with the weights, as igraph 0.10 did,
* with the warnings it gave. */
* igraph_community_eb_get_merges() with the weights, as igraph 0.10 did.
* The warnings igraph 0.10 gave here are raised by cluster_edge_betweenness(). */
if (ppweights) {
IGRAPH_R_CHECK(igraph_community_edge_betweenness(&g, &res, ppeb, 0, 0, 0, 0, directed, /* weights = */ 0, /* lengths = */ ppweights));
if (ppmembership) {
IGRAPH_WARNING("Membership vector will be selected based on the highest "
"modularity score.");
}
if (ppmodularity || ppmembership) {
IGRAPH_WARNING("Modularity calculation with weighted edge betweenness "
"community detection might not make sense -- modularity treats edge "
"weights as similarities while edge betwenness treats them as "
"distances.");
}
if (ppmerges || ppbridges || ppmodularity || ppmembership) {
IGRAPH_R_CHECK(igraph_community_eb_get_merges(&g, directed, &res, ppweights, ppmerges, ppbridges, ppmodularity, ppmembership));
}
Expand Down
69 changes: 15 additions & 54 deletions tests/testthat/_snaps/aaa-auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -3689,70 +3689,70 @@
Error in `ensure_igraph()`:
! Must provide a graph object (provided `NULL`).

# eccentricity_dijkstra_impl basic
# eccentricity_impl modes

Code
eccentricity_dijkstra_impl(graph = g)
eccentricity_impl(graph = g)
Output
[1] 2 1 2

---

Code
eccentricity_dijkstra_impl(graph = g, mode = "in")
eccentricity_impl(graph = g, mode = "in")
Output
[1] 2 1 2

# eccentricity_dijkstra_impl errors
# eccentricity_impl errors

Code
eccentricity_dijkstra_impl(graph = NULL)
eccentricity_impl(graph = NULL)
Condition
Error in `ensure_igraph()`:
! Must provide a graph object (provided `NULL`).

# graph_center_dijkstra_impl basic
# graph_center_impl modes

Code
graph_center_dijkstra_impl(graph = g)
graph_center_impl(graph = g)
Output
+ 1/3 vertex:
[1] 2

---

Code
graph_center_dijkstra_impl(graph = g, mode = "in")
graph_center_impl(graph = g, mode = "in")
Output
+ 1/3 vertex:
[1] 2

# graph_center_dijkstra_impl errors
# graph_center_impl errors

Code
graph_center_dijkstra_impl(graph = NULL)
graph_center_impl(graph = NULL)
Condition
Error in `ensure_igraph()`:
! Must provide a graph object (provided `NULL`).

# radius_dijkstra_impl basic
# radius_impl modes

Code
radius_dijkstra_impl(graph = g)
radius_impl(graph = g)
Output
[1] 1

---

Code
radius_dijkstra_impl(graph = g, mode = "in")
radius_impl(graph = g, mode = "in")
Output
[1] 1

# radius_dijkstra_impl errors
# radius_impl errors

Code
radius_dijkstra_impl(graph = NULL)
radius_impl(graph = NULL)
Condition
Error in `ensure_igraph()`:
! Must provide a graph object (provided `NULL`).
Expand Down Expand Up @@ -3795,45 +3795,6 @@
Error in `ensure_igraph()`:
! Must provide a graph object (provided `NULL`).

# pseudo_diameter_dijkstra_impl basic

Code
pseudo_diameter_dijkstra_impl(graph = g, start_vid = 1)
Output
$diameter
[1] 2

$from
[1] 0

$to
[1] 2


---

Code
pseudo_diameter_dijkstra_impl(graph = g, start_vid = 1, directed = FALSE,
unconnected = FALSE)
Output
$diameter
[1] 2

$from
[1] 0

$to
[1] 2


# pseudo_diameter_dijkstra_impl errors

Code
pseudo_diameter_dijkstra_impl(graph = NULL, start_vid = 1)
Condition
Error in `ensure_igraph()`:
! Must provide a graph object (provided `NULL`).

# diversity_impl basic

Code
Expand Down
79 changes: 21 additions & 58 deletions tests/testthat/test-aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -3827,92 +3827,92 @@ test_that("contract_vertices_impl errors", {
))
})

# 150. eccentricity_dijkstra_impl
# 150. eccentricity_impl

test_that("eccentricity_dijkstra_impl basic", {
test_that("eccentricity_impl modes", {
igraph_local_seed(20250909)
g <- path_graph_impl(
n = 3
)

expect_snapshot(eccentricity_dijkstra_impl(
expect_snapshot(eccentricity_impl(
graph = g
))
expect_snapshot(eccentricity_dijkstra_impl(
expect_snapshot(eccentricity_impl(
graph = g,
mode = "in"
))

# Structured tests
result <- eccentricity_dijkstra_impl(
result <- eccentricity_impl(
graph = g
)
expect_true(is.numeric(result))
})

test_that("eccentricity_dijkstra_impl errors", {
test_that("eccentricity_impl errors", {
igraph_local_seed(20250909)
expect_snapshot_igraph_error(eccentricity_dijkstra_impl(
expect_snapshot_igraph_error(eccentricity_impl(
graph = NULL
))
})

# 151. graph_center_dijkstra_impl
# 151. graph_center_impl

test_that("graph_center_dijkstra_impl basic", {
test_that("graph_center_impl modes", {
igraph_local_seed(20250909)
g <- path_graph_impl(
n = 3
)

expect_snapshot(graph_center_dijkstra_impl(
expect_snapshot(graph_center_impl(
graph = g
))
expect_snapshot(graph_center_dijkstra_impl(
expect_snapshot(graph_center_impl(
graph = g,
mode = "in"
))

# Structured tests
result <- graph_center_dijkstra_impl(
result <- graph_center_impl(
graph = g
)
expect_s3_class(result, "igraph.vs")
})

test_that("graph_center_dijkstra_impl errors", {
test_that("graph_center_impl errors", {
igraph_local_seed(20250909)
expect_snapshot_igraph_error(graph_center_dijkstra_impl(
expect_snapshot_igraph_error(graph_center_impl(
graph = NULL
))
})

# 152. radius_dijkstra_impl
# 152. radius_impl

test_that("radius_dijkstra_impl basic", {
test_that("radius_impl modes", {
igraph_local_seed(20250909)
g <- path_graph_impl(
n = 3
)

expect_snapshot(radius_dijkstra_impl(
expect_snapshot(radius_impl(
graph = g
))
expect_snapshot(radius_dijkstra_impl(
expect_snapshot(radius_impl(
graph = g,
mode = "in"
))

# Structured tests
result <- radius_dijkstra_impl(
result <- radius_impl(
graph = g
)
expect_true(is.numeric(result))
})

test_that("radius_dijkstra_impl errors", {
test_that("radius_impl errors", {
igraph_local_seed(20250909)
expect_snapshot_igraph_error(radius_dijkstra_impl(
expect_snapshot_igraph_error(radius_impl(
graph = NULL
))
})
Expand Down Expand Up @@ -3952,43 +3952,6 @@ test_that("pseudo_diameter_impl errors", {
))
})

# 154. pseudo_diameter_dijkstra_impl

test_that("pseudo_diameter_dijkstra_impl basic", {
igraph_local_seed(20250909)
g <- path_graph_impl(
n = 3
)

expect_snapshot(pseudo_diameter_dijkstra_impl(
graph = g,
start_vid = 1
))
expect_snapshot(pseudo_diameter_dijkstra_impl(
graph = g,
start_vid = 1,
directed = FALSE,
unconnected = FALSE
))

# Structured tests
result <- pseudo_diameter_dijkstra_impl(
graph = g,
start_vid = 1
)
expect_type(result, "list")
})

test_that("pseudo_diameter_dijkstra_impl errors", {
igraph_local_seed(20250909)
expect_snapshot_igraph_error(
pseudo_diameter_dijkstra_impl(
graph = NULL,
start_vid = 1
)
)
})

# 155. diversity_impl

test_that("diversity_impl basic", {
Expand Down
Loading
Loading