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 · 1 comment
Open

SimpleGraph(::Base.OneTo) #365

mtfishman opened this issue Apr 19, 2024 · 1 comment
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
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

2 participants