Skip to content

SimpleGraph(::Base.OneTo) #365

Open
Open
@mtfishman

Description

@mtfishman

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions