Skip to content

Commit e494b0a

Browse files
committed
Merge branch 'main' into next
2 parents 3e3abfd + c5bcecc commit e494b0a

File tree

14 files changed

+170
-451
lines changed

14 files changed

+170
-451
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pak::pak(dependencies = "Config/Needs/build")
4949

5050
- IMPORTANT: PR titles end up in `NEWS.md` grouped by conventional commit label. PRs and commits use the conventional commit style with backticks for code references such as `function_call()`
5151
- PRs are generally squashed, a clean history within a PR is not necessary
52+
- Before resuming work on a PR, always merge the current base branch (typically `main`)
5253

5354
### Comment Style
5455

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: igraph
22
Title: Network Analysis and Visualization
3-
Version: 2.2.1.9003
3+
Version: 2.2.1.9004
44
Authors@R: c(
55
person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = "aut",
66
comment = c(ORCID = "0000-0001-7098-9676")),

R/centrality.R

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -588,43 +588,14 @@ closeness <- function(
588588
normalized = FALSE,
589589
cutoff = -1
590590
) {
591-
# Argument checks
592-
ensure_igraph(graph)
593-
594-
vids <- as_igraph_vs(graph, vids)
595-
mode <- switch(
596-
igraph_match_arg(mode),
597-
"out" = 1,
598-
"in" = 2,
599-
"all" = 3,
600-
"total" = 3
601-
)
602-
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
603-
weights <- E(graph)$weight
604-
}
605-
if (!is.null(weights) && any(!is.na(weights))) {
606-
weights <- as.numeric(weights)
607-
} else {
608-
weights <- NULL
609-
}
610-
normalized <- as.logical(normalized)
611-
cutoff <- as.numeric(cutoff)
612-
613-
on.exit(.Call(R_igraph_finalizer))
614-
# Function call
615-
res <- .Call(
616-
R_igraph_closeness_cutoff,
617-
graph,
618-
vids - 1,
619-
mode,
620-
weights,
621-
normalized,
622-
cutoff
591+
closeness_cutoff_impl(
592+
graph = graph,
593+
vids = vids,
594+
mode = mode,
595+
weights = weights,
596+
normalized = normalized,
597+
cutoff = cutoff
623598
)$res
624-
if (igraph_opt("add.vertex.names") && is_named(graph)) {
625-
names(res) <- V(graph)$name[vids]
626-
}
627-
res
628599
}
629600

630601
#' Deprecated version of `closeness()`

R/community.R

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -911,33 +911,18 @@ modularity.igraph <- function(
911911
directed = TRUE,
912912
...
913913
) {
914-
# Argument checks
915-
ensure_igraph(x)
916914
if (
917915
is.null(membership) || (!is.numeric(membership) && !is.factor(membership))
918916
) {
919917
cli::cli_abort("Membership is not a numerical vector")
920918
}
921-
membership <- as.numeric(membership)
922-
if (!is.null(weights) && any(!is.na(weights))) {
923-
weights <- as.numeric(weights)
924-
} else {
925-
weights <- NULL
926-
}
927-
resolution <- as.numeric(resolution)
928-
directed <- as.logical(directed)
929-
930-
on.exit(.Call(R_igraph_finalizer))
931-
# Function call
932-
res <- .Call(
933-
R_igraph_modularity,
934-
x,
935-
membership - 1,
936-
weights,
937-
resolution,
938-
directed
919+
modularity_impl(
920+
graph = x,
921+
membership = membership,
922+
weights = weights,
923+
resolution = resolution,
924+
directed = directed
939925
)
940-
res
941926
}
942927

943928
#' @rdname communities
@@ -1781,17 +1766,9 @@ cluster_leiden <- function(
17811766
#' g <- make_graph("Zachary")
17821767
#' comms <- cluster_fluid_communities(g, 2)
17831768
cluster_fluid_communities <- function(graph, no.of.communities) {
1784-
# Argument checks
1785-
ensure_igraph(graph)
1786-
1787-
no.of.communities <- as.numeric(no.of.communities)
1788-
1789-
on.exit(.Call(R_igraph_finalizer))
1790-
# Function call
1791-
membership <- .Call(
1792-
R_igraph_community_fluid_communities,
1793-
graph,
1794-
no.of.communities
1769+
membership <- community_fluid_communities_impl(
1770+
graph = graph,
1771+
no_of_communities = no.of.communities
17951772
)
17961773

17971774
res <- list()

R/flow.R

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,12 @@ min_cut <- function(
434434
capacity
435435
)
436436
} else {
437-
res <- .Call(
438-
R_igraph_st_mincut,
439-
graph,
440-
as_igraph_vs(graph, source) - 1,
441-
as_igraph_vs(graph, target) - 1,
442-
capacity
437+
res <- st_mincut_impl(
438+
graph = graph,
439+
source = source,
440+
target = target,
441+
capacity = capacity
443442
)
444-
# No need to add +1 here; R_igraph_st_mincut() is autogenerated and
445-
# adds +1 already
446-
if (igraph_opt("return.vs.es")) {
447-
res$cut <- create_es(graph, res$cut)
448-
res$partition1 <- create_vs(graph, res$partition1)
449-
res$partition2 <- create_vs(graph, res$partition2)
450-
}
451443
}
452444
}
453445

R/games.R

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ pa <- function(...) constructor_spec(sample_pa, ...)
10161016
#' plot(sample_gnp(6, 0.5))
10171017
sample_gnp <- function(n, p, directed = FALSE, loops = FALSE) {
10181018
type <- "gnp"
1019-
type1 <- switch(type, "gnp" = 0, "gnm" = 1)
10201019

10211020
res <- erdos_renyi_game_gnp_impl(
10221021
n = n,
@@ -1067,16 +1066,12 @@ gnp <- function(...) constructor_spec(sample_gnp, ...)
10671066
#' degree_distribution(g)
10681067
sample_gnm <- function(n, m, directed = FALSE, loops = FALSE) {
10691068
type <- "gnm"
1070-
type1 <- switch(type, "gnp" = 0, "gnm" = 1)
10711069

1072-
on.exit(.Call(R_igraph_finalizer))
1073-
res <- .Call(
1074-
R_igraph_erdos_renyi_game_gnm,
1075-
as.numeric(n),
1076-
as.numeric(m),
1077-
as.logical(directed),
1078-
as.logical(loops),
1079-
FALSE
1070+
res <- erdos_renyi_game_gnm_impl(
1071+
n = n,
1072+
m = m,
1073+
directed = directed,
1074+
loops = loops
10801075
)
10811076

10821077
if (igraph_opt("add.params")) {
@@ -1950,16 +1945,14 @@ sample_pref <- function(
19501945
))
19511946
}
19521947

1953-
on.exit(.Call(R_igraph_finalizer))
1954-
res <- .Call(
1955-
R_igraph_preference_game,
1956-
as.numeric(nodes),
1957-
as.numeric(types),
1958-
as.double(type.dist),
1959-
as.logical(fixed.sizes),
1960-
matrix(as.double(pref.matrix), types, types),
1961-
as.logical(directed),
1962-
as.logical(loops)
1948+
res <- preference_game_impl(
1949+
nodes = nodes,
1950+
types = types,
1951+
type_dist = type.dist,
1952+
fixed_sizes = fixed.sizes,
1953+
pref_matrix = pref.matrix,
1954+
directed = directed,
1955+
loops = loops
19631956
)
19641957
V(res[[1]])$type <- res[[2]] + 1
19651958
if (igraph_opt("add.params")) {
@@ -2001,15 +1994,13 @@ sample_asym_pref <- function(
20011994
))
20021995
}
20031996

2004-
on.exit(.Call(R_igraph_finalizer))
2005-
res <- .Call(
2006-
R_igraph_asymmetric_preference_game,
2007-
as.numeric(nodes),
2008-
as.numeric(types),
2009-
as.numeric(types),
2010-
matrix(as.double(type.dist.matrix), types, types),
2011-
matrix(as.double(pref.matrix), types, types),
2012-
as.logical(loops)
1997+
res <- asymmetric_preference_game_impl(
1998+
nodes = nodes,
1999+
out_types = types,
2000+
in_types = types,
2001+
type_dist_matrix = type.dist.matrix,
2002+
pref_matrix = pref.matrix,
2003+
loops = loops
20132004
)
20142005
V(res[[1]])$outtype <- res[[2]] + 1
20152006
V(res[[1]])$intype <- res[[3]] + 1

R/hrg.R

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -456,34 +456,12 @@ predict_edges <- function(
456456
num.samples = 10000,
457457
num.bins = 25
458458
) {
459-
# Argument checks
460-
ensure_igraph(graph)
461-
if (is.null(hrg)) {
462-
hrg <- list(
463-
left = c(),
464-
right = c(),
465-
prob = c(),
466-
edges = c(),
467-
vertices = c()
468-
)
469-
}
470-
hrg <- lapply(
471-
hrg[c("left", "right", "prob", "edges", "vertices")],
472-
as.numeric
473-
)
474-
start <- as.logical(start)
475-
num.samples <- as.numeric(num.samples)
476-
num.bins <- as.numeric(num.bins)
477-
478-
on.exit(.Call(R_igraph_finalizer))
479-
# Function call
480-
res <- .Call(
481-
R_igraph_hrg_predict,
482-
graph,
483-
hrg,
484-
start,
485-
num.samples,
486-
num.bins
459+
res <- hrg_predict_impl(
460+
graph = graph,
461+
hrg = hrg,
462+
start = start,
463+
num_samples = num.samples,
464+
num_bins = num.bins
487465
)
488466
res$edges <- matrix(res$edges, ncol = 2, byrow = TRUE)
489467
class(res$hrg) <- "igraphHRG"

0 commit comments

Comments
 (0)