Skip to content

Expose igraph_product() #1908

Open
Open

Description

@szhorvat

@gulshan-123 implemented a graph product feature in the C core as igraph_product(). It would be great to expose this in R/igraph. Two product types are already released and two more will land soon.

https://igraph.org/c/html/latest/igraph-Operators.html#igraph_product

@schochastics, what do you think a nice interface could be for this? Do we want an operator like * or %*% for the classic Cartesian product, or do we restrict this to a plain function? Other graph operators, such as union, have operators such as %u%.

For the explicit function, what's a better name? Just product() (risk of collision, but short) or graph_product()?

Activity

  1. added
    expose 🏖️
    on Jul 1, 2025
  2. schochastics commented on Jul 2, 2025

    @schochastics
    Contributor

    I think product() might be fine because we also have union() . I also think an operator would be good to have but then separate ones for cartesian/tensor with "%"?
    But @maelle is better at naming things than me!

  3. maelle commented on Jul 3, 2025

    @maelle
    Contributor

    Sounds good to me.

  4. szhorvat commented on Jul 3, 2025

    @szhorvat
    MemberAuthor

    Perhaps this operation is just not common enough to introduce an operator form for it. If one introduced, I would only do it for the Cartesian product, which is the classic graph product concept, and which is set as the default in interfaces.yaml.

  5. schochastics commented on Jul 3, 2025

    @schochastics
    Contributor

    Then maybe no operator. You are right, I don't think that the function is common enough that a shortcut is needed

  6. szhorvat commented on Jul 3, 2025

    @szhorvat
    MemberAuthor

    If the graphs have vertex names, it'd be nice to auto-generate names for the product as well. For example if graph 1 has vertices A and B, and graph 2 has 3 vertices but no vertex names, the result graph could have names

    A-1
    A-2
    A-3
    B-1
    B-2
    B-3
    

    Here I used - as the concatenation character. What this should be is up for debate.

  7. schochastics commented on Jul 4, 2025

    @schochastics
    Contributor

    I have an R implementation of products here: https://github.com/schochastics/netUtils/blob/main/R/graph_products.R and I also used "-". I think it makes the most sense. The problem with autogenerating names is also touching #1932. From a consistency point, throwing an error should be correct? Or we decide on a general naming scheme for unnamed graphs. In that case I would vote for "V1..Vn". Up to debate

  8. szhorvat commented on Aug 6, 2025

    @szhorvat
    MemberAuthor

    There's now a separate function for yet another product type that requires an extra parameter: igraph_rooted_product(). I would recommend using the same function in the R interface, with an extra argument that is valid only for this product.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    expose 🏖️

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions