diff --git a/docs/src/ecosystem/interface.md b/docs/src/ecosystem/interface.md index 808ba3893..9df171dca 100644 --- a/docs/src/ecosystem/interface.md +++ b/docs/src/ecosystem/interface.md @@ -5,7 +5,6 @@ This section is designed to guide developers who wish to write their own graph s All Graphs.jl functions rely on a standard API to function. As long as your graph structure is a subtype of [`AbstractGraph`](@ref) and implements the following API functions with the given return values, all functions within the Graphs.jl package should just work: - [`edges`](@ref) -- [Base.eltype](https://docs.julialang.org/en/latest/base/collections/#Base.eltype) - [`edgetype`](@ref) (example: `edgetype(g::CustomGraph) = Graphs.SimpleEdge{eltype(g)})`) - [`has_edge`](@ref) - [`has_vertex`](@ref) diff --git a/src/SimpleGraphs/simpledigraph.jl b/src/SimpleGraphs/simpledigraph.jl index 606871eb9..efd517c5f 100644 --- a/src/SimpleGraphs/simpledigraph.jl +++ b/src/SimpleGraphs/simpledigraph.jl @@ -24,7 +24,6 @@ function SimpleDiGraph( return SimpleDiGraph{T}(ne, fadjlist, badjlist) end -eltype(x::SimpleDiGraph{T}) where {T} = T # DiGraph{UInt8}(6), DiGraph{Int16}(7), DiGraph{Int8}() """ diff --git a/src/SimpleGraphs/simplegraph.jl b/src/SimpleGraphs/simplegraph.jl index a261cf51a..359c39935 100644 --- a/src/SimpleGraphs/simplegraph.jl +++ b/src/SimpleGraphs/simplegraph.jl @@ -19,8 +19,6 @@ function SimpleGraph(ne, fadjlist::Vector{Vector{T}}) where {T} return SimpleGraph{T}(ne, fadjlist) end -eltype(x::SimpleGraph{T}) where {T} = T - # Graph{UInt8}(6), Graph{Int16}(7), Graph{UInt8}() """ SimpleGraph{T}(n=0) diff --git a/src/Test/Test.jl b/src/Test/Test.jl index c8ac6194d..3a9db112d 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -49,9 +49,6 @@ end Graphs.is_directed(::Type{<:GenericGraph}) = false Graphs.is_directed(::Type{<:GenericDiGraph}) = true -Base.eltype(g::GenericGraph) = eltype(g.g) -Base.eltype(g::GenericDiGraph) = eltype(g.g) - Graphs.edges(g::GenericGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) Graphs.edges(g::GenericDiGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) diff --git a/src/interface.jl b/src/interface.jl index 1472cd9a1..0cc3239da 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -118,11 +118,11 @@ Return the type of graph `g`'s edge edgetype(g::AbstractGraph) = _NI("edgetype") """ - eltype(g) + eltype(G) Return the type of the graph's vertices (must be <: Integer) """ -eltype(g::AbstractGraph) = _NI("eltype") +eltype(::Type{<:AbstractGraph{T}}) where {T} = T """ nv(g) diff --git a/src/linalg/nonbacktracking.jl b/src/linalg/nonbacktracking.jl index 58cf051e8..ec88a59f7 100644 --- a/src/linalg/nonbacktracking.jl +++ b/src/linalg/nonbacktracking.jl @@ -85,7 +85,7 @@ end size(nbt::Nonbacktracking) = (nbt.m, nbt.m) size(nbt::Nonbacktracking, i::Number) = size(nbt)[i] -eltype(nbt::Nonbacktracking) = Float64 +eltype(::Type{<:Nonbacktracking}) = Float64 issymmetric(nbt::Nonbacktracking) = false function *(nbt::Nonbacktracking, x::Vector{T}) where {T<:Number} diff --git a/test/interface.jl b/test/interface.jl index 6219ea16b..bd5e197fc 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -18,7 +18,7 @@ mutable struct DummyEdge <: AbstractEdge{Int} end @test_throws Graphs.NotImplementedError edgefun2edges(dummyedge, dummyedge) end - for graphfunbasic in [nv, ne, vertices, edges, is_directed, edgetype, eltype] + for graphfunbasic in [nv, ne, vertices, edges, is_directed, edgetype] @test_throws Graphs.NotImplementedError graphfunbasic(dummygraph) end diff --git a/test/linalg/spectral.jl b/test/linalg/spectral.jl index 505f8a958..7ea595fcf 100644 --- a/test/linalg/spectral.jl +++ b/test/linalg/spectral.jl @@ -61,6 +61,7 @@ Matrix(nbt::Nonbacktracking) = Matrix(sparse(nbt)) @test size(n10, 1) == n10.m @test size(n10, 2) == n10.m @test eltype(n10) == Float64 + @test eltype(typeof(n10)) == Float64 @test !issymmetric(n10) contract!(z, n10, v) diff --git a/test/simplegraphs/simplegraphs.jl b/test/simplegraphs/simplegraphs.jl index 6d13e62ef..afbff2dec 100644 --- a/test/simplegraphs/simplegraphs.jl +++ b/test/simplegraphs/simplegraphs.jl @@ -89,7 +89,7 @@ using Random: Random T = @inferred(eltype(g)) @test @inferred(nv(SimpleGraph{T}(6))) == 6 - @test @inferred(eltype(SimpleGraph(T))) == T + @test @inferred(eltype(SimpleGraph{T})) == T @test @inferred(eltype(SimpleGraph{T}(adjmx1))) == T ga = SimpleGraph(10) @@ -156,7 +156,7 @@ using Random: Random T = @inferred(eltype(g)) @test @inferred(nv(SimpleDiGraph{T}(6))) == 6 - @test @inferred(eltype(SimpleDiGraph(T))) == T + @test @inferred(eltype(SimpleDiGraph{T})) == T @test @inferred(eltype(SimpleDiGraph{T}(adjmx2))) == T ga = SimpleDiGraph(10) @@ -271,7 +271,7 @@ using Random: Random edge_set_any = Set{Any}(edge_list) g1 = @inferred SimpleDiGraph(edge_list) - # we can't infer the return type of SimpleDiGraphFromIterator at the moment + # we can't infer the return type of SimpleDiGraphFromIterator at the moment g2 = SimpleDiGraphFromIterator(edge_list) g3 = SimpleDiGraphFromIterator(edge_iter) g4 = SimpleDiGraphFromIterator(edge_set) @@ -312,7 +312,7 @@ using Random: Random )) end - # check if multiple edges && multiple self-loops result in the + # check if multiple edges && multiple self-loops result in the # correct number of edges & vertices # edges using integers < 1 should be ignored g_undir = SimpleGraph(0)