MetaGraphsNext.jl
MetaGraphsNext.jl copied to clipboard
Empty constructor to initialize Metagraphsnext
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:
- With MetaGraphs (working)
using MetaGraphs
mg1 = MetaGraph()
- 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()
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()
.
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
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 ?
That sounds reasonable, but then again depending on the underlying graph type the constructor G()
may not even exist.