Skip to content

Commit 8279b25

Browse files
Copilotkrlmlr
andauthored
feat: graphlet_basis() returns a list of vertices in the "cliques" component. Replace .Call(Rx_...) with _impl functions for autogenerated entrypoints (#2472)
Co-authored-by: Kirill Müller <kirill@cynkra.com>
1 parent c5bcecc commit 8279b25

24 files changed

+391
-1317
lines changed

R/aaa-auto.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ edges_impl <- function(
248248
graph,
249249
eids - 1
250250
)
251-
251+
if (igraph_opt("return.vs.es")) {
252+
res <- create_vs(graph, res)
253+
}
252254
res
253255
}
254256

@@ -2966,7 +2968,9 @@ topological_sorting_impl <- function(
29662968
graph,
29672969
mode
29682970
)
2969-
2971+
if (igraph_opt("return.vs.es")) {
2972+
res <- create_vs(graph, res)
2973+
}
29702974
res
29712975
}
29722976

@@ -6628,6 +6632,8 @@ write_graph_edgelist_impl <- function(
66286632
) {
66296633
# Argument checks
66306634
ensure_igraph(graph)
6635+
check_string(outstream)
6636+
66316637

66326638
on.exit(.Call(R_igraph_finalizer))
66336639
# Function call
@@ -6648,6 +6654,8 @@ write_graph_leda_impl <- function(
66486654
) {
66496655
# Argument checks
66506656
ensure_igraph(graph)
6657+
check_string(outstream)
6658+
66516659

66526660
on.exit(.Call(R_igraph_finalizer))
66536661
# Function call
@@ -6669,6 +6677,8 @@ write_graph_graphml_impl <- function(
66696677
) {
66706678
# Argument checks
66716679
ensure_igraph(graph)
6680+
check_string(outstream)
6681+
66726682
prefixattr <- as.logical(prefixattr)
66736683

66746684
on.exit(.Call(R_igraph_finalizer))
@@ -6689,6 +6699,8 @@ write_graph_pajek_impl <- function(
66896699
) {
66906700
# Argument checks
66916701
ensure_igraph(graph)
6702+
check_string(outstream)
6703+
66926704

66936705
on.exit(.Call(R_igraph_finalizer))
66946706
# Function call
@@ -6710,6 +6722,8 @@ write_graph_gml_impl <- function(
67106722
) {
67116723
# Argument checks
67126724
ensure_igraph(graph)
6725+
check_string(outstream)
6726+
67136727
options <- switch_igraph_arg(options, "default" = 0L, "encode_only_quot" = 1L)
67146728
id <- as.numeric(id)
67156729

@@ -6733,6 +6747,8 @@ write_graph_dot_impl <- function(
67336747
) {
67346748
# Argument checks
67356749
ensure_igraph(graph)
6750+
check_string(outstream)
6751+
67366752

67376753
on.exit(.Call(R_igraph_finalizer))
67386754
# Function call

R/cliques.R

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -548,33 +548,17 @@ ivs <- function(graph, min = NULL, max = NULL) {
548548
#' @rdname ivs
549549
#' @export
550550
largest_ivs <- function(graph) {
551-
ensure_igraph(graph)
552-
553-
on.exit(.Call(R_igraph_finalizer))
554-
res <- .Call(Rx_igraph_largest_independent_vertex_sets, graph)
555-
res <- lapply(res, `+`, 1)
556-
557-
if (igraph_opt("return.vs.es")) {
558-
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
559-
}
560-
561-
res
551+
largest_independent_vertex_sets_impl(
552+
graph = graph
553+
)
562554
}
563555

564556
#' @rdname ivs
565557
#' @export
566558
max_ivs <- function(graph) {
567-
ensure_igraph(graph)
568-
569-
on.exit(.Call(R_igraph_finalizer))
570-
res <- .Call(Rx_igraph_maximal_independent_vertex_sets, graph)
571-
res <- lapply(res, `+`, 1)
572-
573-
if (igraph_opt("return.vs.es")) {
574-
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
575-
}
576-
577-
res
559+
maximal_independent_vertex_sets_impl(
560+
graph = graph
561+
)
578562
}
579563

580564
#' Maximal independent vertex sets in the graph
@@ -595,10 +579,9 @@ maximal_ivs <- function(graph) {
595579
#' @rdname ivs
596580
#' @export
597581
ivs_size <- function(graph) {
598-
ensure_igraph(graph)
599-
600-
on.exit(.Call(R_igraph_finalizer))
601-
.Call(Rx_igraph_independence_number, graph)
582+
independence_number_impl(
583+
graph = graph
584+
)
602585
}
603586

604587
#' @rdname ivs

R/cocitation.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
#' bibcoupling(g)
5555
#'
5656
cocitation <- function(graph, v = V(graph)) {
57-
ensure_igraph(graph)
58-
59-
v <- as_igraph_vs(graph, v)
60-
on.exit(.Call(R_igraph_finalizer))
61-
res <- .Call(Rx_igraph_cocitation, graph, v - 1)
57+
res <- cocitation_impl(
58+
graph = graph,
59+
vids = v
60+
)
6261
if (igraph_opt("add.vertex.names") && is_named(graph)) {
62+
v <- as_igraph_vs(graph, v)
6363
rownames(res) <- vertex_attr(graph, "name", v)
6464
colnames(res) <- vertex_attr(graph, "name")
6565
}
@@ -69,12 +69,12 @@ cocitation <- function(graph, v = V(graph)) {
6969
#' @rdname cocitation
7070
#' @export
7171
bibcoupling <- function(graph, v = V(graph)) {
72-
ensure_igraph(graph)
73-
74-
v <- as_igraph_vs(graph, v)
75-
on.exit(.Call(R_igraph_finalizer))
76-
res <- .Call(Rx_igraph_bibcoupling, graph, v - 1)
72+
res <- bibcoupling_impl(
73+
graph = graph,
74+
vids = v
75+
)
7776
if (igraph_opt("add.vertex.names") && is_named(graph)) {
77+
v <- as_igraph_vs(graph, v)
7878
rownames(res) <- vertex_attr(graph, "name", v)
7979
colnames(res) <- vertex_attr(graph, "name")
8080
}

R/cohesive.blocks.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ cohesive_blocks <- function(graph, labels = TRUE) {
355355
# Argument checks
356356
ensure_igraph(graph)
357357

358-
on.exit(.Call(R_igraph_finalizer))
359-
# Function call
360-
res <- .Call(Rx_igraph_cohesive_blocks, graph)
358+
res <- cohesive_blocks_impl(
359+
graph = graph
360+
)
361361
class(res) <- "cohesiveBlocks"
362362
if (labels && "name" %in% vertex_attr_names(graph)) {
363363
res$labels <- V(graph)$name

R/flow.R

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,9 @@ min_cut <- function(
411411

412412
if (is.null(target) && is.null(source)) {
413413
if (value.only) {
414-
res <- .Call(Rx_igraph_mincut_value, graph, capacity)
414+
res <- mincut_value_impl(graph = graph, capacity = capacity)
415415
} else {
416-
res <- .Call(Rx_igraph_mincut, graph, capacity)
417-
res$cut <- res$cut + 1
418-
res$partition1 <- res$partition1 + 1
419-
res$partition2 <- res$partition2 + 1
420-
421-
if (igraph_opt("return.vs.es")) {
422-
res$cut <- create_es(graph, res$cut)
423-
res$partition1 <- create_vs(graph, res$partition1)
424-
res$partition2 <- create_vs(graph, res$partition2)
425-
}
416+
res <- mincut_impl(graph = graph, capacity = capacity)
426417
}
427418
} else {
428419
if (value.only) {
@@ -533,8 +524,7 @@ vertex_connectivity <- function(
533524
ensure_igraph(graph)
534525

535526
if (is.null(source) && is.null(target)) {
536-
on.exit(.Call(R_igraph_finalizer))
537-
.Call(Rx_igraph_vertex_connectivity, graph, as.logical(checks))
527+
vertex_connectivity_impl(graph = graph, checks = checks)
538528
} else if (!is.null(source) && !is.null(target)) {
539529
on.exit(.Call(R_igraph_finalizer))
540530
.Call(
@@ -639,8 +629,7 @@ edge_connectivity <- function(
639629
ensure_igraph(graph)
640630

641631
if (is.null(source) && is.null(target)) {
642-
on.exit(.Call(R_igraph_finalizer))
643-
.Call(Rx_igraph_edge_connectivity, graph, as.logical(checks))
632+
edge_connectivity_impl(graph = graph, checks = checks)
644633
} else if (!is.null(source) && !is.null(target)) {
645634
on.exit(.Call(R_igraph_finalizer))
646635
.Call(
@@ -693,20 +682,20 @@ vertex_disjoint_paths <- function(graph, source = NULL, target = NULL) {
693682
#' @rdname edge_connectivity
694683
#' @export
695684
adhesion <- function(graph, checks = TRUE) {
696-
ensure_igraph(graph)
697-
698-
on.exit(.Call(R_igraph_finalizer))
699-
.Call(Rx_igraph_adhesion, graph, as.logical(checks))
685+
adhesion_impl(
686+
graph = graph,
687+
checks = checks
688+
)
700689
}
701690

702691
#' @rdname vertex_connectivity
703692
#' @method cohesion igraph
704693
#' @export
705694
cohesion.igraph <- function(x, checks = TRUE, ...) {
706-
ensure_igraph(x)
707-
708-
on.exit(.Call(R_igraph_finalizer))
709-
.Call(Rx_igraph_cohesion, x, as.logical(checks))
695+
cohesion_impl(
696+
graph = x,
697+
checks = checks
698+
)
710699
}
711700

712701
#' List all (s,t)-cuts of a graph

0 commit comments

Comments
 (0)