Skip to content

Support of copy constructors? #96

Open

Description

@rongcuid

I have a graph which I would like to copy and change one aspect of it (e.g. weight function). However, it seems like MetaGraph doesn't have a copy constructor:

MetaGraph(graph)
# UndefKeywordError: keyword argument `label_type` not assigned

It would be great if something like that is added. Or alternatively, provide a way to create different views of the same graph with different properties.

Activity

  1. gdalle commented on Oct 13, 2025

    @gdalle
    Member

    Can you just use deepcopy?

  2. Krastanov commented on Oct 13, 2025

    @Krastanov
    Member

    deepcopy is a reasonable workaround, but just wanted to leave this warning here, about deepcopy being discouraged in production-level / library code: JuliaLang/julia#58416 (so we should probably leave this issue open)

  3. rongcuid commented on Oct 13, 2025

    @rongcuid
    Author

    Accessors.jl works so far, though I am not sure if I should rely on knowing the internal representation of the MetaGraph struct.

  4. rafaqz commented on Oct 14, 2025

    @rafaqz

    It's probably good for the graphs ecosystem to commit to ConstructionBase.constructorof always working on graph objects. It will mostly work already as you found with Accessors.jl (that uses it under the hood), but where arguments and type parameters are unusual it may need a method added. ConstructionBase.jl is a small dependency and usually in your deps anyway.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions