Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

fix induced_subgraph indexing with vector of Bools #1573

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -266,6 +266,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 @@ -278,6 +286,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