Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/atoms/IndexAtom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ function Base.getindex(x::AbstractExpr, I::AbstractVector{Bool})
return [xi for (xi, ii) in zip(x, I) if ii]
end

function Base.getindex(x::AbstractExpr, I::BitMatrix)
return [xi for (xi, ii) in zip(x, I) if ii]
end

function Base.getindex(x::AbstractExpr, I::BitVector)
return [xi for (xi, ii) in zip(x, I) if ii]
end

# All rows and columns
Base.getindex(x::AbstractExpr, ::Colon, ::Colon) = x

Expand Down
9 changes: 9 additions & 0 deletions test/test_atoms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,15 @@ function test_IndexAtom()
y = [true, false, true]
x = Variable(3)
@test string(x[y]) == string([x[1], x[3]])
target = """
variables: x1, x2, x3
minobjective: [1.0 * x1, 1.0 * x3]
"""
_test_atom(target) do context
x = Variable(3)
y = BitVector([true, false, true])
return x[y]
end
return
end

Expand Down