Skip to content

Commit 54d2fd1

Browse files
committed
Rename remove_multi_edges to coalesce, update references, add deprecation
1 parent 2dec808 commit 54d2fd1

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

GNNGraphs/src/GNNGraphs.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export add_nodes,
7575
rand_edge_split,
7676
remove_self_loops,
7777
remove_edges,
78-
remove_multi_edges,
79-
coalesce_graph,
78+
coalesce,
8079
set_edge_weight,
8180
to_bidirected,
8281
to_unidirected,

GNNGraphs/src/deprecations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ function Base.getproperty(vds::Vector{DataStore}, s::Symbol)
1111
return [getdata(ds)[s] for ds in vds]
1212
end
1313
end
14+
15+
@deprecate remove_multi_edges(g::GNNGraph{<:COO_T}; aggr = +) Base.coalesce(g; aggr = aggr)

GNNGraphs/src/transform.jl

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end
4444
Return a graph constructed from `g` where self-loops (edges from a node to itself)
4545
are removed.
4646
47-
See also [`add_self_loops`](@ref) and [`remove_multi_edges`](@ref).
47+
See also [`add_self_loops`](@ref) and [`coalesce`](@ref).
4848
"""
4949
function remove_self_loops(g::GNNGraph{<:COO_T})
5050
s, t = edge_index(g)
@@ -146,15 +146,14 @@ function remove_edges(g::GNNGraph{<:COO_T}, p = 0.5)
146146
end
147147

148148
"""
149-
remove_multi_edges(g::GNNGraph; aggr=+)
149+
coalesce(g::GNNGraph; aggr=+)
150150
151-
Remove multiple edges (also called parallel edges or repeated edges) from graph `g`.
152-
Possible edge features are aggregated according to `aggr`, that can take value
153-
`+`,`min`, `max` or `mean`.
151+
Return a new GNNGraph where all multiple edges between the same pair of nodes are merged (using aggr for edge weights and features), and the edge indices are sorted lexicographically (by source, then target).
152+
This method is only applicable to graphs of type `:coo`.
154153
155-
See also [`remove_self_loops`](@ref), [`has_multi_edges`](@ref), and [`to_bidirected`](@ref).
154+
`aggr` can take value `+`,`min`, `max` or `mean`.
156155
"""
157-
function remove_multi_edges(g::GNNGraph{<:COO_T}; aggr = +)
156+
function Base.coalesce(g::GNNGraph{<:COO_T}; aggr = +)
158157
s, t = edge_index(g)
159158
w = get_edge_weight(g)
160159
edata = g.edata
@@ -184,16 +183,6 @@ function remove_multi_edges(g::GNNGraph{<:COO_T}; aggr = +)
184183
g.ndata, edata, g.gdata, true)
185184
end
186185

187-
"""
188-
coalesce_graph(g::GNNGraph)
189-
190-
Return a new GNNGraph where all multiple edges between the same pair of nodes are merged (using aggr for edge weights and features), and the edge indices are sorted lexicographically (by source, then target).
191-
This method is only applicable to graphs of type `:coo`.
192-
"""
193-
function coalesce_graph(g::GNNGraph{<:COO_T}, aggr = +)
194-
return remove_multi_edges(g, aggr = aggr)
195-
end
196-
197186
"""
198187
remove_nodes(g::GNNGraph, nodes_to_remove::AbstractVector)
199188
@@ -451,7 +440,7 @@ end
451440
to_bidirected(g)
452441
453442
Adds a reverse edge for each edge in the graph, then calls
454-
[`remove_multi_edges`](@ref) with `mean` aggregation to simplify the graph.
443+
[`coalesce`](@ref) with `mean` aggregation to simplify the graph.
455444
456445
See also [`is_bidirected`](@ref).
457446
@@ -515,7 +504,7 @@ function to_bidirected(g::GNNGraph{<:COO_T})
515504
g.graph_indicator,
516505
g.ndata, edata, g.gdata)
517506

518-
return remove_multi_edges(g; aggr = mean)
507+
return coalesce(g; aggr = mean)
519508
end
520509

521510
"""
@@ -535,7 +524,7 @@ function to_unidirected(g::GNNGraph{<:COO_T})
535524
g.graph_indicator,
536525
g.ndata, g.edata, g.gdata)
537526

538-
return remove_multi_edges(g; aggr = mean)
527+
return coalesce(g; aggr = mean)
539528
end
540529

541530
function Graphs.SimpleGraph(g::GNNGraph)

GNNGraphs/test/transform.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,22 @@ end
345345
end
346346
end
347347

348-
@testitem "remove_multi_edges" setup=[GraphsTestModule] begin
348+
@testitem "coalesce" setup=[GraphsTestModule] begin
349349
using .GraphsTestModule
350350
for GRAPH_T in GRAPH_TYPES
351351
if GRAPH_T == :coo
352352
g = rand_graph(10, 20, graph_type = GRAPH_T)
353353
s, t = edge_index(g)
354354
g1 = add_edges(g, s[1:5], t[1:5])
355355
@test g1.num_edges == g.num_edges + 5
356-
g2 = remove_multi_edges(g1, aggr = +)
356+
g2 = coalesce(g1, aggr = +)
357357
@test g2.num_edges == g.num_edges
358358
@test sort_edge_index(edge_index(g2)) == sort_edge_index(edge_index(g))
359359

360360
# Default aggregation is +
361361
g1 = GNNGraph(g1, edata = (e1 = ones(3, g1.num_edges), e2 = 2 * ones(g1.num_edges)))
362362
g1 = set_edge_weight(g1, 3 * ones(g1.num_edges))
363-
g2 = remove_multi_edges(g1)
363+
g2 = coalesce(g1)
364364
@test g2.num_edges == g.num_edges
365365
@test sort_edge_index(edge_index(g2)) == sort_edge_index(edge_index(g))
366366
@test count(g2.edata.e1[:, i] == 2 * ones(3) for i in 1:(g2.num_edges)) == 5

0 commit comments

Comments
 (0)