Skip to content

Commit 42322f9

Browse files
CopilotkrlmlrCopilot
authored
feat: autogenerate remaining simple functions (#2551)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> Co-authored-by: Copilot <Copilot@users.noreply.github.com> Co-authored-by: Kirill Müller <kirill@cynkra.com> Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
1 parent 067eb1d commit 42322f9

11 files changed

Lines changed: 972 additions & 38 deletions

File tree

R/aaa-auto.R

Lines changed: 231 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,48 @@ edges_impl <- function(
304304
res
305305
}
306306

307+
get_eid_impl <- function(
308+
graph,
309+
from,
310+
to,
311+
directed = TRUE,
312+
error = TRUE
313+
) {
314+
# Argument checks
315+
ensure_igraph(graph)
316+
from <- as_igraph_vs(graph, from)
317+
if (length(from) != 1) {
318+
cli::cli_abort(
319+
"{.arg from} must specify exactly one vertex",
320+
call = rlang::caller_env()
321+
)
322+
}
323+
to <- as_igraph_vs(graph, to)
324+
if (length(to) != 1) {
325+
cli::cli_abort(
326+
"{.arg to} must specify exactly one vertex",
327+
call = rlang::caller_env()
328+
)
329+
}
330+
directed <- as.logical(directed)
331+
error <- as.logical(error)
332+
333+
on.exit(.Call(R_igraph_finalizer))
334+
# Function call
335+
res <- .Call(
336+
R_igraph_get_eid,
337+
graph,
338+
from - 1,
339+
to - 1,
340+
directed,
341+
error
342+
)
343+
if (igraph_opt("return.vs.es")) {
344+
res <- create_es(graph, res)
345+
}
346+
res
347+
}
348+
307349
get_eids_impl <- function(
308350
graph,
309351
pairs,
@@ -9454,6 +9496,53 @@ community_infomap_impl <- function(
94549496
res
94559497
}
94569498

9499+
community_voronoi_impl <- function(
9500+
graph,
9501+
lengths = NULL,
9502+
weights = NULL,
9503+
mode = c("out", "in", "all", "total"),
9504+
radius = -1
9505+
) {
9506+
# Argument checks
9507+
ensure_igraph(graph)
9508+
if (!is.null(lengths) && !all(is.na(lengths))) {
9509+
lengths <- as.numeric(lengths)
9510+
} else {
9511+
lengths <- NULL
9512+
}
9513+
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
9514+
weights <- E(graph)$weight
9515+
}
9516+
if (!is.null(weights) && !all(is.na(weights))) {
9517+
weights <- as.numeric(weights)
9518+
} else {
9519+
weights <- NULL
9520+
}
9521+
mode <- switch_igraph_arg(
9522+
mode,
9523+
"out" = 1L,
9524+
"in" = 2L,
9525+
"all" = 3L,
9526+
"total" = 3L
9527+
)
9528+
radius <- as.numeric(radius)
9529+
9530+
on.exit(.Call(R_igraph_finalizer))
9531+
# Function call
9532+
res <- .Call(
9533+
R_igraph_community_voronoi,
9534+
graph,
9535+
lengths,
9536+
weights,
9537+
mode,
9538+
radius
9539+
)
9540+
if (igraph_opt("return.vs.es")) {
9541+
res$generators <- create_vs(graph, res$generators)
9542+
}
9543+
res
9544+
}
9545+
94579546
graphlets_impl <- function(
94589547
graph,
94599548
weights = NULL,
@@ -9531,6 +9620,12 @@ graphlets_project_impl <- function(
95319620
} else {
95329621
weights <- NULL
95339622
}
9623+
if (!is.null(cliques) && !is.list(cliques)) {
9624+
cli::cli_abort(
9625+
"{.arg cliques} must be a list or NULL",
9626+
call = rlang::caller_env()
9627+
)
9628+
}
95349629
Muc <- as.numeric(Muc)
95359630
startMu <- as.logical(startMu)
95369631
niter <- as.numeric(niter)
@@ -9541,7 +9636,7 @@ graphlets_project_impl <- function(
95419636
R_igraph_graphlets_project,
95429637
graph,
95439638
weights,
9544-
lapply(cliques, function(.x) .x - 1),
9639+
if (!is.null(cliques)) lapply(cliques, function(.x) .x - 1),
95459640
Muc,
95469641
startMu,
95479642
niter
@@ -10777,14 +10872,20 @@ local_scan_neighborhood_ecount_impl <- function(
1077710872
} else {
1077810873
weights <- NULL
1077910874
}
10875+
if (!is.null(neighborhoods) && !is.list(neighborhoods)) {
10876+
cli::cli_abort(
10877+
"{.arg neighborhoods} must be a list or NULL",
10878+
call = rlang::caller_env()
10879+
)
10880+
}
1078010881

1078110882
on.exit(.Call(R_igraph_finalizer))
1078210883
# Function call
1078310884
res <- .Call(
1078410885
R_igraph_local_scan_neighborhood_ecount,
1078510886
graph,
1078610887
weights,
10787-
lapply(neighborhoods, function(.x) .x - 1)
10888+
if (!is.null(neighborhoods)) lapply(neighborhoods, function(.x) .x - 1)
1078810889
)
1078910890

1079010891
res
@@ -10805,14 +10906,20 @@ local_scan_subset_ecount_impl <- function(
1080510906
} else {
1080610907
weights <- NULL
1080710908
}
10909+
if (!is.null(subsets) && !is.list(subsets)) {
10910+
cli::cli_abort(
10911+
"{.arg subsets} must be a list or NULL",
10912+
call = rlang::caller_env()
10913+
)
10914+
}
1080810915

1080910916
on.exit(.Call(R_igraph_finalizer))
1081010917
# Function call
1081110918
res <- .Call(
1081210919
R_igraph_local_scan_subset_ecount,
1081310920
graph,
1081410921
weights,
10815-
lapply(subsets, function(.x) .x - 1)
10922+
if (!is.null(subsets)) lapply(subsets, function(.x) .x - 1)
1081610923
)
1081710924

1081810925
res
@@ -12652,6 +12759,39 @@ automorphism_group_impl <- function(
1265212759
res
1265312760
}
1265412761

12762+
subisomorphic_lad_impl <- function(
12763+
pattern,
12764+
target,
12765+
domains = NULL,
12766+
induced,
12767+
time_limit
12768+
) {
12769+
# Argument checks
12770+
ensure_igraph(pattern)
12771+
ensure_igraph(target)
12772+
if (!is.null(domains) && !is.list(domains)) {
12773+
cli::cli_abort(
12774+
"{.arg domains} must be a list or NULL",
12775+
call = rlang::caller_env()
12776+
)
12777+
}
12778+
induced <- as.logical(induced)
12779+
time_limit <- as.numeric(time_limit)
12780+
12781+
on.exit(.Call(R_igraph_finalizer))
12782+
# Function call
12783+
res <- .Call(
12784+
R_igraph_subisomorphic_lad,
12785+
pattern,
12786+
target,
12787+
if (!is.null(domains)) lapply(domains, function(.x) .x - 1),
12788+
induced,
12789+
time_limit
12790+
)
12791+
12792+
res
12793+
}
12794+
1265512795
simplify_and_colorize_impl <- function(
1265612796
graph
1265712797
) {
@@ -13051,6 +13191,94 @@ cmp_epsilon_impl <- function(
1305113191
res
1305213192
}
1305313193

13194+
eigen_matrix_impl <- function(
13195+
A,
13196+
sA,
13197+
fun,
13198+
n,
13199+
algorithm,
13200+
which,
13201+
options = arpack_defaults()
13202+
) {
13203+
# Argument checks
13204+
A[] <- as.numeric(A)
13205+
requireNamespace("Matrix", quietly = TRUE)
13206+
sA <- as(as(as(sA, "dMatrix"), "generalMatrix"), "CsparseMatrix")
13207+
n <- as.integer(n)
13208+
algorithm <- switch_igraph_arg(
13209+
algorithm,
13210+
"auto" = 0L,
13211+
"lapack" = 1L,
13212+
"arpack" = 2L,
13213+
"comp_auto" = 3L,
13214+
"comp_lapack" = 4L,
13215+
"comp_arpack" = 5L
13216+
)
13217+
which.tmp <- eigen_defaults()
13218+
which.tmp[names(which)] <- which
13219+
which <- which.tmp
13220+
options <- modify_list(arpack_defaults(), options)
13221+
13222+
on.exit(.Call(R_igraph_finalizer))
13223+
# Function call
13224+
res <- .Call(
13225+
R_igraph_eigen_matrix,
13226+
A,
13227+
sA,
13228+
fun,
13229+
n,
13230+
algorithm,
13231+
which,
13232+
options
13233+
)
13234+
13235+
res
13236+
}
13237+
13238+
eigen_matrix_symmetric_impl <- function(
13239+
A,
13240+
sA,
13241+
fun,
13242+
n,
13243+
algorithm,
13244+
which,
13245+
options = arpack_defaults()
13246+
) {
13247+
# Argument checks
13248+
A[] <- as.numeric(A)
13249+
requireNamespace("Matrix", quietly = TRUE)
13250+
sA <- as(as(as(sA, "dMatrix"), "generalMatrix"), "CsparseMatrix")
13251+
n <- as.integer(n)
13252+
algorithm <- switch_igraph_arg(
13253+
algorithm,
13254+
"auto" = 0L,
13255+
"lapack" = 1L,
13256+
"arpack" = 2L,
13257+
"comp_auto" = 3L,
13258+
"comp_lapack" = 4L,
13259+
"comp_arpack" = 5L
13260+
)
13261+
which.tmp <- eigen_defaults()
13262+
which.tmp[names(which)] <- which
13263+
which <- which.tmp
13264+
options <- modify_list(arpack_defaults(), options)
13265+
13266+
on.exit(.Call(R_igraph_finalizer))
13267+
# Function call
13268+
res <- .Call(
13269+
R_igraph_eigen_matrix_symmetric,
13270+
A,
13271+
sA,
13272+
fun,
13273+
n,
13274+
algorithm,
13275+
which,
13276+
options
13277+
)
13278+
13279+
res
13280+
}
13281+
1305413282
solve_lsap_impl <- function(
1305513283
c,
1305613284
n

R/indexing.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ get_adjacency_submatrix <- function(x, i, j, attr = NULL) {
215215
sparse = igraph_opt("sparsematrices"),
216216
edges = FALSE,
217217
drop = TRUE,
218-
attr = if (is_weighted(x)) "weight" else NULL
218+
attr = if (is_weighted(x)) "weight"
219219
) {
220220
################################################################
221221
## Argument checks
@@ -457,7 +457,7 @@ expand.grid.unordered <- function(i, j, loops = FALSE, directed = FALSE) {
457457
...,
458458
from,
459459
to,
460-
attr = if (is_weighted(x)) "weight" else NULL,
460+
attr = if (is_weighted(x)) "weight",
461461
loops = FALSE,
462462
value
463463
) {

R/iterators.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ parse_op_args <- function(..., what, is_fun, as_fun, check_graph = TRUE) {
16671667
)
16681668
}
16691669

1670-
graph <- if (length(graphs)) graphs[[1]] else NULL
1670+
graph <- if (length(graphs)) graphs[[1]]
16711671

16721672
args <- lapply(args, unclass)
16731673

man/sub-.igraph.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)