diff --git a/R/attributes.R b/R/attributes.R index d45ab8853f..83adc5b9b4 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -328,7 +328,7 @@ graph_attr <- function(graph, name) { check_string(name) - .Call(Rx_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_graph)[[ + .Call(Rx_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_graph)[[ # internal, no _impl name ]] } @@ -388,7 +388,7 @@ set_graph_attr <- function(graph, name, value) { ensure_igraph(graph) - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket3_set, graph, igraph_t_idx_attr, @@ -401,7 +401,7 @@ set_graph_attr <- function(graph, name, value) { #' @export graph.attributes <- function(graph) { ensure_igraph(graph) - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_copy, graph, igraph_t_idx_attr, @@ -417,7 +417,7 @@ graph.attributes <- function(graph) { value <- as.list(value) } - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -459,7 +459,7 @@ vertex_attr <- function(graph, name, index = V(graph)) { check_string(name) myattr <- - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -609,7 +609,7 @@ i_set_vertex_attr <- function( index <- as_igraph_vs(graph, index) } - vattrs <- .Call( + vattrs <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -643,7 +643,7 @@ i_set_vertex_attr <- function( } } - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -660,7 +660,7 @@ vertex.attributes <- function(graph, index = V(graph)) { index <- as_igraph_vs(graph, index) } - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_mybracket2_copy, graph, igraph_t_idx_attr, @@ -720,7 +720,7 @@ set_value_at <- function(value, idx, length_out) { ) } - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -761,7 +761,7 @@ edge_attr <- function(graph, name, index = E(graph)) { } } else { check_string(name) - myattr <- .Call( + myattr <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -865,7 +865,7 @@ i_set_edge_attr <- function( index <- as_igraph_es(graph, index) } - eattrs <- .Call( + eattrs <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -896,7 +896,7 @@ i_set_edge_attr <- function( } } - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -913,7 +913,7 @@ edge.attributes <- function(graph, index = E(graph)) { index <- as_igraph_es(graph, index) } - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_mybracket2_copy, graph, igraph_t_idx_attr, @@ -963,7 +963,7 @@ edge.attributes <- function(graph, index = E(graph)) { ) } - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -986,7 +986,7 @@ edge.attributes <- function(graph, index = E(graph)) { #' graph_attr_names(g) graph_attr_names <- function(graph) { ensure_igraph(graph) - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_mybracket2_names, graph, igraph_t_idx_attr, @@ -1015,7 +1015,7 @@ graph_attr_names <- function(graph) { vertex_attr_names <- function(graph) { ensure_igraph(graph) - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_mybracket2_names, graph, igraph_t_idx_attr, @@ -1043,7 +1043,7 @@ vertex_attr_names <- function(graph) { #' plot(g) edge_attr_names <- function(graph) { ensure_igraph(graph) - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_mybracket2_names, graph, igraph_t_idx_attr, @@ -1077,7 +1077,7 @@ delete_graph_attr <- function(graph, name) { cli::cli_abort("No graph attribute {.arg {name}} found.") } - gattr <- .Call( + gattr <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -1085,7 +1085,7 @@ delete_graph_attr <- function(graph, name) { ) gattr[[name]] <- NULL - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -1117,7 +1117,7 @@ delete_vertex_attr <- function(graph, name) { cli::cli_abort("No vertex attribute {.arg {name}} found.") } - vattr <- .Call( + vattr <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -1125,7 +1125,7 @@ delete_vertex_attr <- function(graph, name) { ) vattr[[name]] <- NULL - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, @@ -1157,7 +1157,7 @@ delete_edge_attr <- function(graph, name) { cli::cli_abort("No edge attribute {.arg {name}} found.") } - eattr <- .Call( + eattr <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -1165,7 +1165,7 @@ delete_edge_attr <- function(graph, name) { ) eattr[[name]] <- NULL - .Call( + .Call( # internal, no _impl Rx_igraph_mybracket2_set, graph, igraph_t_idx_attr, diff --git a/R/bipartite.R b/R/bipartite.R index c5cabb2387..1fc4a823c2 100644 --- a/R/bipartite.R +++ b/R/bipartite.R @@ -190,7 +190,7 @@ bipartite_projection <- function( on.exit(.Call(Rx_igraph_finalizer)) # Function call - res <- .Call( + res <- .Call( # bipartite_projection_impl lacks which/multiplicity parameters Rx_igraph_bipartite_projection, graph, types, diff --git a/R/centrality.R b/R/centrality.R index a017fa3590..b1d03391ec 100644 --- a/R/centrality.R +++ b/R/centrality.R @@ -992,7 +992,7 @@ arpack <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_arpack, func, extra, options, env, sym) + res <- .Call(Rx_igraph_arpack, func, extra, options, env, sym) # ARPACK, no _impl if (complex) { rew <- arpack.unpack.complex( @@ -1030,7 +1030,7 @@ arpack.unpack.complex <- function(vectors, values, nev) { on.exit(.Call(Rx_igraph_finalizer)) # Function call - res <- .Call(Rx_igraph_arpack_unpack_complex, vectors, values, nev) + res <- .Call(Rx_igraph_arpack_unpack_complex, vectors, values, nev) # ARPACK, no _impl res } diff --git a/R/cliques.R b/R/cliques.R index fe3a85f0c3..d2cb69f02b 100644 --- a/R/cliques.R +++ b/R/cliques.R @@ -325,7 +325,7 @@ max_cliques <- function( tmpfile <- FALSE } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # maximal_cliques_file_impl doesn't support subset Rx_igraph_maximal_cliques_file, graph, subset, @@ -350,7 +350,7 @@ max_cliques <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # maximal_cliques_impl doesn't support subset Rx_igraph_maximal_cliques, graph, subset_arg, @@ -403,7 +403,7 @@ count_max_cliques <- function(graph, min = NULL, max = NULL, subset = NULL) { on.exit(.Call(Rx_igraph_finalizer)) # Function call - res <- .Call(Rx_igraph_maximal_cliques_count, graph, subset, min, max) + res <- .Call(Rx_igraph_maximal_cliques_count, graph, subset, min, max) # _impl lacks subset res } @@ -568,30 +568,11 @@ weighted_clique_num <- function(graph, vertex.weights = NULL) { #' #' length(max_ivs(g)) ivs <- function(graph, min = NULL, max = NULL) { - ensure_igraph(graph) - - if (is.null(min)) { - min <- 0 - } - - if (is.null(max)) { - max <- 0 - } - - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( - Rx_igraph_independent_vertex_sets, - graph, - as.numeric(min), - as.numeric(max) + independent_vertex_sets_impl( + graph = graph, + min_size = min %||% 0, + max_size = max %||% 0 ) - res <- lapply(res, `+`, 1) - - if (igraph_opt("return.vs.es")) { - res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph)) - } - - res } #' @rdname ivs diff --git a/R/community.R b/R/community.R index 3fdc0df6ec..8307adbc70 100644 --- a/R/community.R +++ b/R/community.R @@ -1311,12 +1311,12 @@ show_trace <- function(communities) { ##################################################################### community.to.membership2 <- function(merges, vcount, steps) { - mode(merges) <- "numeric" - mode(vcount) <- "numeric" - mode(steps) <- "numeric" - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_community_to_membership2, merges - 1, vcount, steps) - res + 1 + res <- community_to_membership_impl( + merges = merges - 1, + nodes = vcount, + steps = steps + ) + res$membership + 1 } ##################################################################### @@ -1480,7 +1480,7 @@ cluster_spinglass <- function( on.exit(.Call(Rx_igraph_finalizer)) if (is.null(vertex) || length(vertex) == 0) { - res <- .Call( + res <- .Call( # community_spinglass_impl uses different parameter names Rx_igraph_spinglass_community, graph, weights, @@ -1502,7 +1502,7 @@ cluster_spinglass <- function( } class(res) <- "communities" } else { - res <- .Call( + res <- .Call( # community_spinglass_single_impl has different API Rx_igraph_spinglass_my_community, graph, weights, @@ -1858,7 +1858,7 @@ cluster_walktrap <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # community_walktrap_impl lacks output control parameters Rx_igraph_walktrap_community, graph, weights, @@ -1986,7 +1986,7 @@ cluster_edge_betweenness <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # community_edge_betweenness_impl lacks output control parameters Rx_igraph_community_edge_betweenness, graph, weights, @@ -2078,7 +2078,7 @@ cluster_fast_greedy <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # community_fastgreedy_impl lacks output control parameters Rx_igraph_community_fastgreedy, graph, as.logical(merges), @@ -2100,7 +2100,7 @@ cluster_fast_greedy <- function( igraph.i.levc.arp <- function(externalP, externalE) { f <- function(v) { v <- as.numeric(v) - .Call(R_igraph_levc_arpack_multiplier, externalP, externalE, v) + .Call(R_igraph_levc_arpack_multiplier, externalP, externalE, v) # internal ARPACK, no _impl } f } diff --git a/R/conversion.R b/R/conversion.R index 0d73ec08d5..d6cb0331fc 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -656,7 +656,7 @@ as_adj_list <- function( multiple <- if (multiple) 1 else 0 on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_get_adjlist, graph, mode, loops, multiple) + res <- .Call(Rx_igraph_get_adjlist, graph, mode, loops, multiple) # no _impl res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph)) @@ -686,7 +686,7 @@ as_adj_edge_list <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_get_adjedgelist, graph, mode, loops) + res <- .Call(Rx_igraph_get_adjedgelist, graph, mode, loops) # no _impl res <- lapply(res, function(.x) E(graph)[.x + 1]) if (is_named(graph)) { names(res) <- V(graph)$name @@ -1149,7 +1149,7 @@ as_data_frame <- function(x, what = c("edges", "vertices", "both")) { what <- igraph_match_arg(what) if (what %in% c("vertices", "both")) { - ver <- .Call( + ver <- .Call( # internal, no _impl Rx_igraph_mybracket2, x, igraph_t_idx_attr, @@ -1168,7 +1168,7 @@ as_data_frame <- function(x, what = c("edges", "vertices", "both")) { el <- as_edgelist(x) edg <- c( list(from = el[, 1], to = el[, 2]), - .Call(Rx_igraph_mybracket2, x, igraph_t_idx_attr, igraph_attr_idx_edge) + .Call(Rx_igraph_mybracket2, x, igraph_t_idx_attr, igraph_attr_idx_edge) # internal, no _impl ) class(edg) <- "data.frame" rownames(edg) <- seq_len(ecount(x)) @@ -1274,7 +1274,7 @@ graph_from_adj_list <- function( as_long_data_frame <- function(graph) { ensure_igraph(graph) - ver <- .Call( + ver <- .Call( # internal, no _impl Rx_igraph_mybracket2, graph, igraph_t_idx_attr, @@ -1292,7 +1292,7 @@ as_long_data_frame <- function(graph) { edg <- c( list(from = el[, 1]), list(to = el[, 2]), - .Call(Rx_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_edge) + .Call(Rx_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_edge) # internal, no _impl ) class(edg) <- "data.frame" rownames(edg) <- seq_len(ecount(graph)) diff --git a/R/decomposition.R b/R/decomposition.R index 8c8e92b570..ccbd5453a7 100644 --- a/R/decomposition.R +++ b/R/decomposition.R @@ -133,7 +133,7 @@ is_chordal <- function( fillin <- as.logical(fillin) newgraph <- as.logical(newgraph) on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # is_chordal_impl lacks fillin/newgraph parameters Rx_igraph_is_chordal, graph, alpha, diff --git a/R/fit.R b/R/fit.R index e0849b32a4..3a9f10f3d6 100644 --- a/R/fit.R +++ b/R/fit.R @@ -266,7 +266,7 @@ power.law.fit.new <- function( on.exit(.Call(Rx_igraph_finalizer)) # Function call - res <- .Call( + res <- .Call( # power_law_fit_impl lacks p.value/p.precision parameters Rx_igraph_power_law_fit_new, data, xmin, diff --git a/R/foreign.R b/R/foreign.R index 57a927759c..bfe57d9afc 100644 --- a/R/foreign.R +++ b/R/foreign.R @@ -524,12 +524,10 @@ write_graph <- function( ################################################################ read.graph.edgelist <- function(file, n = 0, directed = TRUE) { - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_read_graph_edgelist, - file, - as.numeric(n), - as.logical(directed) + read_graph_edgelist_impl( + instream = file, + n = n, + directed = directed ) } @@ -558,7 +556,7 @@ read.graph.ncol <- function( "auto" = 2L ) on.exit(.Call(Rx_igraph_finalizer)) - .Call( + .Call( # read_graph_ncol_impl has bug with predefnames Rx_igraph_read_graph_ncol, file, as.character(predef), @@ -584,7 +582,7 @@ write.graph.ncol <- function( } on.exit(.Call(Rx_igraph_finalizer)) - .Call( + .Call( # write_graph_ncol_impl can't handle NULL names/weights Rx_igraph_write_graph_ncol, graph, file, @@ -599,19 +597,12 @@ read.graph.lgl <- function( weights = c("auto", "yes", "no"), directed = FALSE ) { - weights <- switch( - igraph_match_arg(weights), - "no" = 0L, - "yes" = 1L, - "auto" = 2L - ) - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_read_graph_lgl, - file, - as.logical(names), - weights, - as.logical(directed) + weights <- igraph_match_arg(weights) + read_graph_lgl_impl( + instream = file, + names = names, + weights = weights, + directed = directed ) } @@ -632,7 +623,7 @@ write.graph.lgl <- function( } on.exit(.Call(Rx_igraph_finalizer)) - .Call( + .Call( # write_graph_lgl_impl can't handle NULL names/weights Rx_igraph_write_graph_lgl, graph, file, @@ -662,7 +653,12 @@ write.graph.pajek <- function(graph, file) { } read.graph.dimacs <- function(file, directed = TRUE) { - res <- .Call(Rx_igraph_read_graph_dimacs, file, as.logical(directed)) + on.exit(.Call(Rx_igraph_finalizer)) + res <- .Call( # read_graph_dimacs_flow_impl returns different structure + Rx_igraph_read_graph_dimacs, + file, + as.logical(directed) + ) if (res[[1]][1] == "max") { graph <- res[[2]] graph <- set_graph_attr(graph, "problem", res[[1]]) @@ -695,14 +691,12 @@ write.graph.dimacs <- function( capacity <- E(graph)$capacity } - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_write_graph_dimacs, - graph, - file, - as.numeric(source), - as.numeric(target), - as.numeric(capacity) + write_graph_dimacs_flow_impl( + graph = graph, + outstream = file, + source = source, + target = target, + capacity = capacity ) } diff --git a/R/games.R b/R/games.R index dd72d790b0..e0289a3118 100644 --- a/R/games.R +++ b/R/games.R @@ -1933,7 +1933,7 @@ traits <- function( #' sample_grg <- function(nodes, radius, torus = FALSE, coords = FALSE) { on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # grg_game_impl lacks torus/coords parameters Rx_igraph_grg_game, as.double(nodes), as.double(radius), diff --git a/R/interface.R b/R/interface.R index f1f1f3b0f5..555e746b62 100644 --- a/R/interface.R +++ b/R/interface.R @@ -150,11 +150,9 @@ add_edges <- function(graph, edges, ..., attr = list()) { } edges.orig <- ecount(graph) - on.exit(.Call(Rx_igraph_finalizer)) - graph <- .Call( - Rx_igraph_add_edges_manual, - graph, - as_igraph_vs(graph, edges) - 1 + graph <- add_edges_impl( + graph = graph, + edges = edges ) edges.new <- ecount(graph) @@ -639,7 +637,12 @@ adjacent_vertices <- function(graph, v, mode = c("out", "in", "all", "total")) { on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_adjacent_vertices, graph, vv, mode) + res <- .Call( # neighbors_impl takes single vertex + Rx_igraph_adjacent_vertices, + graph, + vv, + mode + ) res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { @@ -676,7 +679,12 @@ incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) { on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_incident_edges, graph, vv, mode) + res <- .Call( # incident_impl takes single vertex + Rx_igraph_incident_edges, + graph, + vv, + mode + ) res <- lapply(res, `+`, 1) if (igraph_opt("return.vs.es")) { diff --git a/R/iterators.R b/R/iterators.R index cfde92bebd..626424377f 100644 --- a/R/iterators.R +++ b/R/iterators.R @@ -30,7 +30,7 @@ update_es_ref <- update_vs_ref <- function(graph) { get_es_ref <- get_vs_ref <- function(graph) { if (is_igraph(graph) && !warn_version(graph)) { - .Call(Rx_igraph_copy_env, graph) + .Call(Rx_igraph_copy_env, graph) # internal, no _impl } else { NULL } @@ -84,7 +84,13 @@ get_es_graph_id <- get_vs_graph_id <- function(seq) { #' @export identical_graphs <- function(g1, g2, attrs = TRUE) { stopifnot(is_igraph(g1), is_igraph(g2)) - .Call(Rx_igraph_identical_graphs, g1, g2, as.logical(attrs)) + on.exit(.Call(Rx_igraph_finalizer)) + .Call( # is_same_graph_impl lacks attrs parameter + Rx_igraph_identical_graphs, + g1, + g2, + as.logical(attrs) + ) } add_vses_graph_ref <- function(vses, graph) { @@ -362,7 +368,7 @@ E <- function(graph, P = NULL, path = NULL, directed = TRUE) { res <- set_complete_iterator(res) } else if (!is.null(P)) { on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_es_pairs, graph, as_igraph_vs(graph, P) - 1, @@ -371,7 +377,7 @@ E <- function(graph, P = NULL, path = NULL, directed = TRUE) { 1 } else { on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # internal, no _impl Rx_igraph_es_path, graph, as_igraph_vs(graph, path) - 1, @@ -590,7 +596,7 @@ simple_vs_index <- function(x, i, na_ok = FALSE) { v <- which(v) } on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_vs_nei, graph, x, @@ -621,7 +627,7 @@ simple_vs_index <- function(x, i, na_ok = FALSE) { e <- which(e) } on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_vs_adj, graph, x, @@ -642,7 +648,7 @@ simple_vs_index <- function(x, i, na_ok = FALSE) { e <- which(e) } on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_vs_adj, graph, x, @@ -660,7 +666,7 @@ simple_vs_index <- function(x, i, na_ok = FALSE) { e <- which(e) } on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_vs_adj, graph, x, @@ -983,7 +989,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { .inc <- function(v) { ## TRUE iff the edge is incident to at least one vertex in v on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_es_adj, graph, x, @@ -1001,7 +1007,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { .from <- function(v) { ## TRUE iff the edge originates from at least one vertex in v on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_es_adj, graph, x, @@ -1016,7 +1022,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { .to <- function(v) { ## TRUE iff the edge points to at least one vertex in v on.exit(.Call(Rx_igraph_finalizer)) - tmp <- .Call( + tmp <- .Call( # internal, no _impl Rx_igraph_es_adj, graph, x, @@ -1057,12 +1063,14 @@ simple_es_index <- function(x, i, na_ok = FALSE) { )) # Data objects (visible by default) + from_copy <- .Call(Rx_igraph_copy_from, graph) # internal, no _impl + to_copy <- .Call(Rx_igraph_copy_to, graph) # internal, no _impl bottom <- rlang::new_environment( parent = top, c( attrs, - .igraph.from = list(.Call(Rx_igraph_copy_from, graph)[as.numeric(x)]), - .igraph.to = list(.Call(Rx_igraph_copy_to, graph)[as.numeric(x)]), + .igraph.from = list(from_copy[as.numeric(x)]), + .igraph.to = list(to_copy[as.numeric(x)]), .igraph.graph = list(graph), .env = env, .data = list(attrs) diff --git a/R/layout.R b/R/layout.R index 1f14bbe0fb..5be6ba8888 100644 --- a/R/layout.R +++ b/R/layout.R @@ -848,24 +848,24 @@ layout_as_tree <- function( root <- as_igraph_vs(graph, root) - 1 circular <- as.logical(circular) rootlevel <- as.double(rootlevel) - mode <- switch( - igraph_match_arg(mode), - "out" = 1, - "in" = 2, - "all" = 3, - "total" = 3 - ) + mode <- igraph_match_arg(mode) flip.y <- as.logical(flip.y) - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( - Rx_igraph_layout_reingold_tilford, - graph, - root, - mode, - rootlevel, - circular - ) + if (circular) { + res <- layout_reingold_tilford_circular_impl( + graph = graph, + mode = mode, + roots = root, + rootlevel = rootlevel + ) + } else { + res <- layout_reingold_tilford_impl( + graph = graph, + mode = mode, + roots = root, + rootlevel = rootlevel + ) + } if (flip.y && vcount(graph) > 0) { res[, 2] <- max(res[, 2]) - res[, 2] } @@ -1517,8 +1517,15 @@ layout_with_fr <- function( ) { # Argument checks ensure_igraph(graph) - coords[] <- as.numeric(coords) dim <- igraph_match_arg(dim) + use_seed <- !is.null(coords) + if (is.null(coords)) { + # Initialize coords with zeros - will be ignored if use_seed=FALSE + n <- vcount(graph) + dim_n <- if (dim == "2") 2 else 3 + coords <- matrix(0, n, dim_n) + } + coords[] <- as.numeric(coords) if (!missing(niter) && !missing(maxiter)) { cli::cli_abort(c( "{.arg niter} and {.arg maxiter} must not be specified at the same time.", @@ -1532,16 +1539,9 @@ layout_with_fr <- function( start.temp <- as.numeric(start.temp) grid <- igraph_match_arg(grid) - grid <- switch(grid, "grid" = 0L, "nogrid" = 1L, "auto" = 2L) - if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { - weights <- E(graph)$weight - } - if (!is.null(weights) && any(!is.na(weights))) { - weights <- as.numeric(weights) - } else { - weights <- NULL - } + # Let _impl handle default weights from edge attribute + # Pass weights as-is (including NA to signal "no weights") if (!is.null(minx)) { minx <- as.numeric(minx) } @@ -1573,35 +1573,34 @@ layout_with_fr <- function( lifecycle::deprecate_stop("0.8.0", "layout_with_fr(repulserad = )") } - on.exit(.Call(Rx_igraph_finalizer)) if (dim == 2) { - res <- .Call( - Rx_igraph_layout_fruchterman_reingold, - graph, - coords, - niter, - start.temp, - weights, - minx, - maxx, - miny, - maxy, - grid + res <- layout_fruchterman_reingold_impl( + graph = graph, + coords = coords, + use_seed = use_seed, + niter = niter, + start_temp = start.temp, + grid = grid, + weights = weights, + minx = minx, + maxx = maxx, + miny = miny, + maxy = maxy ) } else { - res <- .Call( - Rx_igraph_layout_fruchterman_reingold_3d, - graph, - coords, - niter, - start.temp, - weights, - minx, - maxx, - miny, - maxy, - minz, - maxz + res <- layout_fruchterman_reingold_3d_impl( + graph = graph, + coords = coords, + use_seed = use_seed, + niter = niter, + start_temp = start.temp, + weights = weights, + minx = minx, + maxx = maxx, + miny = miny, + maxy = maxy, + minz = minz, + maxz = maxz ) } res @@ -1758,6 +1757,11 @@ layout_with_graphopt <- function( max.sa.movement = 5 ) { ensure_igraph(graph) + use_seed <- !is.null(start) + if (is.null(start)) { + # Initialize with zeros - will be ignored if use_seed=FALSE + start <- matrix(0, vcount(graph), 2) + } start[] <- as.numeric(start) niter <- as.double(niter) charge <- as.double(charge) @@ -1766,17 +1770,16 @@ layout_with_graphopt <- function( spring.constant <- as.double(spring.constant) max.sa.movement <- as.double(max.sa.movement) - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_layout_graphopt, - graph, - niter, - charge, - mass, - spring.length, - spring.constant, - max.sa.movement, - start + layout_graphopt_impl( + graph = graph, + res = start, + niter = niter, + node_charge = charge, + node_mass = mass, + spring_length = spring.length, + spring_constant = spring.constant, + max_sa_movement = max.sa.movement, + use_seed = use_seed ) } @@ -1881,8 +1884,15 @@ layout_with_kk <- function( } ensure_igraph(graph) - coords[] <- as.numeric(coords) dim <- igraph_match_arg(dim) + use_seed <- !is.null(coords) + if (is.null(coords)) { + # Initialize coords with zeros - will be ignored if use_seed=FALSE + n <- vcount(graph) + dim_n <- if (dim == "2") 2 else 3 + coords <- matrix(0, n, dim_n) + } + coords[] <- as.numeric(coords) maxiter <- as.numeric(maxiter) epsilon <- as.numeric(epsilon) @@ -1927,37 +1937,36 @@ layout_with_kk <- function( lifecycle::deprecate_stop("0.8.0", "layout_with_kk(coolexp = )") } - on.exit(.Call(Rx_igraph_finalizer)) # Function call if (dim == 2) { - res <- .Call( - Rx_igraph_layout_kamada_kawai, - graph, - coords, - maxiter, - epsilon, - kkconst, - weights, - minx, - maxx, - miny, - maxy + res <- layout_kamada_kawai_impl( + graph = graph, + coords = coords, + use_seed = use_seed, + maxiter = maxiter, + epsilon = epsilon, + kkconst = kkconst, + weights = weights, + minx = minx, + maxx = maxx, + miny = miny, + maxy = maxy ) } else { - res <- .Call( - Rx_igraph_layout_kamada_kawai_3d, - graph, - coords, - maxiter, - epsilon, - kkconst, - weights, - minx, - maxx, - miny, - maxy, - minz, - maxz + res <- layout_kamada_kawai_3d_impl( + graph = graph, + coords = coords, + use_seed = use_seed, + maxiter = maxiter, + epsilon = epsilon, + kkconst = kkconst, + weights = weights, + minx = minx, + maxx = maxx, + miny = miny, + maxy = maxy, + minz = minz, + maxz = maxz ) } @@ -2037,17 +2046,15 @@ layout_with_lgl <- function( root <- as_igraph_vs(graph, root) - 1 } - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_layout_lgl, - graph, - as.double(maxiter), - as.double(maxdelta), - as.double(area), - as.double(coolexp), - as.double(repulserad), - as.double(cellsize), - root + layout_lgl_impl( + graph = graph, + maxiter = maxiter, + maxdelta = maxdelta, + area = area, + coolexp = coolexp, + repulserad = repulserad, + cellsize = cellsize, + root = root ) } @@ -2549,11 +2556,9 @@ merge_coords <- function(graphs, layouts, method = "dla") { cli::cli_abort("{.arg method} must be {.str dla}, not {.str {method}}.") } - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_layout_merge_dla, - graphs, - layouts + layout_merge_dla_impl( + graphs = graphs, + coords = layouts ) } @@ -2891,24 +2896,21 @@ layout_with_drl <- function( weights <- NULL } - on.exit(.Call(Rx_igraph_finalizer)) if (dim == 2) { - res <- .Call( - Rx_igraph_layout_drl, - graph, - seed, - use.seed, - options, - weights + res <- layout_drl_impl( + graph = graph, + res = seed, + use_seed = use.seed, + options = options, + weights = weights ) } else { - res <- .Call( - Rx_igraph_layout_drl_3d, - graph, - seed, - use.seed, - options, - weights + res <- layout_drl_3d_impl( + graph = graph, + res = seed, + use_seed = use.seed, + options = options, + weights = weights ) } res diff --git a/R/operators.R b/R/operators.R index 002e0128a3..9e4105a410 100644 --- a/R/operators.R +++ b/R/operators.R @@ -229,7 +229,7 @@ disjoint_union <- function(...) { lapply(graphs, ensure_igraph) on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_disjoint_union, graphs) + res <- .Call(Rx_igraph_disjoint_union, graphs) # disjoint_union_many_impl does not merge attributes ## Graph attributes graph.attributes(res) <- rename.attr.if.needed("g", graphs) @@ -350,9 +350,9 @@ disjoint_union <- function(...) { on.exit(.Call(Rx_igraph_finalizer)) if (call == "union") { - res <- .Call(Rx_igraph_union, newgraphs, edgemaps) + res <- .Call(Rx_igraph_union, newgraphs, edgemaps) # union_many_impl does not return edgemaps } else { - res <- .Call(Rx_igraph_intersection, newgraphs, edgemaps) + res <- .Call(Rx_igraph_intersection, newgraphs, edgemaps) # intersection_many_impl does not return edgemaps } maps <- res$edgemaps res <- res$graph @@ -390,9 +390,9 @@ disjoint_union <- function(...) { on.exit(.Call(Rx_igraph_finalizer)) if (call == "union") { - res <- .Call(Rx_igraph_union, graphs, edgemaps) + res <- .Call(Rx_igraph_union, graphs, edgemaps) # union_many_impl does not return edgemaps } else { - res <- .Call(Rx_igraph_intersection, graphs, edgemaps) + res <- .Call(Rx_igraph_intersection, graphs, edgemaps) # intersection_many_impl does not return edgemaps } maps <- res$edgemaps res <- res$graph @@ -848,7 +848,7 @@ compose <- function(g1, g2, byname = "auto") { length(edge_attr_names(g2)) != 0) on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_compose, g1, g2, edgemaps) + res <- .Call(Rx_igraph_compose, g1, g2, edgemaps) # compose_impl does not return edgemaps maps <- list(res$edge_map1, res$edge_map2) res <- res$graph diff --git a/R/par.R b/R/par.R index ac5d3d1c3f..f9b46ee9b3 100644 --- a/R/par.R +++ b/R/par.R @@ -76,7 +76,7 @@ getIgraphOpt <- function(x, default = NULL) { igraph.pars.set.verbose <- function(verbose) { if (is.logical(verbose)) { - .Call(Rx_igraph_set_verbose, verbose) + .Call(Rx_igraph_set_verbose, verbose) # internal, no _impl } else if (is.character(verbose)) { if (!verbose %in% c("tk", "tkconsole")) { cli::cli_abort("Unknown {.arg verbose} value.") @@ -89,7 +89,7 @@ igraph.pars.set.verbose <- function(verbose) { cli::cli_abort("tcltk package not available.") } } - .Call(Rx_igraph_set_verbose, TRUE) + .Call(Rx_igraph_set_verbose, TRUE) # internal, no _impl } else { cli::cli_abort("{.arg verbose} should be a logical or character scalar.") } diff --git a/R/pp.R b/R/pp.R index a412f1d434..081485d83e 100644 --- a/R/pp.R +++ b/R/pp.R @@ -20,5 +20,5 @@ ################################################################### get.all.simple.paths.pp <- function(vect) { - .Call(Rx_igraph_get_all_simple_paths_pp, vect) + .Call(Rx_igraph_get_all_simple_paths_pp, vect) # internal, no _impl } diff --git a/R/print.R b/R/print.R index 243a7d2055..d72292332c 100644 --- a/R/print.R +++ b/R/print.R @@ -33,7 +33,7 @@ sep = "", gal, " (g/", - .Call(Rx_igraph_get_attr_mode, object, 2L), + .Call(Rx_igraph_get_attr_mode, object, 2L), # internal, no _impl ")" ) } @@ -43,7 +43,7 @@ sep = "", val, " (v/", - .Call(Rx_igraph_get_attr_mode, object, 3L), + .Call(Rx_igraph_get_attr_mode, object, 3L), # internal, no _impl ")" ) } @@ -53,7 +53,7 @@ sep = "", edge_attr_names(object), " (e/", - .Call(Rx_igraph_get_attr_mode, object, 4L), + .Call(Rx_igraph_get_attr_mode, object, 4L), # internal, no _impl ")" ) } diff --git a/R/structural-properties.R b/R/structural-properties.R index e7c23846e9..1a6b6dc68c 100644 --- a/R/structural-properties.R +++ b/R/structural-properties.R @@ -768,7 +768,7 @@ diameter <- function( } on.exit(.Call(Rx_igraph_finalizer)) - .Call( + .Call( # diameter_impl returns more info (path); uses Dijkstra for weighted Rx_igraph_diameter, graph, as.logical(directed), @@ -797,7 +797,7 @@ get_diameter <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # diameter_impl returns more info (path) Rx_igraph_get_diameter, graph, as.logical(directed), @@ -833,7 +833,7 @@ farthest_vertices <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # no farthest_vertices_impl available Rx_igraph_farthest_points, graph, as.logical(directed), @@ -1245,7 +1245,7 @@ distances <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # distances_impl doesn't support algorithm selection Rx_igraph_shortest_paths, graph, v - 1, @@ -1329,7 +1329,7 @@ shortest_paths <- function( to <- as_igraph_vs(graph, to) - 1 on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # get_shortest_paths_impl doesn't support algorithm selection Rx_igraph_get_shortest_paths, graph, as_igraph_vs(graph, from) - 1, @@ -1522,24 +1522,11 @@ k_shortest_paths <- function( #' subcomponent(g, 1, "out") #' subcomponent(g, 1, "all") subcomponent <- function(graph, v, mode = c("all", "out", "in")) { - ensure_igraph(graph) - mode <- igraph_match_arg(mode) - mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3) - - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( - Rx_igraph_subcomponent, - graph, - as_igraph_vs(graph, v) - 1, - as.numeric(mode) - ) + - 1L - - if (igraph_opt("return.vs.es")) { - res <- create_vs(graph, res) - } - - res + subcomponent_impl( + graph = graph, + vid = v, + mode = mode + ) } #' Subgraph of a graph @@ -1822,7 +1809,7 @@ transitivity <- function( } else if (type == 1) { isolates_num <- as.double(switch(isolates, "nan" = 0, "zero" = 1)) if (is.null(vids)) { - res <- .Call( + res <- .Call( # transitivity_local_undirected_impl requires vids Rx_igraph_transitivity_local_undirected_all, graph, isolates_num @@ -2056,19 +2043,12 @@ ego_size <- function( mode = c("all", "out", "in"), mindist = 0 ) { - ensure_igraph(graph) - mode <- igraph_match_arg(mode) - mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3) - mindist <- as.numeric(mindist) - - on.exit(.Call(Rx_igraph_finalizer)) - .Call( - Rx_igraph_neighborhood_size, - graph, - as_igraph_vs(graph, nodes) - 1, - as.numeric(order), - as.numeric(mode), - mindist + neighborhood_size_impl( + graph = graph, + vids = nodes, + order = order, + mode = mode, + mindist = mindist ) } @@ -2170,27 +2150,13 @@ ego <- function( mode = c("all", "out", "in"), mindist = 0 ) { - ensure_igraph(graph) - mode <- igraph_match_arg(mode) - mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3) - mindist <- as.numeric(mindist) - - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( - Rx_igraph_neighborhood, - graph, - as_igraph_vs(graph, nodes) - 1, - as.numeric(order), - as.numeric(mode), - mindist + neighborhood_impl( + graph = graph, + vids = nodes, + order = order, + mode = mode, + mindist = mindist ) - res <- lapply(res, function(x) x + 1) - - if (igraph_opt("return.vs.es")) { - res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph)) - } - - res } #' @export @@ -2205,21 +2171,13 @@ make_ego_graph <- function( mode = c("all", "out", "in"), mindist = 0 ) { - ensure_igraph(graph) - mode <- igraph_match_arg(mode) - mode <- switch(mode, "out" = 1L, "in" = 2L, "all" = 3L) - mindist <- as.numeric(mindist) - - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( - Rx_igraph_neighborhood_graphs, - graph, - as_igraph_vs(graph, nodes) - 1, - as.numeric(order), - as.integer(mode), - mindist + neighborhood_graphs_impl( + graph = graph, + vids = nodes, + order = order, + mode = mode, + mindist = mindist ) - res } #' @export @@ -2449,15 +2407,13 @@ feedback_vertex_set <- function(graph, weights = NULL, algo = c("exact_ip")) { #' girth(g) #' girth <- function(graph, circle = TRUE) { - ensure_igraph(graph) - - on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call(Rx_igraph_girth, graph, as.logical(circle)) + # girth_impl always computes circle; slightly less efficient when circle=FALSE + res <- girth_impl(graph = graph) if (res$girth == 0) { res$girth <- Inf } - if (igraph_opt("return.vs.es") && circle) { - res$circle <- create_vs(graph, res$circle) + if (!circle) { + res$circle <- NULL } res } @@ -2768,7 +2724,7 @@ bfs <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # bfs_closure_impl returns only order, not rank/parent/pred/succ/dist Rx_igraph_bfs, graph, root, @@ -3024,7 +2980,7 @@ dfs <- function( } on.exit(.Call(Rx_igraph_finalizer)) - res <- .Call( + res <- .Call( # dfs_closure_impl returns only order/order_out, not parent/dist Rx_igraph_dfs, graph, root, @@ -3183,7 +3139,7 @@ count_components <- function(graph, mode = c("weak", "strong")) { mode <- switch(mode, "weak" = 1L, "strong" = 2L) on.exit(.Call(Rx_igraph_finalizer)) - .Call(Rx_igraph_no_components, graph, mode) + .Call(Rx_igraph_no_components, graph, mode) # connected_components_impl returns membership, not count } #' Count reachable vertices diff --git a/R/topology.R b/R/topology.R index c07d59e785..cf258d004e 100644 --- a/R/topology.R +++ b/R/topology.R @@ -220,7 +220,7 @@ graph.subisomorphic.lad <- function( on.exit(.Call(Rx_igraph_finalizer)) # Function call - res <- .Call( + res <- .Call( # subisomorphic_lad_impl lacks map/all.maps parameters Rx_igraph_subisomorphic_lad, pattern, target, diff --git a/R/utils.R b/R/utils.R index d172590cc0..83e7778acb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -72,7 +72,7 @@ capitalize <- function(x) { } address <- function(x) { - .Call(Rx_igraph_address, x) + .Call(Rx_igraph_address, x) # internal, no _impl } `%+%` <- function(x, y) { diff --git a/R/uuid.R b/R/uuid.R index b617afeff4..094427b2f4 100644 --- a/R/uuid.R +++ b/R/uuid.R @@ -5,7 +5,7 @@ generate_uuid <- function(use_time = NA) { get_graph_id <- function(graph) { if (!warn_version(graph)) { - .Call(Rx_igraph_get_graph_id, graph) + .Call(Rx_igraph_get_graph_id, graph) # internal, no _impl } else { NA_character_ } diff --git a/R/versions.R b/R/versions.R index 40b80ac2a1..4e515a2266 100644 --- a/R/versions.R +++ b/R/versions.R @@ -57,7 +57,7 @@ graph_version <- function(graph) { # Don't call is_igraph() here to avoid recursion stopifnot(inherits(graph, "igraph")) - .Call(Rx_igraph_graph_version, graph) + .Call(Rx_igraph_graph_version, graph) # internal, no _impl } #' igraph data structure versions @@ -99,13 +99,13 @@ upgrade_graph <- function(graph) { # g_ver < p_ver if (g_ver == ver_0_4) { - .Call(Rx_igraph_add_env, graph) + .Call(Rx_igraph_add_env, graph) # internal, no _impl } else if (g_ver == ver_0_7_999) { # Not observed in the wild - .Call(Rx_igraph_add_myid_to_env, graph) - .Call(Rx_igraph_add_version_to_env, graph) + .Call(Rx_igraph_add_myid_to_env, graph) # internal, no _impl + .Call(Rx_igraph_add_version_to_env, graph) # internal, no _impl } else if (g_ver == ver_0_8) { - .Call(Rx_igraph_add_version_to_env, graph) + .Call(Rx_igraph_add_version_to_env, graph) # internal, no _impl graph <- unclass(graph) graph[igraph_t_idx_oi:igraph_t_idx_is] <- list(NULL) class(graph) <- "igraph" @@ -130,7 +130,7 @@ warn_version <- function(graph) { .Call(Rx_igraph_vcount, graph) # graph_version() calls is_igraph(), but that function must call warn_version() for safety - their_version <- .Call(Rx_igraph_graph_version, graph) + their_version <- .Call(Rx_igraph_graph_version, graph) # internal, no _impl if (pkg_graph_version == their_version) { return(FALSE) @@ -151,7 +151,7 @@ warn_version <- function(graph) { # Users will have to call upgrade_graph(), but this is what the message # is about. if (pkg_graph_version <= ver_1_5_0) { - .Call(Rx_igraph_add_version_to_env, graph) + .Call(Rx_igraph_add_version_to_env, graph) # internal, no _impl } return(TRUE) } diff --git a/R/weakref.R b/R/weakref.R index 45970feeaf..2e1af8edfc 100644 --- a/R/weakref.R +++ b/R/weakref.R @@ -22,17 +22,17 @@ ## ----------------------------------------------------------------------- make_weak_ref <- function(key, value, finalizer = NULL) { - .Call(Rx_igraph_make_weak_ref, key, value, finalizer) + .Call(Rx_igraph_make_weak_ref, key, value, finalizer) # internal, no _impl } weak_ref_key <- function(ref) { - .Call(Rx_igraph_weak_ref_key, ref) + .Call(Rx_igraph_weak_ref_key, ref) # internal, no _impl } weak_ref_value <- function(ref) { - .Call(Rx_igraph_weak_ref_value, ref) + .Call(Rx_igraph_weak_ref_value, ref) # internal, no _impl } weak_ref_run_finalizer <- function(ref) { - .Call(Rx_igraph_weak_ref_run_finalizer, ref) + .Call(Rx_igraph_weak_ref_run_finalizer, ref) # internal, no _impl }