Skip to content

Commit a788d99

Browse files
Copilotkrlmlr
andcommitted
refactor: move optional VERTEX subtraction to INCONV block
Move the `- 1` subtraction for optional VERTEX parameters from .Call() into the INCONV block (inside the NULL check) as requested by @maelle. This improves code clarity by keeping all parameter transformations together. Changes: - Modified Stimulus R generator to add subtraction inside optional_wrapper_r for VERTEX type - Updated CALL handling to pass VERTEX name directly for optional parameters - Regenerated R/aaa-auto.R with cleaner code structure Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
1 parent edbb220 commit a788d99

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

R/aaa-auto.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9730,6 +9730,7 @@ fundamental_cycles_impl <- function(
97309730
call = rlang::caller_env()
97319731
)
97329732
}
9733+
start <- start - 1
97339734
}
97349735
bfs_cutoff <- as.numeric(bfs_cutoff)
97359736
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
@@ -9746,7 +9747,8 @@ fundamental_cycles_impl <- function(
97469747
res <- .Call(
97479748
R_igraph_fundamental_cycles,
97489749
graph,
9749-
if (!is.null(start)) start - 1 else NULL, bfs_cutoff,
9750+
start,
9751+
bfs_cutoff,
97509752
weights
97519753
)
97529754
if (igraph_opt("return.vs.es")) {
@@ -9982,14 +9984,15 @@ random_spanning_tree_impl <- function(
99829984
call = rlang::caller_env()
99839985
)
99849986
}
9987+
vid <- vid - 1
99859988
}
99869989

99879990
on.exit(.Call(R_igraph_finalizer))
99889991
# Function call
99899992
res <- .Call(
99909993
R_igraph_random_spanning_tree,
99919994
graph,
9992-
if (!is.null(vid)) vid - 1 else NULL
9995+
vid
99939996
)
99949997
if (igraph_opt("return.vs.es")) {
99959998
res <- create_es(graph, res)
@@ -10315,6 +10318,7 @@ vertex_path_from_edge_path_impl <- function(
1031510318
call = rlang::caller_env()
1031610319
)
1031710320
}
10321+
start <- start - 1
1031810322
}
1031910323
edge_path <- as_igraph_es(graph, edge_path)
1032010324
mode <- switch_igraph_arg(
@@ -10330,7 +10334,8 @@ vertex_path_from_edge_path_impl <- function(
1033010334
res <- .Call(
1033110335
R_igraph_vertex_path_from_edge_path,
1033210336
graph,
10333-
if (!is.null(start)) start - 1 else NULL, edge_path - 1,
10337+
start,
10338+
edge_path - 1,
1033410339
mode
1033510340
)
1033610341
if (igraph_opt("return.vs.es")) {

tools/py-stimulus/src/stimulus/generators/r.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,15 @@ def handle_argument_check(param: ParamSpec) -> str:
255255

256256
if param.is_optional and param.is_input and res:
257257
res = optional_wrapper_r(res)
258-
258+
# For optional VERTEX parameters, add the subtraction inside the NULL check
259+
if param.type == "VERTEX":
260+
# Add the subtraction at the end of the wrapped block
261+
name = get_r_parameter_name(param)
262+
res = res.rstrip()
263+
if res.endswith("}"):
264+
# Insert before the closing brace
265+
res = res[:-1] + f" {name} <- {name} - 1\n}}"
266+
259267
# Replace template placeholders
260268
res = indent(res).replace("%I%", get_r_parameter_name(param))
261269
for i, dep in enumerate(param.dependencies):
@@ -299,9 +307,13 @@ def handle_argument_check(param: ParamSpec) -> str:
299307
name = get_r_parameter_name(param)
300308
call = type.get("CALL", name)
301309
if call:
302-
call_formatted = call.replace("%I%", name)
303-
# Add spaces around arithmetic operators
304-
call_formatted = re.sub(r'(\w+)(\+|\-|\*|/)(\d+)', r'\1 \2 \3', call_formatted)
310+
# For optional VERTEX parameters, subtraction is done in INCONV, so just use the name
311+
if param.is_optional and param.type == "VERTEX":
312+
call_formatted = name
313+
else:
314+
call_formatted = call.replace("%I%", name)
315+
# Add spaces around arithmetic operators
316+
call_formatted = re.sub(r'(\w+)(\+|\-|\*|/)(\d+)', r'\1 \2 \3', call_formatted)
305317
parts.append(call_formatted)
306318

307319
# Format .Call() as multi-line with each argument on its own line

0 commit comments

Comments
 (0)