Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty constructor to initialize Metagraphsnext #65

Open
harinandana02 opened this issue Sep 4, 2023 · 4 comments
Open

Empty constructor to initialize Metagraphsnext #65

harinandana02 opened this issue Sep 4, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@harinandana02
Copy link

harinandana02 commented Sep 4, 2023

At the moment MetaGraphs.jl/src/metagraphs.jl has an empty constructor which can be used to implement empty graphs. Also, the package Graphs.jl has empty constructors.

Similarly, can we have an empty constructor at MetaGraphsNext.jl/src/metagraphs.jl for constructing empty graphs of type MetagraphsNext?

Sample code:

  1. With MetaGraphs (working)
using MetaGraphs
     mg1 = MetaGraph() 
  1. With MetaGraphsNext (requesting review)
using MetaGraphsNext
         #adding an empty constructor
          MetaGraph() = MetaGraph{Int, SimpleGraph{Int}, Symbol, Nothing, Nothing, Nothing, e->1.0, Float64}()

With the help of this constructor we can initialize

using MetaGraphsNext
     mg2 = MetaGraph() 
@filchristou
Copy link
Contributor

I think the problem is that MetaGraph{Int, SimpleGraph{Int}, Symbol, Nothing, Nothing, Nothing, e->1.0, Float64}() will not work. So the empty constructor should be defined in these terms. In that regard I am in favor.

However, having MetaGraph() defaulting into SimpleGraph I don't find it completely necessary. Although you could easily argue in favor of that. After all in Graphs.jl, Graph() will similarly default in SimpleGraph().

@gdalle
Copy link
Member

gdalle commented Sep 5, 2023

Thank you for the suggestion! However I don't think such an empty constructor is a good idea, because default vertex and edge data types are very arbitrary, and the user may not be aware of those choices

@filchristou
Copy link
Contributor

filchristou commented Sep 5, 2023

What about MetaGraph{Int, SimpleGraph{Int}, Symbol, Nothing, Nothing, Nothing}(), which currently fails ? I think this empty constructor of the parametrized struct shouldn't fail.

e.g. we could define the following constructor

function MetaGraph{C, G, L, VD, ED, GD}() where {C<:Integer, G<:AbstractGraph{C}, L, VD, ED, GD}
  return MetaGraph(G(), L, VD, ED, GD)
end

My personal use case is that I want to make an empty copy of a graph. But I would like that to be consistent with all AbstractGraphs. I thought about empty constructors, but that might not go very far.
E.g. for now I have been doing typeof(mygraph)(), which feels hacky and it breaks for MetaGraphsNext.
Maybe it's an issue for GraphBase to define such an interface if nothing similar exists ?

@gdalle
Copy link
Member

gdalle commented Sep 6, 2023

That sounds reasonable, but then again depending on the underlying graph type the constructor G() may not even exist.

@gdalle gdalle added the enhancement New feature or request label Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants