Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port] fix induced_subgraph indexing with vector of Bools #22

Merged
merged 2 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@ function induced_subgraph(g::T, vlist::AbstractVector{U}) where T <: AbstractGra
return h, vmap
end

function induced_subgraph(g::AbstractGraph, vlist::AbstractVector{Bool})
length(vlist) == length(g) || throw(BoundsError(g, vlist))
return induced_subgraph(g, findall(vlist))
end

function induced_subgraph(g::AG, elist::AbstractVector{U}) where AG <: AbstractGraph{T} where T where U <: AbstractEdge
h = zero(g)
Expand Down
14 changes: 14 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@
@test h2 == h
@test vm == collect(r)
@test h2 == g[r]

r2 = falses(length(g))
r2[r] .= true
h2, vm = @inferred(induced_subgraph(g, r2))
@test h2 == h
@test vm == findall(r2)
@test h2 == g[r2]

end

g10 = complete_graph(10)
Expand All @@ -285,6 +293,12 @@
@test sg2 == sg
@test vm[4] == 8

bv = falses(length(g))
bv[5:8] .= true
sg2, vm = @inferred(induced_subgraph(g, bv))
@test sg2 == sg
@test vm[4] == 8

elist = [
SimpleEdge(1, 2), SimpleEdge(2, 3), SimpleEdge(3, 4),
SimpleEdge(4, 5), SimpleEdge(5, 1)
Expand Down