From 14d58de20c7e316e8b0a80367f0c3ef54c3071d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 1 Sep 2025 15:08:54 +0200 Subject: [PATCH 01/14] chore: autogenerate `igraph_incident()` --- R/aaa-auto.R | 18 ++++++++++++++++++ R/interface.R | 4 ++-- src/rinterface.c | 31 +++++++++++++++++++++++++++++++ tools/stimulus/functions-R.yaml | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 88c40309ef..b86a1b44dc 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -81,6 +81,24 @@ get_all_eids_between_impl <- function(graph, from, to, directed=TRUE) { res } +incident_impl <- function(graph, vid, mode=c("all", "out", "in", "total")) { + # Argument checks + ensure_igraph(graph) + vid <- as_igraph_vs(graph, vid) + if (length(vid) == 0) { + stop("No vertex was specified") + } + mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L) + + on.exit( .Call(R_igraph_finalizer) ) + # Function call + res <- .Call(R_igraph_incident, graph, vid-1, mode) + if (igraph_opt("return.vs.es")) { + res <- create_es(, res) + } + res +} + wheel_impl <- function(n, mode=c("out", "in", "undirected", "mutual"), center=0) { # Argument checks n <- as.numeric(n) diff --git a/R/interface.R b/R/interface.R index e5317fd54e..c7e811b5d2 100644 --- a/R/interface.R +++ b/R/interface.R @@ -397,7 +397,7 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { stop("No vertex was specified") } on.exit(.Call(R_igraph_finalizer)) - res <- .Call(R_igraph_incident, graph, v - 1, as.numeric(mode)) + 1L + res <- incident_impl(graph, vid = v - 1, mode = mode) + 1L if (igraph_opt("return.vs.es")) { res <- create_es(graph, res) @@ -692,7 +692,7 @@ incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) { on.exit(.Call(R_igraph_finalizer)) - res <- .Call(R_igraph_incident_edges, graph, vv, mode) + res <- incident_impl(graph, vid = vv, mode = mode) res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { diff --git a/src/rinterface.c b/src/rinterface.c index 046b758be1..000dccd3d0 100644 --- a/src/rinterface.c +++ b/src/rinterface.c @@ -222,6 +222,37 @@ SEXP R_igraph_get_all_eids_between(SEXP graph, SEXP from, SEXP to, SEXP directed return(r_result); } +/*-------------------------------------------/ +/ igraph_incident / +/-------------------------------------------*/ +SEXP R_igraph_incident(SEXP graph, SEXP vid, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_eids; + igraph_integer_t c_vid; + igraph_neimode_t c_mode; + SEXP eids; + + SEXP r_result; + /* Convert input */ + R_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_eids, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_eids); + c_vid = (igraph_integer_t) REAL(vid)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_incident(&c_graph, &c_eids, c_vid, c_mode)); + + /* Convert output */ + PROTECT(eids=R_igraph_vector_int_to_SEXPp1(&c_eids)); + igraph_vector_int_destroy(&c_eids); + IGRAPH_FINALLY_CLEAN(1); + r_result = eids; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_adjacency / /-------------------------------------------*/ diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index b7a2c84f43..b4849a74c8 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -55,7 +55,7 @@ igraph_get_all_eids_between: DEPS: from ON graph, to ON graph, eids ON graph igraph_incident: - IGNORE: RR, RC + DEPS: vid ON graph igraph_is_same_graph: IGNORE: RR, RC, RInit From dd117439129ed04ed427c32879a911fc99c7e384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 10:29:26 +0200 Subject: [PATCH 02/14] Update R/interface.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Szabolcs Horvát --- R/interface.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/interface.R b/R/interface.R index c7e811b5d2..6d5ba75fbd 100644 --- a/R/interface.R +++ b/R/interface.R @@ -397,7 +397,7 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { stop("No vertex was specified") } on.exit(.Call(R_igraph_finalizer)) - res <- incident_impl(graph, vid = v - 1, mode = mode) + 1L + res <- incident_impl(graph, vid = v, mode = mode) if (igraph_opt("return.vs.es")) { res <- create_es(graph, res) From f790e9be49869dcd0fa51a303a5c7ca4ff82c166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 10:38:33 +0200 Subject: [PATCH 03/14] rm fixes --- R/interface.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/R/interface.R b/R/interface.R index 6d5ba75fbd..92f54b8bae 100644 --- a/R/interface.R +++ b/R/interface.R @@ -396,7 +396,7 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { if (length(v) == 0) { stop("No vertex was specified") } - on.exit(.Call(R_igraph_finalizer)) + res <- incident_impl(graph, vid = v, mode = mode) if (igraph_opt("return.vs.es")) { @@ -687,20 +687,19 @@ adjacent_vertices <- function(graph, v, mode = c("out", "in", "all", "total")) { incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) { ensure_igraph(graph) - vv <- as_igraph_vs(graph, v) - 1 + vv <- as_igraph_vs(graph, v) mode <- switch(match.arg(mode), "out" = 1, "in" = 2, "all" = 3, "total" = 3) on.exit(.Call(R_igraph_finalizer)) res <- incident_impl(graph, vid = vv, mode = mode) - res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { res <- lapply(res, unsafe_create_es, graph = graph, es = E(graph)) } if (is_named(graph)) { - names(res) <- V(graph)$name[vv + 1] + names(res) <- V(graph)$name[vv] } res From 5653e131882e8ab12946106c08341ad45db858b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 11:14:38 +0200 Subject: [PATCH 04/14] fix: rm extra implementation --- src/rinterface_extra.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 461d2db073..64abe1d7b3 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -8317,48 +8317,6 @@ SEXP R_igraph_adjacent_vertices(SEXP pgraph, SEXP pv, SEXP pmode) { return result; } -SEXP R_igraph_incident_edges(SEXP pgraph, SEXP pe, SEXP pmode) { - - igraph_t graph; - igraph_vs_t vs; - igraph_vector_int_t vs_data; - igraph_vit_t vit; - igraph_neimode_t mode=(igraph_neimode_t) Rf_asInteger(pmode); - SEXP result; - size_t i, n; - igraph_lazy_inclist_t adjlist; - - R_SEXP_to_igraph(pgraph, &graph); - R_SEXP_to_igraph_vs(pe, &graph, &vs, &vs_data); - IGRAPH_FINALLY(igraph_vs_destroy, &vs); - IGRAPH_FINALLY_PV(igraph_vector_int_destroy, &vs_data); - - igraph_vit_create(&graph, vs, &vit); - IGRAPH_FINALLY(igraph_vit_destroy, &vit); - n = IGRAPH_VIT_SIZE(vit); - - igraph_lazy_inclist_init(&graph, &adjlist, mode, IGRAPH_LOOPS_TWICE); - IGRAPH_FINALLY(igraph_lazy_inclist_destroy, &adjlist); - - PROTECT(result = NEW_LIST(n)); - for (IGRAPH_VIT_RESET(vit), i=0; - !IGRAPH_VIT_END(vit); - IGRAPH_VIT_NEXT(vit), i++) { - igraph_integer_t eid = IGRAPH_VIT_GET(vit); - igraph_vector_int_t *neis = igraph_lazy_inclist_get(&adjlist, eid); - SET_VECTOR_ELT(result, i, R_igraph_vector_int_to_SEXP(neis)); - } - - igraph_lazy_inclist_destroy(&adjlist); - igraph_vit_destroy(&vit); - igraph_vs_destroy(&vs); - igraph_vector_int_destroy(&vs_data); - IGRAPH_FINALLY_CLEAN(4); - - UNPROTECT(1); - return result; -} - SEXP R_igraph_power_law_fit_new(SEXP data, SEXP xmin, SEXP force_continuous, SEXP compute_pvalue, SEXP precision) { igraph_vector_t c_data; From 8c1d6b993c0c09b444042e10efb40b1f2dafdb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 11:21:25 +0200 Subject: [PATCH 05/14] rm extra impl --- src/rinterface_extra.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 64abe1d7b3..bfbf31cabd 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -3893,7 +3893,6 @@ SEXP R_igraph_neighbors(SEXP graph, SEXP pvid, SEXP pmode) { return result; } -SEXP R_igraph_incident(SEXP graph, SEXP pvid, SEXP pmode) { igraph_t g; igraph_vector_int_t neis; From 5396b2ca9d9da1ef530c33489c5e71a85a285e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Thu, 4 Sep 2025 10:14:05 +0200 Subject: [PATCH 06/14] fix --- src/rinterface_extra.c | 108 ++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 38 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index bfbf31cabd..beba2b889e 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -3367,11 +3367,11 @@ void R_igraph_SEXP_to_matrixlist(SEXP matrixlist, igraph_matrix_list_t *list) { } igraph_error_t R_igraph_SEXP_to_strvector(SEXP rval, igraph_strvector_t *sv) { - igraph_integer_t length = Rf_xlength(rval); + const igraph_integer_t length = Rf_xlength(rval); sv->stor_begin=(char**) R_alloc((size_t) length, sizeof(char*)); sv->stor_end=sv->stor_begin+length; sv->end=sv->stor_end; - for (igraph_integer_t i=0; istor_begin[i]=(char*) CHAR(STRING_ELT(rval, i)); } @@ -3379,8 +3379,9 @@ igraph_error_t R_igraph_SEXP_to_strvector(SEXP rval, igraph_strvector_t *sv) { } igraph_error_t R_igraph_SEXP_to_strvector_copy(SEXP rval, igraph_strvector_t *sv) { - IGRAPH_STRVECTOR_INIT_FINALLY(sv, Rf_xlength(rval)); - for (igraph_integer_t i=0; i Date: Mon, 1 Sep 2025 15:08:54 +0200 Subject: [PATCH 07/14] chore: autogenerate `igraph_incident()` --- R/aaa-auto.R | 18 ++++++++++++++++++ R/interface.R | 4 ++-- src/rinterface.c | 31 +++++++++++++++++++++++++++++++ tools/stimulus/functions-R.yaml | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 88c40309ef..b86a1b44dc 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -81,6 +81,24 @@ get_all_eids_between_impl <- function(graph, from, to, directed=TRUE) { res } +incident_impl <- function(graph, vid, mode=c("all", "out", "in", "total")) { + # Argument checks + ensure_igraph(graph) + vid <- as_igraph_vs(graph, vid) + if (length(vid) == 0) { + stop("No vertex was specified") + } + mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L) + + on.exit( .Call(R_igraph_finalizer) ) + # Function call + res <- .Call(R_igraph_incident, graph, vid-1, mode) + if (igraph_opt("return.vs.es")) { + res <- create_es(, res) + } + res +} + wheel_impl <- function(n, mode=c("out", "in", "undirected", "mutual"), center=0) { # Argument checks n <- as.numeric(n) diff --git a/R/interface.R b/R/interface.R index e5317fd54e..c7e811b5d2 100644 --- a/R/interface.R +++ b/R/interface.R @@ -397,7 +397,7 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { stop("No vertex was specified") } on.exit(.Call(R_igraph_finalizer)) - res <- .Call(R_igraph_incident, graph, v - 1, as.numeric(mode)) + 1L + res <- incident_impl(graph, vid = v - 1, mode = mode) + 1L if (igraph_opt("return.vs.es")) { res <- create_es(graph, res) @@ -692,7 +692,7 @@ incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) { on.exit(.Call(R_igraph_finalizer)) - res <- .Call(R_igraph_incident_edges, graph, vv, mode) + res <- incident_impl(graph, vid = vv, mode = mode) res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { diff --git a/src/rinterface.c b/src/rinterface.c index 046b758be1..000dccd3d0 100644 --- a/src/rinterface.c +++ b/src/rinterface.c @@ -222,6 +222,37 @@ SEXP R_igraph_get_all_eids_between(SEXP graph, SEXP from, SEXP to, SEXP directed return(r_result); } +/*-------------------------------------------/ +/ igraph_incident / +/-------------------------------------------*/ +SEXP R_igraph_incident(SEXP graph, SEXP vid, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_eids; + igraph_integer_t c_vid; + igraph_neimode_t c_mode; + SEXP eids; + + SEXP r_result; + /* Convert input */ + R_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_eids, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_eids); + c_vid = (igraph_integer_t) REAL(vid)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_incident(&c_graph, &c_eids, c_vid, c_mode)); + + /* Convert output */ + PROTECT(eids=R_igraph_vector_int_to_SEXPp1(&c_eids)); + igraph_vector_int_destroy(&c_eids); + IGRAPH_FINALLY_CLEAN(1); + r_result = eids; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_adjacency / /-------------------------------------------*/ diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index b7a2c84f43..b4849a74c8 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -55,7 +55,7 @@ igraph_get_all_eids_between: DEPS: from ON graph, to ON graph, eids ON graph igraph_incident: - IGNORE: RR, RC + DEPS: vid ON graph igraph_is_same_graph: IGNORE: RR, RC, RInit From 56599accdd265fa629eb230787797e66215b64d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 10:29:26 +0200 Subject: [PATCH 08/14] Update R/interface.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Szabolcs Horvát --- R/interface.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/interface.R b/R/interface.R index c7e811b5d2..6d5ba75fbd 100644 --- a/R/interface.R +++ b/R/interface.R @@ -397,7 +397,7 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { stop("No vertex was specified") } on.exit(.Call(R_igraph_finalizer)) - res <- incident_impl(graph, vid = v - 1, mode = mode) + 1L + res <- incident_impl(graph, vid = v, mode = mode) if (igraph_opt("return.vs.es")) { res <- create_es(graph, res) From 04a49819b242d9ba43cd20314d4912e55373c835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 10:38:33 +0200 Subject: [PATCH 09/14] rm fixes --- R/interface.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/R/interface.R b/R/interface.R index 6d5ba75fbd..92f54b8bae 100644 --- a/R/interface.R +++ b/R/interface.R @@ -396,7 +396,7 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { if (length(v) == 0) { stop("No vertex was specified") } - on.exit(.Call(R_igraph_finalizer)) + res <- incident_impl(graph, vid = v, mode = mode) if (igraph_opt("return.vs.es")) { @@ -687,20 +687,19 @@ adjacent_vertices <- function(graph, v, mode = c("out", "in", "all", "total")) { incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) { ensure_igraph(graph) - vv <- as_igraph_vs(graph, v) - 1 + vv <- as_igraph_vs(graph, v) mode <- switch(match.arg(mode), "out" = 1, "in" = 2, "all" = 3, "total" = 3) on.exit(.Call(R_igraph_finalizer)) res <- incident_impl(graph, vid = vv, mode = mode) - res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { res <- lapply(res, unsafe_create_es, graph = graph, es = E(graph)) } if (is_named(graph)) { - names(res) <- V(graph)$name[vv + 1] + names(res) <- V(graph)$name[vv] } res From 3a051d00f172ba0d2657ba6dfd6068fb295d1ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 11:14:38 +0200 Subject: [PATCH 10/14] fix: rm extra implementation --- src/rinterface_extra.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 2ce149bf7e..10418ea8ab 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -8327,48 +8327,6 @@ SEXP R_igraph_adjacent_vertices(SEXP pgraph, SEXP pv, SEXP pmode) { return result; } -SEXP R_igraph_incident_edges(SEXP pgraph, SEXP pe, SEXP pmode) { - - igraph_t graph; - igraph_vs_t vs; - igraph_vector_int_t vs_data; - igraph_vit_t vit; - igraph_neimode_t mode=(igraph_neimode_t) Rf_asInteger(pmode); - SEXP result; - size_t i, n; - igraph_lazy_inclist_t adjlist; - - R_SEXP_to_igraph(pgraph, &graph); - R_SEXP_to_igraph_vs(pe, &graph, &vs, &vs_data); - IGRAPH_FINALLY(igraph_vs_destroy, &vs); - IGRAPH_FINALLY_PV(igraph_vector_int_destroy, &vs_data); - - igraph_vit_create(&graph, vs, &vit); - IGRAPH_FINALLY(igraph_vit_destroy, &vit); - n = IGRAPH_VIT_SIZE(vit); - - igraph_lazy_inclist_init(&graph, &adjlist, mode, IGRAPH_LOOPS_TWICE); - IGRAPH_FINALLY(igraph_lazy_inclist_destroy, &adjlist); - - PROTECT(result = NEW_LIST(n)); - for (IGRAPH_VIT_RESET(vit), i=0; - !IGRAPH_VIT_END(vit); - IGRAPH_VIT_NEXT(vit), i++) { - igraph_integer_t eid = IGRAPH_VIT_GET(vit); - igraph_vector_int_t *neis = igraph_lazy_inclist_get(&adjlist, eid); - SET_VECTOR_ELT(result, i, R_igraph_vector_int_to_SEXP(neis)); - } - - igraph_lazy_inclist_destroy(&adjlist); - igraph_vit_destroy(&vit); - igraph_vs_destroy(&vs); - igraph_vector_int_destroy(&vs_data); - IGRAPH_FINALLY_CLEAN(4); - - UNPROTECT(1); - return result; -} - SEXP R_igraph_power_law_fit_new(SEXP data, SEXP xmin, SEXP force_continuous, SEXP compute_pvalue, SEXP precision) { igraph_vector_t c_data; From df89cc7b19eb8f328cbf9a5fabaa8fd5d5203815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 2 Sep 2025 11:21:25 +0200 Subject: [PATCH 11/14] rm extra impl --- src/rinterface_extra.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 10418ea8ab..49adb1c3f5 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -3894,7 +3894,6 @@ SEXP R_igraph_neighbors(SEXP graph, SEXP pvid, SEXP pmode) { return result; } -SEXP R_igraph_incident(SEXP graph, SEXP pvid, SEXP pmode) { igraph_t g; igraph_vector_int_t neis; From c14363ef90e800054a16e15c33ae7e4588bd790f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Thu, 4 Sep 2025 10:14:05 +0200 Subject: [PATCH 12/14] fix --- src/rinterface_extra.c | 64 ++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 49adb1c3f5..beba2b889e 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -3894,26 +3894,6 @@ SEXP R_igraph_neighbors(SEXP graph, SEXP pvid, SEXP pmode) { return result; } - - igraph_t g; - igraph_vector_int_t neis; - SEXP result; - igraph_real_t vid; - igraph_neimode_t mode; - - igraph_vector_int_init(&neis, 0); - vid=REAL(pvid)[0]; - mode = (igraph_neimode_t) Rf_asInteger(pmode); - R_SEXP_to_igraph(graph, &g); - IGRAPH_R_CHECK(igraph_incident(&g, &neis, (igraph_integer_t) vid, mode)); - - PROTECT(result=R_igraph_vector_int_to_SEXP(&neis)); - igraph_vector_int_destroy(&neis); - - UNPROTECT(1); - return result; -} - SEXP R_igraph_delete_edges(SEXP graph, SEXP edges) { igraph_es_t es; @@ -8326,6 +8306,48 @@ SEXP R_igraph_adjacent_vertices(SEXP pgraph, SEXP pv, SEXP pmode) { return result; } +SEXP R_igraph_incident_edges(SEXP pgraph, SEXP pe, SEXP pmode) { + + igraph_t graph; + igraph_vs_t vs; + igraph_vector_int_t vs_data; + igraph_vit_t vit; + igraph_neimode_t mode=(igraph_neimode_t) Rf_asInteger(pmode); + SEXP result; + size_t i, n; + igraph_lazy_inclist_t adjlist; + + R_SEXP_to_igraph(pgraph, &graph); + R_SEXP_to_igraph_vs(pe, &graph, &vs, &vs_data); + IGRAPH_FINALLY(igraph_vs_destroy, &vs); + IGRAPH_FINALLY_PV(igraph_vector_int_destroy, &vs_data); + + igraph_vit_create(&graph, vs, &vit); + IGRAPH_FINALLY(igraph_vit_destroy, &vit); + n = IGRAPH_VIT_SIZE(vit); + + igraph_lazy_inclist_init(&graph, &adjlist, mode, IGRAPH_LOOPS_TWICE); + IGRAPH_FINALLY(igraph_lazy_inclist_destroy, &adjlist); + + PROTECT(result = NEW_LIST(n)); + for (IGRAPH_VIT_RESET(vit), i=0; + !IGRAPH_VIT_END(vit); + IGRAPH_VIT_NEXT(vit), i++) { + igraph_integer_t eid = IGRAPH_VIT_GET(vit); + igraph_vector_int_t *neis = igraph_lazy_inclist_get(&adjlist, eid); + SET_VECTOR_ELT(result, i, R_igraph_vector_int_to_SEXP(neis)); + } + + igraph_lazy_inclist_destroy(&adjlist); + igraph_vit_destroy(&vit); + igraph_vs_destroy(&vs); + igraph_vector_int_destroy(&vs_data); + IGRAPH_FINALLY_CLEAN(4); + + UNPROTECT(1); + return result; +} + SEXP R_igraph_power_law_fit_new(SEXP data, SEXP xmin, SEXP force_continuous, SEXP compute_pvalue, SEXP precision) { igraph_vector_t c_data; @@ -8665,4 +8687,4 @@ SEXP R_igraph_add_env(SEXP graph) { SEXP R_igraph_get_graph_id(SEXP graph) { return Rf_findVar(Rf_install("myid"), R_igraph_graph_env(graph)); -} +} \ No newline at end of file From 3a5231f779c2ff9a1055329f613ebcbd0290eb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 8 Sep 2025 14:20:52 +0200 Subject: [PATCH 13/14] fixes --- R/interface.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/interface.R b/R/interface.R index 92f54b8bae..123b07ac4e 100644 --- a/R/interface.R +++ b/R/interface.R @@ -388,9 +388,8 @@ incident <- function(graph, v, mode = c("all", "out", "in", "total")) { ensure_igraph(graph) if (is_directed(graph)) { mode <- igraph.match.arg(mode) - mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3, "total" = 3) } else { - mode <- 1 + mode <- "out" } v <- as_igraph_vs(graph, v) if (length(v) == 0) { @@ -688,9 +687,6 @@ incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) { ensure_igraph(graph) vv <- as_igraph_vs(graph, v) - mode <- switch(match.arg(mode), "out" = 1, "in" = 2, "all" = 3, "total" = 3) - - on.exit(.Call(R_igraph_finalizer)) res <- incident_impl(graph, vid = vv, mode = mode) From aaccdcf69e8984f0be461c14f35b63a38e560344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 8 Sep 2025 14:29:15 +0200 Subject: [PATCH 14/14] yay --- R/aaa-auto.R | 2 +- tools/stimulus/functions-R.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index b86a1b44dc..4c8854f813 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -94,7 +94,7 @@ incident_impl <- function(graph, vid, mode=c("all", "out", "in", "total")) { # Function call res <- .Call(R_igraph_incident, graph, vid-1, mode) if (igraph_opt("return.vs.es")) { - res <- create_es(, res) + res <- create_es(graph, res) } res } diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index b4849a74c8..0c1a362c40 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -55,7 +55,7 @@ igraph_get_all_eids_between: DEPS: from ON graph, to ON graph, eids ON graph igraph_incident: - DEPS: vid ON graph + DEPS: vid ON graph, eids ON graph igraph_is_same_graph: IGNORE: RR, RC, RInit