Skip to content

Commit 20a12a0

Browse files
committed
Fix overrides and formatting
1 parent 6f5b1ad commit 20a12a0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/overrides.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,22 @@ function Graphs.induced_subgraph(
172172
return newg, Vector{E}(vlist)
173173
end
174174

175-
function induced_subgraph(g::T, elist::AbstractVector{U}) where T <: AbstractSimpleWeightedGraph where U <: AbstractEdge
175+
function Graphs.induced_subgraph(
176+
g::T, elist::AbstractVector{U}
177+
) where {T<:AbstractSimpleWeightedGraph} where {U<:AbstractEdge}
176178
allunique(elist) || throw(ArgumentError("Edges in subgraph list must be unique"))
177179
E = eltype(g)
178180
vertex_set = Set{E}()
179181
@inbounds for e in elist
180182
if has_edge(g, e)
181183
push!(vertex_set, src(e), dst(e))
182-
else
184+
else
183185
@warn "Skipping the edge $(e), since it does not exist in the graph!"
184186
end
185187
end
186188
vertex_list = collect(vertex_set)
187189
sort!(vertex_list)
188-
index_map = Dict(vertex_list[i] => i for i=1:length(vertex_list))
190+
index_map = Dict(vertex_list[i] => i for i in 1:length(vertex_list))
189191
n = length(vertex_list)
190192
new_weights = spzeros(weighttype(g), E, E(n), E(n))
191193
@inbounds for e in elist
@@ -197,7 +199,6 @@ function induced_subgraph(g::T, elist::AbstractVector{U}) where T <: AbstractSim
197199
end
198200
end
199201
end
200-
newg = zero(g)
201-
newg.weights = new_weights
202+
newg = T(new_weights)
202203
return newg, Vector{edgetype(g)}(collect(edges(newg)))
203204
end

test/simpleweightedgraph.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,13 @@ using SparseArrays
367367
# test edge induced graph with one edge removed
368368
# graph isomorphic to C_5
369369
g = SimpleWeightedGraph([0 2 0 0 2; 2 0 2 0 0; 0 2 0 2 0; 0 0 2 0 2; 2 0 0 2 0])
370-
expected_graph_weights = sparse([0 2 0 0 0; 2 0 2 0 0; 0 2 0 2 0; 0 0 2 0 2; 0 0 0 2 0]);
370+
expected_graph_weights = sparse(
371+
[0 2 0 0 0; 2 0 2 0 0; 0 2 0 2 0; 0 0 2 0 2; 0 0 0 2 0]
372+
)
371373
# create edge induced subgraph isomorphic to P_5. The edge (1, 5) is missing and test if weights are correct.
372-
edge_induced_subgraph_weights = weights(first(induced_subgraph(g, [Edge(1, 2), Edge(2, 3), Edge(3, 4), Edge(4, 5)])))
374+
edge_induced_subgraph_weights = weights(
375+
first(induced_subgraph(g, [Edge(1, 2), Edge(2, 3), Edge(3, 4), Edge(4, 5)]))
376+
)
373377
@test edge_induced_subgraph_weights == expected_graph_weights
374378

375379
# test edge induced subgraph which does not contain the whole vertex set, especially remove the first column (vertex 1)

0 commit comments

Comments
 (0)