From 804ec8999d44a62f8d63682cf177c60f13f9905a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Tue, 6 Feb 2024 09:30:48 +0000 Subject: [PATCH 1/2] refactor: reduce number of manual edits to autogenerated files --- R/aaa-auto.R | 31 ++++- src/cpp11.cpp | 4 + src/rinterface.c | 218 +++++++++----------------------- tools/stimulus/functions-R.yaml | 33 ++++- 4 files changed, 125 insertions(+), 161 deletions(-) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index e6c01f42d0..9fd7e695d5 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -215,6 +215,21 @@ realize_degree_sequence_impl <- function(out.deg, in.deg=NULL, allowed.edge.type res } +realize_bipartite_degree_sequence_impl <- function(degrees1, degrees2, allowed.edge.types=c("simple", "loops", "multi", "all"), method=c("smallest", "largest", "index")) { + # Argument checks + degrees1 <- as.numeric(degrees1) + degrees2 <- as.numeric(degrees2) + allowed.edge.types <- switch(igraph.match.arg(allowed.edge.types), + "simple"=0L, "loop"=1L, "loops"=1L, "multi"=6L, "multiple"=6L, "all"=7L) + method <- switch(igraph.match.arg(method), "smallest"=0L, "largest"=1L, "index"=2L) + + on.exit( .Call(R_igraph_finalizer) ) + # Function call + res <- .Call(R_igraph_realize_bipartite_degree_sequence, degrees1, degrees2, allowed.edge.types, method) + + res +} + circulant_impl <- function(n, shifts, directed=FALSE) { # Argument checks n <- as.numeric(n) @@ -2257,6 +2272,17 @@ bridges_impl <- function(graph) { res } +is_biconnected_impl <- function(graph) { + # Argument checks + ensure_igraph(graph) + + on.exit( .Call(R_igraph_finalizer) ) + # Function call + res <- .Call(R_igraph_is_biconnected, graph) + + res +} + cliques_impl <- function(graph, min=0, max=0) { # Argument checks ensure_igraph(graph) @@ -3229,9 +3255,6 @@ subisomorphic_vf2_impl <- function(graph1, graph2, vertex.color1=NULL, vertex.co res } -# get_subisomorphisms_vf2_callback_impl gives LTO warnings -# wrong number of arguments to R_igraph_get_subisomorphisms_vf2_callback() - count_subisomorphisms_vf2_impl <- function(graph1, graph2, vertex.color1, vertex.color2, edge.color1, edge.color2) { # Argument checks ensure_igraph(graph1) @@ -3816,7 +3839,6 @@ stochastic_imitation_impl <- function(graph, vid, algo, quantities, strategies, res } - vertex_path_from_edge_path_impl <- function(graph, start, edge.path, mode=c("out", "in", "all", "total")) { # Argument checks ensure_igraph(graph) @@ -3835,3 +3857,4 @@ vertex_path_from_edge_path_impl <- function(graph, start, edge.path, mode=c("out } res } + diff --git a/src/cpp11.cpp b/src/cpp11.cpp index f964e4fde3..69569d526b 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -247,6 +247,7 @@ extern SEXP R_igraph_induced_subgraph(void *, void *, void *); extern SEXP R_igraph_induced_subgraph_map(void *, void *, void *); extern SEXP R_igraph_intersection(void *, void *); extern SEXP R_igraph_is_acyclic(void *); +extern SEXP R_igraph_is_biconnected(void *); extern SEXP R_igraph_is_bipartite(void *); extern SEXP R_igraph_is_chordal(void *, void *, void *, void *, void *); extern SEXP R_igraph_is_connected(void *, void *); @@ -375,6 +376,7 @@ extern SEXP R_igraph_read_graph_graphml(void *, void *); extern SEXP R_igraph_read_graph_lgl(void *, void *, void *, void *); extern SEXP R_igraph_read_graph_ncol(void *, void *, void *, void *, void *); extern SEXP R_igraph_read_graph_pajek(void *); +extern SEXP R_igraph_realize_bipartite_degree_sequence(void *, void *, void *, void *); extern SEXP R_igraph_realize_degree_sequence(void *, void *, void *, void *); extern SEXP R_igraph_recent_degree_aging_game(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); extern SEXP R_igraph_reciprocity(void *, void *, void *); @@ -705,6 +707,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_induced_subgraph_map", (DL_FUNC) &R_igraph_induced_subgraph_map, 3}, {"R_igraph_intersection", (DL_FUNC) &R_igraph_intersection, 2}, {"R_igraph_is_acyclic", (DL_FUNC) &R_igraph_is_acyclic, 1}, + {"R_igraph_is_biconnected", (DL_FUNC) &R_igraph_is_biconnected, 1}, {"R_igraph_is_bipartite", (DL_FUNC) &R_igraph_is_bipartite, 1}, {"R_igraph_is_chordal", (DL_FUNC) &R_igraph_is_chordal, 5}, {"R_igraph_is_connected", (DL_FUNC) &R_igraph_is_connected, 2}, @@ -833,6 +836,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_read_graph_lgl", (DL_FUNC) &R_igraph_read_graph_lgl, 4}, {"R_igraph_read_graph_ncol", (DL_FUNC) &R_igraph_read_graph_ncol, 5}, {"R_igraph_read_graph_pajek", (DL_FUNC) &R_igraph_read_graph_pajek, 1}, + {"R_igraph_realize_bipartite_degree_sequence", (DL_FUNC) &R_igraph_realize_bipartite_degree_sequence, 4}, {"R_igraph_realize_degree_sequence", (DL_FUNC) &R_igraph_realize_degree_sequence, 4}, {"R_igraph_recent_degree_aging_game", (DL_FUNC) &R_igraph_recent_degree_aging_game, 10}, {"R_igraph_reciprocity", (DL_FUNC) &R_igraph_reciprocity, 3}, diff --git a/src/rinterface.c b/src/rinterface.c index 6a9ee73650..a1973d73a6 100644 --- a/src/rinterface.c +++ b/src/rinterface.c @@ -788,6 +788,44 @@ SEXP R_igraph_realize_degree_sequence(SEXP out_deg, SEXP in_deg, SEXP allowed_ed return(r_result); } +/*-------------------------------------------/ +/ igraph_realize_bipartite_degree_sequence / +/-------------------------------------------*/ +SEXP R_igraph_realize_bipartite_degree_sequence(SEXP degrees1, SEXP degrees2, SEXP allowed_edge_types, SEXP method) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_degrees1; + igraph_vector_int_t c_degrees2; + igraph_edge_type_sw_t c_allowed_edge_types; + igraph_realize_degseq_t c_method; + SEXP graph; + + SEXP r_result; + /* Convert input */ + R_SEXP_to_vector_int_copy(degrees1, &c_degrees1); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_degrees1); + R_SEXP_to_vector_int_copy(degrees2, &c_degrees2); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_degrees2); + c_allowed_edge_types = (igraph_edge_type_sw_t) Rf_asInteger(allowed_edge_types); + c_method = (igraph_realize_degseq_t) Rf_asInteger(method); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_realize_bipartite_degree_sequence(&c_graph, &c_degrees1, &c_degrees2, c_allowed_edge_types, c_method)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=R_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_degrees1); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_degrees2); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_circulant / /-------------------------------------------*/ @@ -6222,6 +6260,30 @@ SEXP R_igraph_bridges(SEXP graph) { return(r_result); } +/*-------------------------------------------/ +/ igraph_is_biconnected / +/-------------------------------------------*/ +SEXP R_igraph_is_biconnected(SEXP graph) { + /* Declarations */ + igraph_t c_graph; + igraph_bool_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + R_SEXP_to_igraph(graph, &c_graph); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_is_biconnected(&c_graph, &c_res)); + + /* Convert output */ + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_cliques / /-------------------------------------------*/ @@ -9853,93 +9915,6 @@ SEXP R_igraph_subisomorphic_vf2(SEXP graph1, SEXP graph2, SEXP vertex_color1, SE return(r_result); } -/*-------------------------------------------/ -/ igraph_get_subisomorphisms_vf2_callback / -/-------------------------------------------*/ -SEXP R_igraph_get_subisomorphisms_vf2_callback(SEXP graph1, SEXP graph2, SEXP vertex_color1, SEXP vertex_color2, SEXP edge_color1, SEXP edge_color2) { - /* Declarations */ - igraph_t c_graph1; - igraph_t c_graph2; - igraph_vector_int_t c_vertex_color1; - igraph_vector_int_t c_vertex_color2; - igraph_vector_int_t c_edge_color1; - igraph_vector_int_t c_edge_color2; - igraph_vector_int_t c_map12; - igraph_vector_int_t c_map21; - - - - - SEXP map12; - SEXP map21; - - SEXP r_result, r_names; - /* Convert input */ - R_SEXP_to_igraph(graph1, &c_graph1); - R_SEXP_to_igraph(graph2, &c_graph2); - if (!Rf_isNull(vertex_color1)) { - R_SEXP_to_vector_int_copy(vertex_color1, &c_vertex_color1); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_color1, 0)); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_color1); - if (!Rf_isNull(vertex_color2)) { - R_SEXP_to_vector_int_copy(vertex_color2, &c_vertex_color2); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_color2, 0)); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_color2); - if (!Rf_isNull(edge_color1)) { - R_SEXP_to_vector_int_copy(edge_color1, &c_edge_color1); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_color1, 0)); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_color1); - if (!Rf_isNull(edge_color2)) { - R_SEXP_to_vector_int_copy(edge_color2, &c_edge_color2); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_color2, 0)); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_color2); - if (0 != igraph_vector_int_init(&c_map12, 0)) { - igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_map12); - if (0 != igraph_vector_int_init(&c_map21, 0)) { - igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_map21); - /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_subisomorphisms_vf2_callback(&c_graph1, &c_graph2, (Rf_isNull(vertex_color1) ? 0 : (Rf_isNull(vertex_color1) ? 0 : &c_vertex_color1)), (Rf_isNull(vertex_color2) ? 0 : (Rf_isNull(vertex_color2) ? 0 : &c_vertex_color2)), (Rf_isNull(edge_color1) ? 0 : (Rf_isNull(edge_color1) ? 0 : &c_edge_color1)), (Rf_isNull(edge_color2) ? 0 : (Rf_isNull(edge_color2) ? 0 : &c_edge_color2)), &c_map12, &c_map21, 0, 0, 0, 0)); - - /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - igraph_vector_int_destroy(&c_vertex_color1); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vertex_color2); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_edge_color1); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_edge_color2); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(map12=R_igraph_vector_int_to_SEXPp1(&c_map12)); - igraph_vector_int_destroy(&c_map12); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(map21=R_igraph_vector_int_to_SEXPp1(&c_map21)); - igraph_vector_int_destroy(&c_map21); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, map12); - SET_VECTOR_ELT(r_result, 1, map21); - SET_STRING_ELT(r_names, 0, Rf_mkChar("map12")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("map21")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); - - UNPROTECT(1); - return(r_result); -} - /*-------------------------------------------/ / igraph_count_subisomorphisms_vf2 / /-------------------------------------------*/ @@ -10743,7 +10718,6 @@ SEXP R_igraph_dim_select(SEXP sv) { return(r_result); } - /*-------------------------------------------/ / igraph_solve_lsap / /-------------------------------------------*/ @@ -11392,28 +11366,6 @@ SEXP R_igraph_stochastic_imitation(SEXP graph, SEXP vid, SEXP algo, SEXP quantit return(r_result); } -/*-------------------------------------------/ -/ igraph_has_attribute_table / -/-------------------------------------------*/ -// FIXME: Change Stimulus to generate (void) instead of () -SEXP R_igraph_has_attribute_table(void) { - /* Declarations */ - igraph_bool_t c_result; - SEXP r_result; - /* Convert input */ - - /* Call igraph */ - c_result=igraph_has_attribute_table(); - - /* Convert output */ - - PROTECT(r_result=NEW_LOGICAL(1)); - LOGICAL(r_result)[0]=c_result; - - UNPROTECT(1); - return(r_result); -} - /*-------------------------------------------/ / igraph_expand_path_to_pairs / /-------------------------------------------*/ @@ -11499,49 +11451,3 @@ SEXP R_igraph_vertex_path_from_edge_path(SEXP graph, SEXP start, SEXP edge_path, UNPROTECT(1); return(r_result); } - -/*-------------------------------------------/ -/ igraph_version / -/-------------------------------------------*/ -// FIXME: Change Stimulus to generate (void) instead of () -SEXP R_igraph_version(void) { - /* Declarations */ - const char* c_version_string; - int c_major; - int c_minor; - int c_subminor; - SEXP version_string; - SEXP major; - SEXP minor; - SEXP subminor; - - SEXP r_result, r_names; - /* Convert input */ - - /* Call igraph */ - igraph_version(&c_version_string, &c_major, &c_minor, &c_subminor); - - /* Convert output */ - PROTECT(r_result=NEW_LIST(4)); - PROTECT(r_names=NEW_CHARACTER(4)); - PROTECT(version_string = Rf_mkCharLenCE(c_version_string, strlen(c_version_string), CE_UTF8)); - PROTECT(major=NEW_INTEGER(1)); - INTEGER(major)[0]=(int) c_major; - PROTECT(minor=NEW_INTEGER(1)); - INTEGER(minor)[0]=(int) c_minor; - PROTECT(subminor=NEW_INTEGER(1)); - INTEGER(subminor)[0]=(int) c_subminor; - SET_VECTOR_ELT(r_result, 0, version_string); - SET_VECTOR_ELT(r_result, 1, major); - SET_VECTOR_ELT(r_result, 2, minor); - SET_VECTOR_ELT(r_result, 3, subminor); - SET_STRING_ELT(r_names, 0, Rf_mkChar("version_string")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("major")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("minor")); - SET_STRING_ELT(r_names, 3, Rf_mkChar("subminor")); - SET_NAMES(r_result, r_names); - UNPROTECT(5); - - UNPROTECT(1); - return(r_result); -} diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index 5b33047654..ef9fe4a535 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -82,9 +82,13 @@ igraph_create: igraph_adjacency: IGNORE: RR +# TODO: temporarily disabled igraph_sparse_adjacency: + IGNORE: RR, RC +# TODO: temporarily disabled igraph_sparse_weighted_adjacency: + IGNORE: RR, RC igraph_weighted_adjacency: IGNORE: RR @@ -167,7 +171,9 @@ igraph_generalized_petersen: igraph_turan: +# TODO: temporarily disabled igraph_weighted_sparsemat: + IGNORE: RR, RC ####################################### # Constructors, games @@ -748,7 +754,9 @@ igraph_largest_cliques: igraph_maximal_cliques: IGNORE: RR, RC, RInit +# TODO: temporarily disabled igraph_maximal_cliques_subset: + IGNORE: RR, RC igraph_maximal_cliques_callback: IGNORE: RR, RC, RInit @@ -1012,7 +1020,9 @@ igraph_from_hrg_dendrogram: igraph_get_adjacency: IGNORE: RR, RC +# TODO: temporarily disabled igraph_get_adjacency_sparse: + IGNORE: RR igraph_get_edgelist: IGNORE: RR, RC @@ -1047,7 +1057,9 @@ igraph_read_graph_pajek: igraph_read_graph_graphml: IGNORE: RR, RC +# TODO: temporarily disabled igraph_read_graph_dimacs_flow: + IGNORE: RR, RC igraph_read_graph_graphdb: IGNORE: RR, RC @@ -1076,8 +1088,9 @@ igraph_write_graph_graphml: igraph_write_graph_pajek: IGNORE: RR, RC +# TODO: temporarily disabled igraph_write_graph_dimacs_flow: - IGNORE: RR + IGNORE: RR, RC PARAMS: |- INOUT GRAPH graph, OUTFILE outstream, VERTEX source=0, VERTEX target=0, VECTOR capacity @@ -1272,7 +1285,11 @@ igraph_subisomorphic: igraph_subisomorphic_vf2: +# TODO: temporarily disabled +# get_subisomorphisms_vf2_callback_impl gives LTO warnings +# wrong number of arguments to R_igraph_get_subisomorphisms_vf2_callback() igraph_get_subisomorphisms_vf2_callback: + IGNORE: RR, RC igraph_count_subisomorphisms_vf2: @@ -1360,13 +1377,21 @@ igraph_convex_hull: igraph_dim_select: +# Not needed in R igraph_almost_equals: + IGNORE: RR, RC +# Not needed in R igraph_cmp_epsilon: + IGNORE: RR, RC +# TODO: temporarily disabled igraph_eigen_matrix: + IGNORE: RR, RC +# TODO: temporarily disabled igraph_eigen_matrix_symmetric: + IGNORE: RR, RC igraph_solve_lsap: @@ -1455,17 +1480,22 @@ igraph_stochastic_imitation: igraph_convergence_degree: IGNORE: RR, RC, RInit +# Not needed in R igraph_has_attribute_table: + IGNORE: RR, RC ####################################### # Progress, status handling ####################################### igraph_progress: + IGNORE: RR, RC igraph_status: + IGNORE: RR, RC igraph_strerror: + IGNORE: RR, RC ####################################### # Other functions, documented, graph related @@ -1486,3 +1516,4 @@ igraph_vertex_path_from_edge_path: ####################################### igraph_version: + IGNORE: RR, RC From 32ef7b33712d5b86bbd0b46bf8caa00b6cecef9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Tue, 6 Feb 2024 09:48:49 +0000 Subject: [PATCH 2/2] fix: do not add vertex names to edge_betweenness_subset result as the result is associated with edges and not vertices. Also fix invalid dependency specification: no dependency on V(g). --- R/aaa-auto.R | 4 +--- tools/stimulus/functions-R.yaml | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 9fd7e695d5..5199d5679b 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -985,9 +985,7 @@ edge_betweenness_subset_impl <- function(graph, eids=E(graph), directed=TRUE, so on.exit( .Call(R_igraph_finalizer) ) # Function call res <- .Call(R_igraph_edge_betweenness_subset, graph, eids-1, directed, sources-1, targets-1, weights) -if (igraph_opt("add.vertex.names") && is_named(graph)) { - names(res) <- vertex_attr(graph, "name", V(graph)) - } + res } diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index ef9fe4a535..b03cfae964 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -416,8 +416,6 @@ igraph_edge_betweenness_cutoff: IGNORE: RR igraph_edge_betweenness_subset: - DEPS: |- - eids ON graph, weights ON graph V(graph), res ON graph V(graph), sources ON graph, targets ON graph igraph_harmonic_centrality: IGNORE: RR, RC, RInit