Skip to content

Commit 37b76ee

Browse files
committed
Adjust edge_index_table API for directed
Fix
1 parent 09ddd17 commit 37b76ee

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/graph/index.jl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,31 @@ end
5353
Zygote.@nograd vertex_pair_table
5454

5555
"""
56-
edge_index_table(adj[, num_E])
56+
edge_index_table(adj[, directed])
5757
5858
Generate a mapping from vertex pair (i, j) to edge index. The edge indecies are determined by
5959
the sorted vertex indecies.
6060
"""
61-
function edge_index_table(adj::AbstractVector{<:AbstractVector{<:Integer}},
62-
num_E=sum(map(length, adj)))
61+
function edge_index_table(adj::AbstractVector{<:AbstractVector{<:Integer}}, directed::Bool=is_directed(adj))
6362
table = Dict{Tuple{UInt32,UInt32},UInt64}()
6463
e = one(UInt64)
65-
for (i, js) = enumerate(adj)
66-
js = sort(js)
67-
for j = js
68-
table[(i, j)] = e
69-
e += one(UInt64)
64+
if directed
65+
for (i, js) = enumerate(adj)
66+
js = sort(js)
67+
for j = js
68+
table[(i, j)] = e
69+
e += one(UInt64)
70+
end
71+
end
72+
else
73+
for (i, js) = enumerate(adj)
74+
js = sort(js)
75+
js = js[i .≤ js]
76+
for j = js
77+
table[(i, j)] = e
78+
table[(j, i)] = e
79+
e += one(UInt64)
80+
end
7081
end
7182
end
7283
table
@@ -80,6 +91,8 @@ function edge_index_table(vpair::AbstractVector{<:Tuple})
8091
table
8192
end
8293

94+
edge_index_table(fg::FeaturedGraph) = edge_index_table(fg.graph, fg.directed)
95+
8396
Zygote.@nograd edge_index_table
8497

8598
function transform(X::AbstractArray, vpair::AbstractVector{<:Tuple}, num_V)

0 commit comments

Comments
 (0)