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

SimpleGraph(::Base.OneTo) #365

Open
mtfishman opened this issue Apr 19, 2024 · 5 comments
Open

SimpleGraph(::Base.OneTo) #365

mtfishman opened this issue Apr 19, 2024 · 5 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@mtfishman
Copy link
Contributor

I think it would be helpful to add constructors:

SimpleGraph(Base.OneTo(4)) == SimpleGraph(4)
SimpleDiGraph(Base.OneTo(4)) == SimpleDiGraph(4)

representing the more general concept of constructing a graph from a set of vertices. It would enable writing generic code like:

rem_all_edges(g::AbstractGraph) = typeof(g)(vertices(g))

which would work with graphs that don't have simple vertices.

This is analogous to constructing Julia arrays from axes:

julia> zeros(Base.OneTo(3), Base.OneTo(3))
3×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

(though for whatever reason Matrix{Float64}(undef, (Base.OneTo(3), Base.OneTo(3))) doesn't work).

@gdalle
Copy link
Member

gdalle commented Apr 22, 2024

While this makes sense for SimpleGraphs, the method you defined for general graphs would not be guaranteed to work in general. Typically, there are some graphs that cannot exist without edges (think grids) so the constructor would fail.

@gdalle gdalle added enhancement New feature or request wontfix This will not be worked on labels May 4, 2024
@simonschoelly
Copy link
Member

Adding this will make the big list of SimpleGraph constructors even bigger - and makes looking at the documentation more complicated.

@mtfishman If you don't strongly object I will close this as wontfix for now.

@mtfishman
Copy link
Contributor Author

Obviously up to you, I would still like this kind of interface, however I suppose it could be implemented through an orthogonal interface outside of constructors, such as similar(SimpleGraph, Base.OneTo(4)) which could then be generalized to other graph types. (similar may not be the best name, I'm just using it as a stand-in name.)

@simonschoelly
Copy link
Member

In that case lets keep the issue open for now.

@mtfishman
Copy link
Contributor Author

While this makes sense for SimpleGraphs, the method you defined for general graphs would not be guaranteed to work in general. Typically, there are some graphs that cannot exist without edges (think grids) so the constructor would fail.

That's fair, that was just a random example, but the more general concept is that it would be nice to have a more general interface, either through constructors or otherwise, for constructing a graph from a set of vertices rather than just the number of vertices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants