Skip to content

Commit 5ae657d

Browse files
Fix gnnheterographs failed test (#241)
* Fix print order for Dict * Add sorted order to dict print * Fix style Co-authored-by: Carlo Lucibello <[email protected]> * Add spaces Co-authored-by: Carlo Lucibello <[email protected]> * Fix indentations Co-authored-by: Carlo Lucibello <[email protected]>
1 parent 1381a78 commit 5ae657d

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/GNNGraphs/gnnheterograph.jl

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,58 @@ function GNNHeteroGraph(data::EDict;
130130
ntypes, etypes)
131131
end
132132

133+
function show_sorted_Dict(io::IO, d::Dict, compact::Bool)
134+
if compact
135+
print(io, "Dict")
136+
end
137+
print(io, "(")
138+
if !isempty(d)
139+
if length(keys(d)) == 1
140+
show(io, keys[1])
141+
print(io, " => $(d[keys[1]])")
142+
else
143+
sorted_keys = sort!(collect(keys(d)))
144+
for key in sorted_keys[1:end-1]
145+
show(io, key)
146+
print(io, " => $(d[key]), ")
147+
end
148+
show(io, sorted_keys[end])
149+
print(io, " => $(d[sorted_keys[end]])")
150+
end
151+
end
152+
print(io, ")")
153+
end
133154

134155
function Base.show(io::IO, g::GNNHeteroGraph)
135-
print(io, "GNNHeteroGraph($(g.num_nodes), $(g.num_edges))")
156+
print(io, "GNNHeteroGraph(")
157+
show_sorted_Dict(io, g.num_nodes, true)
158+
print(io, ", ")
159+
show_sorted_Dict(io, g.num_edges, true)
160+
print(io, ")")
136161
end
137162

138163
function Base.show(io::IO, ::MIME"text/plain", g::GNNHeteroGraph)
139164
if get(io, :compact, false)
140-
print(io, "GNNHeteroGraph($(g.num_nodes), $(g.num_edges))")
165+
print(io, "GNNHeteroGraph(")
166+
show_sorted_Dict(io, g.num_nodes, true)
167+
print(io, ", ")
168+
show_sorted_Dict(io, g.num_edges, true)
169+
print(io, ")")
141170
else
142-
print(io, "GNNHeteroGraph:\n num_nodes: $((g.num_nodes...,))\n num_edges: $((g.num_edges...,))")
171+
print(io, "GNNHeteroGraph:\n num_nodes: ")
172+
show_sorted_Dict(io, g.num_nodes, false)
173+
print(io, "\n num_edges: ")
174+
show_sorted_Dict(io, g.num_edges, false)
143175
g.num_graphs > 1 && print(io, "\n num_graphs: $(g.num_graphs)")
144176
if !isempty(g.ndata)
145177
print(io, "\n ndata:")
146-
for k in keys(g.ndata)
178+
for k in sort(collect(keys(g.ndata)))
147179
print(io, "\n\t", _str(k), " => $(shortsummary(g.ndata[k]))")
148180
end
149181
end
150182
if !isempty(g.edata)
151183
print(io, "\n edata:")
152-
for k in keys(g.edata)
184+
for k in sort(collect(keys(g.edata)))
153185
print(io, "\n\t$k => $(shortsummary(g.edata[k]))")
154186
end
155187
end

0 commit comments

Comments
 (0)