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

Add Support for BitVector and BitMatrix Indexing #708

Merged
merged 6 commits into from
Nov 13, 2024
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]
odow marked this conversation as resolved.
Show resolved Hide resolved
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