Skip to content

feat: Add attribute combination support to graph operators#2676

Open
schochastics wants to merge 9 commits into
mainfrom
feat-attrib_comb
Open

feat: Add attribute combination support to graph operators#2676
schochastics wants to merge 9 commits into
mainfrom
feat-attrib_comb

Conversation

@schochastics

Copy link
Copy Markdown
Contributor

fix #57

@schochastics

Copy link
Copy Markdown
Contributor Author

devtools::document() doesnt work locally for me

Comment thread tests/testthat/test-operators.R Outdated
Comment on lines +1317 to +1325
make_named_pair <- function() {
g1 <- graph_from_literal(A - B, B - C, C - A)
g2 <- graph_from_literal(A - B, B - C, C - A)
V(g1)$weight <- c(1, 2, 3)
V(g2)$weight <- c(10, 20, 30)
E(g1)$weight <- c(1, 2, 3)
E(g2)$weight <- c(10, 20, 30)
list(g1 = g1, g2 = g2)
}

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.

Move to helper or a proper R/ function?

Comment thread R/attributes.R
#############

igraph.i.attribute.combination <- function(comb) {
igraph.i.attribute.combination <- function(comb, allow_rename = FALSE) {

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.

Split into two functions, one for a scalar, and the list function as a simple wrapper?

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.

Maybe not.

Comment thread R/operators.R
default_comb <- if (length(default_idx) > 0) {
comb[[default_idx[1]]]
} else {
"rename"

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.

Suggested change
"rename"
# Backward-compatible standard
"rename"

Comment thread R/operators.R Outdated
#' print_all(g1 %du% g2)
#' @export
disjoint_union <- function(...) {
disjoint_union <- function(..., graph.attr.comb = "rename") {

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.

Suggested change
disjoint_union <- function(..., graph.attr.comb = "rename") {
disjoint_union <- function(..., graph_attr_comb = "rename") {

and clean up edge.attr.comb ? Think harder about naming, but the names already are long enough.

Comment thread R/operators.R
###################################################################

rename.attr.if.needed <- function(
combine.attrs <- function(

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.

Keep rename_attr_if_needed() and use it only for those attributes where the action is "rename"?

@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if c26ab02 is merged into main:

  • ✔️as_adjacency_matrix: 777ms -> 779ms [-0.27%, +0.78%]
  • ✔️as_biadjacency_matrix: 777ms -> 779ms [-0.47%, +1.17%]
  • ✔️as_data_frame_both: 1.61ms -> 1.59ms [-2.88%, +1.5%]
  • ✔️as_long_data_frame: 4ms -> 4ms [-1.29%, +1.34%]
  • ✔️es_attr_filter: 2.8ms -> 2.82ms [-1.01%, +2.48%]
  • ✔️graph_from_adjacency_matrix: 147ms -> 148ms [-0.73%, +1.43%]
  • ✔️graph_from_data_frame: 3.56ms -> 3.56ms [-1.83%, +1.32%]
  • ✔️vs_attr_filter: 1.65ms -> 1.63ms [-3.3%, +0.25%]
  • ✔️vs_by_name: 1.06ms -> 1.06ms [-2.31%, +2.11%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@igraph igraph deleted a comment from github-actions Bot Jun 10, 2026
schochastics and others added 3 commits June 10, 2026 12:27
…lper

Address review feedback on #2676:
- Rename the new graph.attr.comb/vertex.attr.comb/edge.attr.comb arguments of
  union()/intersection()/compose()/disjoint_union() to snake_case (these args
  are new in this PR, so no deprecation is needed).
- Extract rename_attr_if_needed() back out of combine.attrs() for the "rename"
  strategy, preserving the historical overwrite-on-clash semantics under chains
  of %du%.
- Add a clarifying comment on the backward-compatible "rename" default.
- Move the make_named_pair() test helper into helper.R.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tted names

Follow-up to review feedback on #2676 ("clean up edge.attr.comb"):

- simplify(), as_undirected() and contract() gain snake_case
  edge_attr_comb / vertex_attr_comb arguments via the argument-migration
  infrastructure (tools/migrations.R). The old dotted names still work and
  emit a single lifecycle::deprecate_soft() warning.
- Rename the matching igraph option keys edge.attr.comb -> edge_attr_comb and
  vertex.attr.comb -> vertex_attr_comb, with back-compatible aliasing in
  igraph_opt()/igraph_options(); the dotted keys still read and set, soft-
  deprecated. Update the stimulus codegen default (types-RR.yaml) and the
  regenerated *_impl defaults to match.

Deprecated wrappers (as.undirected(), contract.vertices()) are left frozen;
their snapshot now records the resulting layered deprecation warnings.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if b58da44 is merged into main:

  • ✔️as_adjacency_matrix: 731ms -> 728ms [-1.46%, +0.89%]
  • ✔️as_biadjacency_matrix: 735ms -> 740ms [-0.52%, +1.76%]
  • ✔️as_data_frame_both: 1.51ms -> 1.5ms [-2.15%, +1.45%]
  • ✔️as_long_data_frame: 4.06ms -> 4.05ms [-3.39%, +2.93%]
  • ✔️es_attr_filter: 2.9ms -> 2.93ms [-3.59%, +5.69%]
  • ✔️graph_from_adjacency_matrix: 118ms -> 119ms [-0.35%, +2.21%]
  • ✔️graph_from_data_frame: 3.54ms -> 3.58ms [-1.51%, +4.05%]
  • ✔️vs_attr_filter: 1.66ms -> 1.66ms [-2.81%, +3.13%]
  • ✔️vs_by_name: 1.05ms -> 1.09ms [-4.13%, +11.57%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Comment thread R/par.R
Comment on lines +64 to +65
"vertex_attr_comb" = list(name = "concat", "ignore"),
"edge_attr_comb" = list(weight = "sum", name = "concat", "ignore"),

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.

"graph_attr_comb" missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

R: API for combining attributes from different graphs

2 participants