Skip to content

Commit fba3690

Browse files
committed
DGraph: Fixups for vertex element types
1 parent 30093f2 commit fba3690

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

lib/DaggerGraphs/src/DaggerGraphs.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,4 @@ include("edgeiter.jl")
1515
include("io.jl")
1616
include("tables.jl")
1717

18-
function DGraph{T}(x; kwargs...) where T
19-
if Tables.istable(x)
20-
return fromtable(T, x; kwargs...)
21-
end
22-
throw(ArgumentError("Cannot convert a $(typeof(x)) to a DGraph"))
23-
end
24-
DGraph(x; kwargs...) = DGraph{Int}(x; kwargs...)
25-
2618
end # module DaggerGraphs

lib/DaggerGraphs/src/dgraph.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,20 @@ mutable struct DGraph{T<:Integer, D} <: Graphs.AbstractGraph{T}
8686
return new{T,D}(Dagger.tochunk(state), Ref(false))
8787
end
8888
end
89+
DGraph(x; kwargs...) = DGraph{Int}(x; kwargs...)
8990
DGraph(; kwargs...) = DGraph{Int}(; kwargs...)
90-
function DGraph(n::T; freeze::Bool=false, kwargs...) where {T<:Integer}
91+
DGraph{T}(n::S; kwargs...) where {T<:Integer,S<:Integer} =
92+
DGraph{T}(T(n); kwargs...)
93+
function DGraph{T}(n::T; freeze::Bool=false, kwargs...) where {T<:Integer}
9194
g = DGraph{T}(; kwargs...)
9295
add_vertices!(g, n)
9396
freeze && freeze!(g)
9497
return g
9598
end
96-
function DGraph(sg::AbstractGraph{T}; directed::Bool=is_directed(sg), freeze::Bool=false, kwargs...) where {T<:Integer}
97-
g = DGraph(nv(sg); directed, kwargs...)
99+
function DGraph{T}(sg::AbstractGraph{T}; directed::Bool=is_directed(sg), freeze::Bool=false, kwargs...) where {T<:Integer}
100+
g = DGraph{T}(nv(sg); directed, kwargs...)
98101
foreach(edges(sg)) do edge
102+
99103
add_edge!(g, edge)
100104
if !is_directed(sg) && directed
101105
add_edge!(g, dst(edge), src(edge))
@@ -104,7 +108,7 @@ function DGraph(sg::AbstractGraph{T}; directed::Bool=is_directed(sg), freeze::Bo
104108
freeze && freeze!(g)
105109
return g
106110
end
107-
function DGraph(dg::DGraph{T,D}; chunksize::T=0, directed::Bool=D, freeze::Bool=false) where {T<:Integer, D}
111+
function DGraph{T}(dg::DGraph{T,D}; chunksize::T=0, directed::Bool=D, freeze::Bool=false) where {T<:Integer, D}
108112
state = fetch(dg.state)
109113
# FIXME: Create g.state on same node as dg.state
110114
if chunksize == 0
@@ -480,11 +484,11 @@ nparts(g::DGraphState) = length(g.parts)
480484
Base.eltype(::DGraph{T}) where T = T
481485
Graphs.edgetype(::DGraph{T}) where T = Edge{T}
482486
Graphs.nv(g::DGraph{T}) where T <: Integer = with_state(g, nv)::T
483-
function Graphs.nv(g::DGraphState)
487+
function Graphs.nv(g::DGraphState{T}) where T
484488
if !isempty(g.parts_nv)
485-
return Int(last(g.parts_nv).stop)
489+
return T(last(g.parts_nv).stop)
486490
else
487-
return 0
491+
return zero(T)
488492
end
489493
end
490494
Graphs.ne(g::DGraph) = with_state(g, ne)::Int
@@ -577,7 +581,7 @@ end
577581
578582
Add a partition of `n` vertices to the graph state `g`.
579583
"""
580-
function add_partition!(g::DGraphState{T,D}, n::T) where {T <: Integer, D}
584+
function add_partition!(g::DGraphState{T,D}, n::Integer) where {T <: Integer, D}
581585
check_not_frozen(g)
582586
if n < 1
583587
throw(ArgumentError("n must be >= 1"))

0 commit comments

Comments
 (0)