Skip to content

Commit

Permalink
chore: start deprecation of as_adj() alias of `as_adjacency_matrix(…
Browse files Browse the repository at this point in the history
…)` (#1524)
  • Loading branch information
aviator-app[bot] authored Sep 24, 2024
2 parents 635f07d + c7e627d commit a34e7c0
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 63 deletions.
16 changes: 8 additions & 8 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ arpack_defaults <- function() {
#' if (require(Matrix)) {
#' set.seed(42)
#' g <- sample_gnp(1000, 5 / 1000)
#' M <- as_adj(g, sparse = TRUE)
#' M <- as_adjacency_matrix(g, sparse = TRUE)
#' f2 <- function(x, extra = NULL) {
#' cat(".")
#' as.vector(M %*% x)
Expand Down Expand Up @@ -800,7 +800,7 @@ arpack.unpack.complex <- function(vectors, values, nev) {
#' cor(degree(g), sc)
#'
subgraph_centrality <- function(graph, diag = FALSE) {
A <- as_adj(graph)
A <- as_adjacency_matrix(graph)
if (!diag) {
diag(A) <- 0
}
Expand Down Expand Up @@ -860,7 +860,7 @@ subgraph_centrality <- function(graph, diag = FALSE) {
#' \item{values}{Numeric vector, the eigenvalues.} \item{vectors}{Numeric
#' matrix, with the eigenvectors as columns.}
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}
#' @seealso [as_adj()] to create a (sparse) adjacency matrix.
#' @seealso [as_adjacency_matrix()] to create a (sparse) adjacency matrix.
#' @keywords graphs
#' @examples
#'
Expand All @@ -869,7 +869,7 @@ subgraph_centrality <- function(graph, diag = FALSE) {
#' spectrum(kite)[c("values", "vectors")]
#'
#' ## Double check
#' eigen(as_adj(kite, sparse = FALSE))$vectors[, 1]
#' eigen(as_adjacency_matrix(kite, sparse = FALSE))$vectors[, 1]
#'
#' ## Should be the same as 'eigen_centrality' (but rescaled)
#' cor(eigen_centrality(kite)$vector, spectrum(kite)$vectors)
Expand Down Expand Up @@ -1361,7 +1361,7 @@ bonpow.dense <- function(graph, nodes = V(graph),
rescale = FALSE, tol = 1e-7) {
ensure_igraph(graph)

d <- as_adj(graph)
d <- as_adjacency_matrix(graph)
if (!loops) {
diag(d) <- 0
}
Expand Down Expand Up @@ -1389,7 +1389,7 @@ bonpow.sparse <- function(graph, nodes = V(graph), loops = FALSE,
vg <- vcount(graph)

## sparse adjacency matrix
d <- as_adj(graph, sparse = TRUE)
d <- as_adjacency_matrix(graph, sparse = TRUE)

## sparse identity matrix
id <- as(Matrix::Matrix(diag(vg), doDiag = FALSE), "generalMatrix")
Expand Down Expand Up @@ -1564,7 +1564,7 @@ alpha.centrality.dense <- function(graph, nodes = V(graph), alpha = 1,
attr <- NULL
}

d <- t(as_adj(graph, attr = attr, sparse = FALSE))
d <- t(as_adjacency_matrix(graph, attr = attr, sparse = FALSE))
if (!loops) {
diag(d) <- 0
}
Expand Down Expand Up @@ -1605,7 +1605,7 @@ alpha.centrality.sparse <- function(graph, nodes = V(graph), alpha = 1,
attr <- NULL
}

M <- Matrix::t(as_adj(graph, attr = attr, sparse = TRUE))
M <- Matrix::t(as_adjacency_matrix(graph, attr = attr, sparse = TRUE))

## Create an identity matrix
M2 <- Matrix::sparseMatrix(dims = c(vc, vc), i = 1:vc, j = 1:vc, x = rep(1, vc))
Expand Down
32 changes: 26 additions & 6 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,30 @@ as_adjacency_matrix <- function(graph, type = c("both", "upper", "lower"),
}
}

#' Convert a graph to an adjacency matrix
#'
#' `r lifecycle::badge("deprecated")`
#' We plan to remove `as_adj()` in favor of the more explicitly named
#' `as_adjacency_matrix()` so please use `as_adjacency_matrix()` instead.
#'
#' @export
#' @rdname as_adjacency_matrix
as_adj <- as_adjacency_matrix

#' @inheritParams as_adjacency_matrix
#' @keywords internal
as_adj <- function(graph, type = c("both", "upper", "lower"),
attr = NULL, edges = deprecated(), names = TRUE,
sparse = igraph_opt("sparsematrices")) {

lifecycle::deprecate_soft("2.0.4", "as_adj()", "as_adjacency_matrix()")

as_adjacency_matrix(
graph = graph,
type = type,
attr = attr,
edges = edges,
names = names,
sparse = sparse
)
}
#' Convert a graph to an edge list
#'
#' Sometimes it is useful to work with a standard representation of a
Expand Down Expand Up @@ -549,7 +569,7 @@ as_undirected <- function(graph, mode = c("collapse", "each", "mutual"), edge.at
#' vectors of the adjacency lists are coerced to `igraph.vs`, this can be
#' a very expensive operation on large graphs.
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}
#' @seealso [as_edgelist()], [as_adj()]
#' @seealso [as_edgelist()], [as_adjacency_matrix()]
#' @family conversion
#' @export
#' @keywords graphs
Expand Down Expand Up @@ -652,7 +672,7 @@ as_adj_edge_list <- function(graph,
#' whenever possible, before adding them to the igraph graph.
#' @return `graph_from_graphnel()` returns an igraph graph object.
#' @seealso [as_graphnel()] for the other direction,
#' [as_adj()], [graph_from_adjacency_matrix()],
#' [as_adjacency_matrix()], [graph_from_adjacency_matrix()],
#' [as_adj_list()] and [graph_from_adj_list()] for other
#' graph representations.
#' @examplesIf rlang::is_installed("graph")
Expand Down Expand Up @@ -741,7 +761,7 @@ graph_from_graphnel <- function(graphNEL, name = TRUE, weight = TRUE,
#' @param graph An igraph graph object.
#' @return `as_graphnel()` returns a graphNEL graph object.
#' @seealso [graph_from_graphnel()] for the other direction,
#' [as_adj()], [graph_from_adjacency_matrix()],
#' [as_adjacency_matrix()], [graph_from_adjacency_matrix()],
#' [as_adj_list()] and [graph_from_adj_list()] for
#' other graph representations.
#'
Expand Down
16 changes: 8 additions & 8 deletions R/indexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,27 @@
res
} else if (missing(i) && missing(j)) {
if (missing(edges)) {
as_adj(x, sparse = sparse, attr = attr)
as_adjacency_matrix(x, sparse = sparse, attr = attr)
} else {
as_adj(x, sparse = sparse, attr = attr, edges = edges)
as_adjacency_matrix(x, sparse = sparse, attr = attr, edges = edges)
}
} else if (missing(j)) {
if (missing(edges)) {
as_adj(x, sparse = sparse, attr = attr)[i, , drop = drop]
as_adjacency_matrix(x, sparse = sparse, attr = attr)[i, , drop = drop]
} else {
as_adj(x, sparse = sparse, attr = attr, edges = edges)[i, , drop = drop]
as_adjacency_matrix(x, sparse = sparse, attr = attr, edges = edges)[i, , drop = drop]
}
} else if (missing(i)) {
if (missing(edges)) {
as_adj(x, sparse = sparse, attr = attr)[, j, drop = drop]
as_adjacency_matrix(x, sparse = sparse, attr = attr)[, j, drop = drop]
} else {
as_adj(x, sparse = sparse, attr = attr, edges = edges)[, j, drop = drop]
as_adjacency_matrix(x, sparse = sparse, attr = attr, edges = edges)[, j, drop = drop]
}
} else {
if (missing(edges)) {
as_adj(x, sparse = sparse, attr = attr)[i, j, drop = drop]
as_adjacency_matrix(x, sparse = sparse, attr = attr)[i, j, drop = drop]
} else {
as_adj(x, sparse = sparse, attr = attr, edges = edges)[i, j, drop = drop]
as_adjacency_matrix(x, sparse = sparse, attr = attr, edges = edges)[i, j, drop = drop]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/stochastic_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ get.stochastic <- function(graph, column.wise = FALSE, sparse = igraph_opt("spar
#' @return A regular matrix or a matrix of class `Matrix` if a
#' `sparse` argument was `TRUE`.
#' @author Gabor Csardi \email{csardi.gabor@@gmail.com}
#' @seealso [as_adj()]
#' @seealso [as_adjacency_matrix()]
#' @export
#' @keywords graphs
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion demo/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (require(Matrix)) {
} else {
myimage <- image
}
A <- as_adj(G)
A <- as_adjacency_matrix(G)
myimage(A)

pause()
Expand Down
2 changes: 1 addition & 1 deletion man/arpack.Rd

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

54 changes: 54 additions & 0 deletions man/as_adj.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/as_adj_list.Rd

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

10 changes: 0 additions & 10 deletions man/as_adjacency_matrix.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/as_graphnel.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/graph_from_graphnel.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/spectrum.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/stochastic_matrix.Rd

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

Loading

0 comments on commit a34e7c0

Please sign in to comment.