Skip to content
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
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Imports:
cli,
graphics,
grDevices,
lifecycle,
magrittr,
Matrix,
pkgconfig (>= 2.0.0),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ export(hrg_tree)
export(hub.score)
export(hub_score)
export(identical_graphs)
export(igraph.arpack.default)
export(igraph.console)
export(igraph.drl.coarsen)
export(igraph.drl.coarsest)
Expand Down
30 changes: 15 additions & 15 deletions R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ personalized_pagerank_impl <- function(graph, algo=c("prpack", "arpack"), vids=V
if (algo == 0L) {
options <- list(niter=1000, eps=0.001)
} else if (algo == 1L) {
options <- arpack_defaults
options <- arpack_defaults()
} else {
options <- NULL
}
Expand Down Expand Up @@ -549,7 +549,7 @@ count_multiple_impl <- function(graph, eids=E(graph)) {
res
}

eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weights=NULL, options=arpack_defaults) {
eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weights=NULL, options=arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
directed <- as.logical(directed)
Expand All @@ -562,7 +562,7 @@ eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weigh
} else {
weights <- NULL
}
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options <- modify_list(arpack_defaults(), options)

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -573,7 +573,7 @@ eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weigh
res
}

hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults) {
hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
scale <- as.logical(scale)
Expand All @@ -585,7 +585,7 @@ hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defau
} else {
weights <- NULL
}
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -596,7 +596,7 @@ hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defau
res
}

authority_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults) {
authority_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
scale <- as.logical(scale)
Expand All @@ -608,7 +608,7 @@ authority_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack
} else {
weights <- NULL
}
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand Down Expand Up @@ -772,12 +772,12 @@ centralization_closeness_tmax_impl <- function(graph=NULL, nodes=0, mode=c("out"
res
}

centralization_eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, options=arpack_defaults, normalized=TRUE) {
centralization_eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, options=arpack_defaults(), normalized=TRUE) {
# Argument checks
ensure_igraph(graph)
directed <- as.logical(directed)
scale <- as.logical(scale)
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp
normalized <- as.logical(normalized)

on.exit( .Call(R_igraph_finalizer) )
Expand Down Expand Up @@ -2013,7 +2013,7 @@ scg_norm_eps_impl <- function(V, groups, mtype=c("symmetric", "laplacian", "stoc
res
}

adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), scaled=TRUE, cvec=graph.strength(graph, weights=weights)/(vcount(graph)-1), options=igraph.arpack.default) {
adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), scaled=TRUE, cvec=graph.strength(graph, weights=weights)/(vcount(graph)-1), options=arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
no <- as.integer(no)
Expand All @@ -2028,7 +2028,7 @@ adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("
which <- switch(igraph.match.arg(which), "lm"=0L, "la"=2L, "sa"=3L)
scaled <- as.logical(scaled)
cvec <- as.numeric(cvec)
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -2037,7 +2037,7 @@ adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("
res
}

laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), type=c("default", "D-A", "DAD", "I-DAD", "OAP"), scaled=TRUE, options=igraph.arpack.default) {
laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), type=c("default", "D-A", "DAD", "I-DAD", "OAP"), scaled=TRUE, options=arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
no <- as.integer(no)
Expand All @@ -2055,7 +2055,7 @@ laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("
"da"=0L, "d-a"=0L, "idad"=1L, "i-dad"=1L, "dad"=2L,
"oap"=3L)
scaled <- as.logical(scaled)
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -2064,15 +2064,15 @@ laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("
res
}

eigen_adjacency_impl <- function(graph, algorithm=c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"), which=list(), options=arpack_defaults) {
eigen_adjacency_impl <- function(graph, algorithm=c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"), which=list(), options=arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
algorithm <- switch(igraph.match.arg(algorithm), "auto"=0, "lapack"=1,
"arpack"=2, "comp_auto"=3, "comp_lapack"=4,
"comp_arpack"=5)
which.tmp <- eigen_defaults();
which.tmp[ names(which) ] <- which ; which <- which.tmp
options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp
options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand Down
38 changes: 25 additions & 13 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,13 @@ estimate_closeness <- function(graph, vids = V(graph), mode = c("out", "in", "al
#' @rdname arpack
#' @family arpack
#' @export
arpack_defaults <- list(
bmat = "I", n = 0, which = "XX", nev = 1, tol = 0.0,
ncv = 3, ldv = 0, ishift = 1, maxiter = 3000, nb = 1,
mode = 1, start = 0, sigma = 0.0, sigmai = 0.0
)
arpack_defaults <- function() {
list(
bmat = "I", n = 0, which = "XX", nev = 1, tol = 0.0,
ncv = 3, ldv = 0, ishift = 1, maxiter = 3000, nb = 1,
mode = 1, start = 0, sigma = 0.0, sigmai = 0.0
)
}

#' ARPACK eigenvector calculation
#'
Expand Down Expand Up @@ -415,8 +417,7 @@ arpack_defaults <- list(
#' re-orthogonalization.} } } Please see the ARPACK documentation for
#' additional details.
#'
#' @aliases arpack arpack-options igraph.arpack.default arpack.unpack.complex
#' arpack_defaults
#' @aliases arpack arpack-options arpack.unpack.complex arpack_defaults
#' @param func The function to perform the matrix-vector multiplication. ARPACK
#' requires to perform these by the user. The function gets the vector \eqn{x}
#' as the first argument, and it should return \eqn{Ax}, where \eqn{A} is the
Expand Down Expand Up @@ -496,27 +497,38 @@ arpack_defaults <- list(
#' }
#' @family arpack
#' @export
arpack <- function(func, extra = NULL, sym = FALSE, options = arpack_defaults,
arpack <- function(func, extra = NULL, sym = FALSE, options = arpack_defaults(),
env = parent.frame(), complex = !sym) {

eval_try <- rlang::eval_tidy(options)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need eval_tidy for? Can't we just force, and if the user has passed a function, we call it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to catch the case where the argument is arpack_defaults and a function. I'm using rlang::call_args(rlang::current_call())[["options"]] on the following line hence the rlang here, especially as rlang is a dependency.

Now, maybe this whole "hack" is a bad idea.

options_value <- rlang::call_args(rlang::current_call())[["options"]]
if (is(eval_try, "function") && as.character(options_value) == "arpack_defaults") {
lifecycle::deprecate_soft(
"1.5.0",
I("arpack_defaults"),
"arpack_defaults()",
details = c("So the function arpack_defaults(), not an object called code arpack_defaults.")
)
options <- arpack_defaults()
}

if (!is.list(options) ||
(is.null(names(options)) && length(options) != 0)) {
stop("options must be a named list")
}
if (any(names(options) == "")) {
stop("all options must be named")
}
if (any(!names(options) %in% names(arpack_defaults))) {
if (any(!names(options) %in% names(arpack_defaults()))) {
stop(
"unkown ARPACK option(s): ",
paste(setdiff(names(options), names(arpack_defaults)),
paste(setdiff(names(options), names(arpack_defaults())),
collapse = ", "
)
)
}

options.tmp <- arpack_defaults
options.tmp[names(options)] <- options
options <- options.tmp
options <- modify_list(arpack_defaults(), options)

if (sym && complex) {
complex <- FALSE
Expand Down
6 changes: 2 additions & 4 deletions R/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ igraph.i.levc.arp <- function(externalP, externalE) {
#'
cluster_leading_eigen <- function(graph, steps = -1, weights = NULL,
start = NULL,
options = arpack_defaults,
options = arpack_defaults(),
callback = NULL, extra = NULL,
env = parent.frame()) {
# Argument checks
Expand All @@ -1673,9 +1673,7 @@ cluster_leading_eigen <- function(graph, steps = -1, weights = NULL,
if (!is.null(start)) {
start <- as.numeric(start) - 1
}
options.tmp <- arpack_defaults
options.tmp[names(options)] <- options
options <- options.tmp
options <- modify_list(arpack_defaults(), options)

on.exit(.Call(R_igraph_finalizer))
# Function call
Expand Down
4 changes: 2 additions & 2 deletions R/embedding.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#' graph. This vector is added to the diagonal of the adjacency matrix.
#' @param options A named list containing the parameters for the SVD
#' computation algorithm in ARPACK. By default, the list of values is assigned
#' the values given by [igraph.arpack.default].
#' the values given by [arpack_defaults()].
#' @return A list containing with entries: \item{X}{Estimated latent positions,
#' an `n` times `no` matrix, `n` is the number of vertices.}
#' \item{Y}{`NULL` for undirected graphs, the second half of the latent
Expand Down Expand Up @@ -203,7 +203,7 @@ dim_select <- dim_select_impl
#' returned instead of \eqn{X} and \eqn{Y}.
#' @param options A named list containing the parameters for the SVD
#' computation algorithm in ARPACK. By default, the list of values is assigned
#' the values given by [igraph.arpack.default].
#' the values given by [arpack_defaults()].
#' @return A list containing with entries: \item{X}{Estimated latent positions,
#' an `n` times `no` matrix, `n` is the number of vertices.}
#' \item{Y}{`NULL` for undirected graphs, the second half of the latent
Expand Down
2 changes: 1 addition & 1 deletion R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ layout.lgl <- function(..., params = list()) {
#' l <- layout_with_mds(g)
#' plot(g, layout = l, vertex.label = NA, vertex.size = 3)
layout_with_mds <- function(graph, dist = NULL, dim = 2,
options = arpack_defaults) {
options = arpack_defaults()) {
# Argument checks
ensure_igraph(graph)
if (!is.null(dist)) dist <- structure(as.double(dist), dim = dim(dist))
Expand Down
4 changes: 1 addition & 3 deletions R/layout_drl.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ layout_with_drl <- function(graph, use.seed = FALSE,
use.seed <- as.logical(use.seed)
seed <- as.matrix(seed)

options.tmp <- drl_defaults$default
options.tmp[names(options)] <- options
options <- options.tmp
options <- modify_list(drl_defaults$default, options)

if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ chr <- as.character
drop_null <- function(x) {
x[!sapply(x, is.null)]
}

# from https://github.com/r-lib/pkgdown/blob/c354aa7e5ea1f9936692494c28c89e5bdd31fc68/R/utils.R#L109
modify_list <- function(x, y) {
if (is.null(y)) {
return(x)
}

utils::modifyList(x, y)
}
2 changes: 0 additions & 2 deletions R/zzz-deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ deprecated("hrg.predict", predict_edges)
#' @export hub.score
deprecated("hub.score", hub_score)

#' @export igraph.arpack.default
deprecated("igraph.arpack.default", arpack_defaults)
#' @export igraph.console
deprecated("igraph.console", console)
#' @export igraph.sample
Expand Down
10 changes: 2 additions & 8 deletions man/arpack.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/centr_eigen.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cluster_leading_eigen.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/eigen_centrality.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/embed_adjacency_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/embed_laplacian_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading