Skip to content

Commit 91e3463

Browse files
authored
Fix ambiguity error in induced_subgraph (#54)
1 parent d7162f5 commit 91e3463

4 files changed

Lines changed: 53 additions & 6 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DataGraphs"
22
uuid = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
3-
version = "0.2.12"
43
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]
4+
version = "0.2.13"
55

66
[deps]
77
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
@@ -19,7 +19,7 @@ DataGraphsGraphsFlowsExt = "GraphsFlows"
1919
Dictionaries = "0.4"
2020
Graphs = "1"
2121
GraphsFlows = "0.1.1"
22-
NamedGraphs = "0.6.9, 0.7, 0.8"
22+
NamedGraphs = "0.8.2"
2323
SimpleTraits = "0.9"
2424
julia = "1.7"
2525

src/abstractdatagraph.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ edge_data_eltype(graph::AbstractDataGraph) = eltype(edge_data(graph))
4040

4141
Base.zero(graph_type::Type{<:AbstractDataGraph}) = graph_type()
4242

43+
# Graphs overloads
44+
function Graphs.vertices(graph::AbstractDataGraph)
45+
return Graphs.vertices(underlying_graph(graph))
46+
end
47+
4348
# Graphs overloads
4449
for f in [
4550
:(Graphs.a_star),
@@ -92,7 +97,6 @@ for f in [
9297
:(Graphs.steiner_tree),
9398
:(Graphs.topological_sort_by_dfs),
9499
:(Graphs.tree),
95-
:(Graphs.vertices),
96100
:(GraphsExtensions.boundary_edges),
97101
:(GraphsExtensions.boundary_vertices),
98102
:(GraphsExtensions.eccentricities),
@@ -402,7 +406,7 @@ function Base.setindex!(graph::AbstractDataGraph, x, i1, i2, i...)
402406
return graph
403407
end
404408

405-
function Graphs.induced_subgraph(graph::AbstractDataGraph, subvertices)
409+
function induced_subgraph_datagraph(graph::AbstractDataGraph, subvertices)
406410
underlying_subgraph, vlist = Graphs.induced_subgraph(underlying_graph(graph), subvertices)
407411
subgraph = similar_type(graph)(underlying_subgraph)
408412
for v in vertices(subgraph)
@@ -417,6 +421,15 @@ function Graphs.induced_subgraph(graph::AbstractDataGraph, subvertices)
417421
end
418422
return subgraph, vlist
419423
end
424+
function Graphs.induced_subgraph(graph::AbstractDataGraph, subvertices)
425+
return induced_subgraph_datagraph(graph, subvertices)
426+
end
427+
# Fix ambiguity with Graphs.jl for integer `subvertices`.
428+
function Graphs.induced_subgraph(
429+
graph::AbstractDataGraph, subvertices::AbstractVector{<:Integer}
430+
)
431+
return induced_subgraph_datagraph(graph, subvertices)
432+
end
420433

421434
#
422435
# Printing

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DataGraphs = "0.2.6"
1515
Dictionaries = "0.4.4"
1616
Graphs = "1.12"
1717
GraphsFlows = "0.1.1"
18-
NamedGraphs = "0.6.6, 0.7, 0.8"
18+
NamedGraphs = "0.8.2"
1919
SafeTestsets = "0.1"
2020
Suppressor = "0.2.8"
2121
Test = "1.10"

test/test_basics.jl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using Graphs:
2626
using Graphs.SimpleGraphs: SimpleDiGraph, SimpleEdge, SimpleGraph
2727
using GraphsFlows: GraphsFlows
2828
using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph
29-
using NamedGraphs.GraphsExtensions: , rename_vertices, vertextype
29+
using NamedGraphs.GraphsExtensions: , rename_vertices, subgraph, vertextype
3030
using NamedGraphs.NamedGraphGenerators: named_grid, named_path_graph
3131
using NamedGraphs.OrdinalIndexing: nd, st, rd, th
3232
using Test: @test, @test_broken, @testset
@@ -193,6 +193,40 @@ using Test: @test, @test_broken, @testset
193193
@test dg[1 => 2] == :default
194194
end
195195

196+
@testset "subgraph" begin
197+
dg = DataGraph(named_path_graph(4))
198+
dg[1] = "V1"
199+
dg[2] = "V2"
200+
dg[3] = "V3"
201+
dg[4] = "V4"
202+
dg[1 => 2] = "E12"
203+
dg[2 => 3] = "E23"
204+
dg[3 => 4] = "E34"
205+
sg = subgraph(dg, [2, 3, 4])
206+
@test nv(sg) == 3
207+
@test ne(sg) == 2
208+
@test !has_vertex(sg, 1)
209+
@test has_vertex(sg, 2)
210+
@test has_vertex(sg, 3)
211+
@test has_vertex(sg, 4)
212+
@test !has_edge(sg, 1 => 2)
213+
@test !has_edge(sg, 2 => 1)
214+
@test has_edge(sg, 2 => 3)
215+
@test has_edge(sg, 3 => 2)
216+
@test has_edge(sg, 3 => 4)
217+
@test has_edge(sg, 4 => 3)
218+
@test isnothing(get(sg, 1, nothing))
219+
@test sg[2] == "V2"
220+
@test sg[3] == "V3"
221+
@test sg[4] == "V4"
222+
@test isnothing(get(sg, 1 => 2, nothing))
223+
@test isnothing(get(sg, 2 => 1, nothing))
224+
@test sg[2 => 3] == "E23"
225+
@test sg[3 => 2] == "E23"
226+
@test sg[3 => 4] == "E34"
227+
@test sg[4 => 3] == "E34"
228+
end
229+
196230
@testset "Constructors specifying vertex type" begin
197231
dg = DataGraph{Float64}(
198232
named_path_graph(4); vertex_data_eltype = String, edge_data_eltype = Symbol

0 commit comments

Comments
 (0)