ITensor / ITensor/NamedGraphs.jl
`similar` for generically constructing graphs of the same/similar type without edges
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 10
- Forks
- 5
- Avg merge
- 6h 43m
- Merged PRs (30d)
- 17
Description
Graphs.jl doesn't seem to provide a generic interface for creating graphs of the same type without any edges, and possibly with new vertices.
The closest concept in Julia seems to be Base.similar, for example for sparse arrays:
julia> using SparseArrays
julia> A = sprandn(4, 4, 0.5)
4×4 SparseMatrixCSC{Float64, Int64} with 7 stored entries:
⋅ ⋅ ⋅ ⋅
-0.21712 ⋅ -0.741368 0.199437
⋅ ⋅ ⋅ 1.78635
0.486078 ⋅ 0.593271 -0.199654
julia> similar(A, 4, 4)
4×4 SparseMatrixCSC{Float64, Int64} with 0 stored entries:
⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅
though for some reason it doesn't work for types:
julia> similar(typeof(A), 4, 4)
ERROR: MethodError: no method matching SparseMatrixCSC{Float64, Int64}(::UndefInitializer, ::Tuple{Int64, Int64})
Closest candidates are:
SparseMatrixCSC{Tv, Ti}(::LinearAlgebra.UniformScaling, ::Tuple{Int64, Int64}) where {Tv, Ti} at /Applications/Julia-1.8.5.app/Contents/Resources/julia/share/julia/stdlib/v1.8/SparseArrays/src/sparsematrix.jl:1788
Stacktrace:
[1] similar(#unused#::Type{SparseMatrixCSC{Float64, Int64}}, dims::Tuple{Int64, Int64})
@ Base ./abstractarray.jl:841
[2] similar(::Type{SparseMatrixCSC{Float64, Int64}}, ::Int64, ::Int64)
@ Base ./abstractarray.jl:839
[3] top-level scope
@ REPL[20]:1
We could adopt the interface:
Base.similar(g::AbstractGraph, vertices)
Base.similar(g::AbstractGraph, nvertices::Integer)
Base.similar(G::Type{<:AbstractGraph}, vertices)
Base.similar(G::Type{<:AbstractGraph}, nvertices::Integer)
as a way to generically create a graph of the same type G without any edges with either the specified vertex collection or number of vertices. Additionally this could be used as an interface for creating a similar graph with a new vertex type, and new vertex data and edge data types in the case of data graphs.
Originally posted by @mtfishman in https://github.com/mtfishman/NamedGraphs.jl/pull/32#discussion_r1105037874
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation file or test. Start by reviewing the AbstractGraph and Base.similar interfaces in Graphs.jl and NamedGraphs.jl, then determine the supported vertex and data-type forms. Done means an edge-free graph of the requested type can be constructed from either a vertex collection or vertex count, with tests covering the agreed interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100