Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up as_adj_list if igraph_opt("return.vs.es") is false #196

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ as.undirected <- function(graph, mode=c("collapse", "each", "mutual"), edge.attr
#' to include in the lists. \sQuote{\code{out}} is for outgoing edges/vertices,
#' \sQuote{\code{in}} is for incoming edges/vertices, \sQuote{\code{all}} is
#' for both. This argument is ignored for undirected graphs.
#' @return A list of numeric vectors.
#' @return A list of \code{igraph.vs} or a list of numeric vectors depending on
#' the value of \code{igraph_opt("return.vs.es")}, see details for performance
#' characteristics.
#' @details If \code{igraph_opt("return.vs.es")} is true (default), the numeric
#' vectors of the adjacency lists are coerced to \code{igraph.vs}, this can be
#' a very expensive operation on large graphs.
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}
#' @seealso \code{\link{as_edgelist}}, \code{\link{as_adj}}
#' @export
Expand All @@ -387,7 +392,12 @@ as_adj_list <- function(graph, mode=c("all", "out", "in", "total")) {
mode <- as.numeric(switch(mode, "out"=1, "in"=2, "all"=3, "total"=3))
on.exit( .Call(C_R_igraph_finalizer) )
res <- .Call(C_R_igraph_get_adjlist, graph, mode)
res <- lapply(res, function(x) V(graph)[x + 1])
res <- lapply(res, `+`, 1)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, create_vs, graph = graph)
}

if (is_named(graph)) names(res) <- V(graph)$name
res
}
Expand Down
16 changes: 9 additions & 7 deletions R/structural.properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -1656,13 +1656,15 @@ ego_size <- function(graph, order = 1, nodes=V(graph),
#' steps are counted. \sQuote{"all"} ignores the direction of the edges. This
#' argument is ignored for undirected graphs.
#' @param mindist The minimum distance to include the vertex in the result.
#' @return \code{ego_size} returns with an integer vector.
#'
#' \code{ego} returns with a list of integer vectors.
#'
#' \code{make_ego_graph} returns with a list of graphs.
#'
#' \code{connect} returns with a new graph object.
#' @return
#' \itemize{
#' \item{\code{ego_size} returns with an integer vector.}
#' \item{\code{ego} returns A list of \code{igraph.vs} or a list of numeric
#' vectors depending on the value of \code{igraph_opt("return.vs.es")},
#' see details for performance characteristics.}
#' \item{\code{make_ego_graph} returns with a list of graphs.}
#' \item{\code{connect} returns with a new graph object.}
#' }
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}, the first version was
#' done by Vincent Matossian
#' @export
Expand Down