Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cf1575a
Initial plan
Copilot Jan 24, 2026
e181050
refactor: replace .Call() with _impl functions in R/make.R and others
Copilot Jan 24, 2026
9561c7f
Replace .Call() with _impl in R/games.R and R/flow.R
Copilot Jan 24, 2026
df951cc
Fix callaway_traits and establishment games to extract graph from result
Copilot Jan 24, 2026
b9ae7fd
fix: correct parameter passing to _impl functions
Copilot Jan 24, 2026
8a2f0a0
Merge branch 'main' into copilot/replace-call-expressions-with-impl-f…
krlmlr Jan 24, 2026
5500dce
chore: Auto-update from GitHub Actions
krlmlr Jan 24, 2026
6d07b24
fix: pass string parameters to _impl functions instead of numeric
Copilot Jan 24, 2026
90ab990
fix: correct get_edge_ids() to return numeric and update snapshot
Copilot Jan 24, 2026
593e779
Merge remote-tracking branch 'origin/main' into copilot/replace-call-…
Copilot Jan 24, 2026
fd37a96
Add R conversion
krlmlr Jan 24, 2026
162fe6a
Edge case
krlmlr Jan 24, 2026
7d1f778
Merge remote-tracking branch 'origin/main' into copilot/replace-call-…
krlmlr Jan 24, 2026
699950e
chore: Auto-update from GitHub Actions
krlmlr Jan 24, 2026
af80285
Merge branch 'main' into copilot/replace-call-expressions-with-impl-f…
krlmlr Jan 25, 2026
23b177f
Tweak tests
krlmlr Jan 25, 2026
ad144c5
Merge branch 'main' into copilot/replace-call-expressions-with-impl-f…
krlmlr Jan 25, 2026
4ccab78
chore: Auto-update from GitHub Actions
krlmlr Jan 25, 2026
c47993e
Fix treating weighted graph as unweighted on request
krlmlr Jan 25, 2026
6426dcc
refactor: replace get.adjacency.sparse() with get_adjacency_sparse_im…
Copilot Jan 25, 2026
1c6c97c
chore: Auto-update from GitHub Actions
Jan 25, 2026
66890b7
Fix sparse case
krlmlr Jan 25, 2026
fd14478
Merge branch 'main' into copilot/replace-call-expressions-with-impl-f…
krlmlr Jan 26, 2026
5348f7e
Merge branch 'main' into copilot/replace-call-expressions-with-impl-f…
krlmlr Jan 26, 2026
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: 9 additions & 5 deletions R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ add_edges_impl <- function(
) {
# Argument checks
ensure_igraph(graph)
edges <- as_igraph_vs(graph, edges)

on.exit(.Call(R_igraph_finalizer))
# Function call
res <- .Call(
R_igraph_add_edges,
graph,
edges
edges - 1
)

res
Expand Down Expand Up @@ -354,6 +355,7 @@ get_eids_impl <- function(
) {
# Argument checks
ensure_igraph(graph)
pairs <- as_igraph_vs(graph, pairs)
directed <- as.logical(directed)
error <- as.logical(error)

Expand All @@ -362,7 +364,7 @@ get_eids_impl <- function(
res <- .Call(
R_igraph_get_eids,
graph,
pairs,
pairs - 1,
directed,
error
)
Expand Down Expand Up @@ -7244,7 +7246,7 @@ edgelist_percolation_impl <- function(
# Function call
res <- .Call(
R_igraph_edgelist_percolation,
edges
edges - 1
)

res
Expand Down Expand Up @@ -8763,6 +8765,7 @@ similarity_dice_pairs_impl <- function(
) {
# Argument checks
ensure_igraph(graph)
pairs <- as_igraph_vs(graph, pairs)
mode <- switch_igraph_arg(
mode,
"out" = 1L,
Expand All @@ -8777,7 +8780,7 @@ similarity_dice_pairs_impl <- function(
res <- .Call(
R_igraph_similarity_dice_pairs,
graph,
pairs,
pairs - 1,
mode,
loops
)
Expand Down Expand Up @@ -8883,6 +8886,7 @@ similarity_jaccard_pairs_impl <- function(
) {
# Argument checks
ensure_igraph(graph)
pairs <- as_igraph_vs(graph, pairs)
mode <- switch_igraph_arg(
mode,
"out" = 1L,
Expand All @@ -8897,7 +8901,7 @@ similarity_jaccard_pairs_impl <- function(
res <- .Call(
R_igraph_similarity_jaccard_pairs,
graph,
pairs,
pairs - 1,
mode,
loops
)
Expand Down
11 changes: 4 additions & 7 deletions R/components.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,15 @@ decompose <- function(
) {
ensure_igraph(graph)
mode <- igraph_match_arg(mode)
mode <- switch(mode, "weak" = 1L, "strong" = 2L)

if (is.na(max.comps)) {
max.comps <- -1
}
on.exit(.Call(Rx_igraph_finalizer))
.Call(
Rx_igraph_decompose,
decompose_impl(
graph,
as.numeric(mode),
as.numeric(max.comps),
as.numeric(min.vertices)
mode,
max.comps,
min.vertices
Comment on lines +211 to +215
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

decompose_impl() expects mode as a character value (it uses switch_igraph_arg(mode, ...)). In this function, mode is converted to an integer earlier and then passed here, which will error (e.g., tolower(1L)). Pass the matched mode string ("weak"/"strong") to decompose_impl() instead and remove the numeric conversion.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 6d07b24. Removed the numeric conversion - decompose_impl() expects the string mode parameter and handles the conversion internally.

)
}

Expand Down
85 changes: 23 additions & 62 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ get.adjacency.dense <- function(
graph,
type = c("both", "upper", "lower"),
attr = NULL,
weights = NULL,
loops = c("once", "twice", "ignore"),
names = TRUE
) {
Expand All @@ -243,20 +242,17 @@ get.adjacency.dense <- function(
)
}
loops <- igraph_match_arg(loops)
loops <- switch(loops, "ignore" = 0L, "twice" = 1L, "once" = 2L)

if (!is.null(weights)) {
weights <- as.numeric(weights)
# Map "ignore" to "none" for get_adjacency_impl
if (loops == "ignore") {
loops <- "none"
}

if (is.null(attr)) {
on.exit(.Call(Rx_igraph_finalizer))
type <- switch(type, "upper" = 0, "lower" = 1, "both" = 2)
res <- .Call(
Rx_igraph_get_adjacency,
# FIXME: Use get_adjacency_impl() also for non-NULL attr
res <- get_adjacency_impl(
graph,
as.numeric(type),
weights,
type,
weights = numeric(),
loops
)
} else {
Expand Down Expand Up @@ -287,67 +283,33 @@ get.adjacency.sparse <- function(

type <- igraph_match_arg(type)

vc <- vcount(graph)

el <- as_edgelist(graph, names = FALSE)
use.last.ij <- FALSE

if (!is.null(attr)) {
# Prepare weights parameter
if (is.null(attr)) {
weights <- numeric()
} else {
attr <- as.character(attr)
if (!attr %in% edge_attr_names(graph)) {
cli::cli_abort("No such edge attribute", call = call)
}
value <- edge_attr(graph, name = attr)
if (!is.numeric(value) && !is.logical(value)) {
weights <- edge_attr(graph, name = attr)
if (!is.numeric(weights) && !is.logical(weights)) {
cli::cli_abort(
"Matrices must be either numeric or logical, and the edge attribute is not",
call = call
)
}
} else {
value <- rep(1, nrow(el))
}

if (is_directed(graph)) {
res <- Matrix::sparseMatrix(
dims = c(vc, vc),
i = el[, 1],
j = el[, 2],
x = value,
use.last.ij = use.last.ij
)
} else {
if (type == "upper") {
## upper
res <- Matrix::sparseMatrix(
dims = c(vc, vc),
i = pmin(el[, 1], el[, 2]),
j = pmax(el[, 1], el[, 2]),
x = value,
use.last.ij = use.last.ij
)
} else if (type == "lower") {
## lower
res <- Matrix::sparseMatrix(
dims = c(vc, vc),
i = pmax(el[, 1], el[, 2]),
j = pmin(el[, 1], el[, 2]),
x = value,
use.last.ij = use.last.ij
)
} else if (type == "both") {
## both
res <- Matrix::sparseMatrix(
dims = c(vc, vc),
i = pmin(el[, 1], el[, 2]),
j = pmax(el[, 1], el[, 2]),
x = value,
symmetric = TRUE,
use.last.ij = use.last.ij
)
res <- as(res, "generalMatrix")
}
}
# Use the library implementation
tmp <- get_adjacency_sparse_impl(
graph,
type,
weights,
loops = "once"
)

# Convert to proper Matrix object
res <- igraph.i.spMatrix(tmp)

if (names && "name" %in% vertex_attr_names(graph)) {
colnames(res) <- rownames(res) <- V(graph)$name
Expand Down Expand Up @@ -427,7 +389,6 @@ as_adjacency_matrix <- function(
graph,
type = type,
attr = attr,
weights = NULL,
names = names,
loops = "once"
)
Expand Down
51 changes: 21 additions & 30 deletions R/flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,11 @@ min_cut <- function(
}
} else {
if (value.only) {
res <- .Call(
Rx_igraph_st_mincut_value,
graph,
as_igraph_vs(graph, source) - 1,
as_igraph_vs(graph, target) - 1,
capacity
res <- st_mincut_value_impl(
graph = graph,
source = source,
target = target,
capacity = capacity
)
} else {
res <- st_mincut_impl(
Expand Down Expand Up @@ -526,12 +525,10 @@ vertex_connectivity <- function(
if (is.null(source) && is.null(target)) {
vertex_connectivity_impl(graph = graph, checks = checks)
} else if (!is.null(source) && !is.null(target)) {
on.exit(.Call(Rx_igraph_finalizer))
.Call(
Rx_igraph_st_vertex_connectivity,
graph,
as_igraph_vs(graph, source) - 1,
as_igraph_vs(graph, target) - 1
st_vertex_connectivity_impl(
graph = graph,
source = source,
target = target
)
} else {
cli::cli_abort(c(
Expand Down Expand Up @@ -631,12 +628,10 @@ edge_connectivity <- function(
if (is.null(source) && is.null(target)) {
edge_connectivity_impl(graph = graph, checks = checks)
} else if (!is.null(source) && !is.null(target)) {
on.exit(.Call(Rx_igraph_finalizer))
.Call(
Rx_igraph_st_edge_connectivity,
graph,
as_igraph_vs(graph, source) - 1,
as_igraph_vs(graph, target) - 1
st_edge_connectivity_impl(
graph = graph,
source = source,
target = target
)
} else {
cli::cli_abort(c(
Expand All @@ -653,12 +648,10 @@ edge_disjoint_paths <- function(graph, source = NULL, target = NULL) {
if (is.null(source) || is.null(target)) {
cli::cli_abort("Both source and target must be given")
}
on.exit(.Call(Rx_igraph_finalizer))
.Call(
Rx_igraph_edge_disjoint_paths,
graph,
as_igraph_vs(graph, source) - 1,
as_igraph_vs(graph, target) - 1
edge_disjoint_paths_impl(
graph = graph,
source = source,
target = target
)
}

Expand All @@ -670,12 +663,10 @@ vertex_disjoint_paths <- function(graph, source = NULL, target = NULL) {
cli::cli_abort("Both source and target must be given")
}

on.exit(.Call(Rx_igraph_finalizer))
.Call(
Rx_igraph_vertex_disjoint_paths,
graph,
as_igraph_vs(graph, source) - 1,
as_igraph_vs(graph, target) - 1
vertex_disjoint_paths_impl(
graph = graph,
source = source,
target = target
)
}

Expand Down
Loading
Loading