@@ -86,8 +86,9 @@ mutable struct DGraph{T<:Integer, D} <: Graphs.AbstractGraph{T}
8686 return new {T,D} (Dagger. tochunk (state), Ref (false ))
8787 end
8888end
89- DGraph (x; kwargs... ) = DGraph {Int} (x; kwargs... )
9089DGraph (; kwargs... ) = DGraph {Int} (; kwargs... )
90+ DGraph (x:: T ; kwargs... ) where {T<: Integer } = DGraph {T} (x; kwargs... )
91+ DGraph (x:: AbstractGraph{T} ; kwargs... ) where {T<: Integer } = DGraph {T} (x; kwargs... )
9192DGraph {T} (n:: S ; kwargs... ) where {T<: Integer ,S<: Integer } =
9293 DGraph {T} (T (n); kwargs... )
9394function DGraph {T} (n:: T ; freeze:: Bool = false , kwargs... ) where {T<: Integer }
@@ -96,13 +97,13 @@ function DGraph{T}(n::T; freeze::Bool=false, kwargs...) where {T<:Integer}
9697 freeze && freeze! (g)
9798 return g
9899end
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... )
100+ function DGraph {T} (sg:: AbstractGraph{U } ; directed:: Bool = is_directed (sg), freeze:: Bool = false , kwargs... ) where {T<: Integer , U <: Integer }
101+ g = DGraph {T} (T ( nv (sg) ); directed, kwargs... )
101102 foreach (edges (sg)) do edge
102-
103- add_edge! (g, edge )
103+ edge_conv = Edge ( T ( src (edge)), T ( dst (edge)))
104+ add_edge! (g, edge_conv )
104105 if ! is_directed (sg) && directed
105- add_edge! (g, dst (edge ), src (edge ))
106+ add_edge! (g, dst (edge_conv ), src (edge_conv ))
106107 end
107108 end
108109 freeze && freeze! (g)
@@ -221,7 +222,7 @@ function freeze!(g::DGraphState)
221222 return false
222223 end
223224 g. frozen[] = true
224- for part in nparts (g)
225+ for part in 1 : nparts (g)
225226 if Dagger. istask (g. parts[part])
226227 g. parts[part] = fetch (g. parts[part]; raw= true )
227228 end
@@ -516,6 +517,9 @@ function Graphs.has_edge(g::DGraphState{T,D}, src::Integer, dst::Integer) where
516517 end
517518end
518519Graphs. is_directed (:: DGraph{T,D} ) where {T,D} = D
520+ Graphs. is_directed (:: Type{<:DGraph{T,D}} ) where {T,D} = D
521+ Graphs. is_directed (:: DGraphState{T,D} ) where {T,D} = D
522+ Graphs. is_directed (:: Type{<:DGraphState{T,D}} ) where {T,D} = D
519523Graphs. vertices (g:: DGraph{T} ) where T = Base. OneTo {T} (nv (g))
520524Graphs. edges (g:: DGraph ) = DGraphEdgeIter (g)
521525
@@ -663,30 +667,30 @@ function add_partition!(g::DGraphState{T,D}, part_data::Ref, back_data::Ref,
663667 push! (g. bg_adjs_e_meta, back_edge_meta_data[])
664668 return length (g. parts)
665669end
666- function Graphs. add_edge! (g:: DGraph , src:: Integer , dst:: Integer )
670+ function Graphs. add_edge! (g:: DGraph{T} , src:: Integer , dst:: Integer ) where T
667671 check_not_frozen (g)
668- return with_state (g, add_edge!, src, dst)
672+ return with_state (g, add_edge!, T ( src), T ( dst) )
669673end
670- function Graphs. add_edge! (g:: DGraph , edge:: Edge )
674+ function Graphs. add_edge! (g:: DGraph{T} , edge:: Edge ) where T
671675 check_not_frozen (g)
672- return add_edge! (g, src (edge), dst (edge))
676+ return add_edge! (g, T ( src (edge)), T ( dst (edge) ))
673677end
674678function Graphs. add_edge! (g:: DGraphState{T,D} , src:: Integer , dst:: Integer ) where {T,D}
675679 check_not_frozen (g)
676680
677- src_part_idx = findfirst (span-> src in span, g. parts_nv)
681+ src_part_idx = T ( findfirst (span-> src in span, g. parts_nv) )
678682 @assert src_part_idx != = nothing " Source vertex $src does not exist"
679683
680- dst_part_idx = findfirst (span-> dst in span, g. parts_nv)
684+ dst_part_idx = T ( findfirst (span-> dst in span, g. parts_nv) )
681685 @assert dst_part_idx != = nothing " Destination vertex $dst does not exist"
682686
683687 if src_part_idx == dst_part_idx
684688 # Edge exists within a single partition
685689 part = g. parts[src_part_idx]
686- src_shift = src - (g. parts_nv[src_part_idx]. start - 1 )
687- dst_shift = dst - (g. parts_nv[dst_part_idx]. start - 1 )
690+ src_shift = src - (g. parts_nv[src_part_idx]. start - one (T) )
691+ dst_shift = dst - (g. parts_nv[dst_part_idx]. start - one (T) )
688692 if exec_fast (add_edge!, part, src_shift, dst_shift)
689- g. parts_ne[src_part_idx] += 1
693+ g. parts_ne[src_part_idx] += one (T)
690694 else
691695 return false
692696 end
@@ -701,13 +705,13 @@ function Graphs.add_edge!(g::DGraphState{T,D}, src::Integer, dst::Integer) where
701705 end
702706 if D
703707 # TODO : This will cause imbalance for many outgoing edges from a few vertices
704- g. bg_adjs_ne_src[src_part_idx] += 1
708+ g. bg_adjs_ne_src[src_part_idx] += one (T)
705709 else
706710 owner_part_idx = edge_owner (src, dst, src_part_idx, dst_part_idx)
707- g. bg_adjs_ne_src[owner_part_idx] += 1
711+ g. bg_adjs_ne_src[owner_part_idx] += one (T)
708712 end
709- g. bg_adjs_ne[src_part_idx] += 1
710- g. bg_adjs_ne[dst_part_idx] += 1
713+ g. bg_adjs_ne[src_part_idx] += one (T)
714+ g. bg_adjs_ne[dst_part_idx] += one (T)
711715 end
712716
713717 return true
@@ -771,23 +775,24 @@ function add_edges!(g::Graphs.AbstractSimpleGraph, shift, edges; all::Bool=true)
771775end
772776
773777"""
774- edge_owner(src::Integer , dst::Integer , src_part_idx::Integer , dst_part_idx::Integer)
778+ edge_owner(src::T , dst::T , src_part_idx::T , dst_part_idx::T) where {T<:Integer}
775779
776780Determine which partition owns the edge `(src, dst)`.
777- FIXME: I do not like it. Both partitions should own the edge. (i.e. there should be data redundancy for the backgorund graph)
781+ FIXME: I do not like it. Both partitions should own the edge. (i.e. there should be data redundancy for the background graph)
778782"""
779- edge_owner (src:: Int , dst:: Int , src_part_idx:: Int , dst_part_idx:: Int ) =
783+ edge_owner (src:: T , dst:: T , src_part_idx:: T , dst_part_idx:: T ) where {T <: Integer } =
780784 iseven (hash (Base. unsafe_trunc (UInt, src+ dst))) ? src_part_idx : dst_part_idx
781785
782- Graphs. inneighbors (g:: DGraph , v:: Integer ) = with_state (g, inneighbors, v)
783- function Graphs. inneighbors (g:: DGraphState{T} , v:: Integer ) where T
786+ Graphs. inneighbors (g:: DGraph{T} , v:: Integer ) where T =
787+ with_state (g, inneighbors, T (v))
788+ function Graphs. inneighbors (g:: DGraphState{T} , v:: T ) where T
784789 part_idx = findfirst (span-> v in span, g. parts_nv)
785790 if part_idx === nothing
786791 throw (BoundsError (g, v))
787792 end
788793
789794 neighbors = T[]
790- shift = g. parts_nv[part_idx]. start - 1
795+ shift = g. parts_nv[part_idx]. start - one (T)
791796
792797 # Check against local edges
793798 v_shift = v - shift
@@ -797,17 +802,18 @@ function Graphs.inneighbors(g::DGraphState{T}, v::Integer) where T
797802 # Check against background edges
798803 append! (neighbors, exec_fast (inneighbors, g. bg_adjs[part_idx], v))
799804
800- return neighbors
805+ return sort! ( neighbors)
801806end
802- Graphs. outneighbors (g:: DGraph , v:: Integer ) = with_state (g, outneighbors, v)
803- function Graphs. outneighbors (g:: DGraphState{T} , v:: Integer ) where T
807+ Graphs. outneighbors (g:: DGraph{T} , v:: Integer ) where T =
808+ with_state (g, outneighbors, T (v))
809+ function Graphs. outneighbors (g:: DGraphState{T} , v:: T ) where T
804810 part_idx = findfirst (span-> v in span, g. parts_nv)
805811 if part_idx === nothing
806812 throw (BoundsError (g, v))
807813 end
808814
809815 neighbors = T[]
810- shift = g. parts_nv[part_idx]. start - 1
816+ shift = g. parts_nv[part_idx]. start - one (T)
811817
812818 # Check against local edges
813819 v_shift = v - shift
@@ -817,7 +823,7 @@ function Graphs.outneighbors(g::DGraphState{T}, v::Integer) where T
817823 # Check against background edges
818824 append! (neighbors, exec_fast (outneighbors, g. bg_adjs[part_idx], v))
819825
820- return neighbors
826+ return sort! ( neighbors)
821827end
822828
823829"""
@@ -878,8 +884,8 @@ partition_edges(g::DGraph, part::Integer) =
878884
879885Get the edges of the partition `part` of the graph state `g`.
880886"""
881- function partition_edges (g:: DGraphState , part:: Integer )
882- shift = g. parts_nv[part]. start - 1
887+ function partition_edges (g:: DGraphState{T} , part:: Integer ) where T
888+ shift = g. parts_nv[part]. start - one (T)
883889 part_edges = map (edge-> Edge (src (edge)+ shift, dst (edge)+ shift), exec_fast (edges, g. parts[part]))
884890 back_edges = exec_fast (edges, g. bg_adjs[part])
885891 return part_edges, back_edges
0 commit comments