Skip to content

Commit

Permalink
allow BitArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Abbott committed Mar 16, 2020
1 parent 4b2e7cd commit 214431c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ for (bget, rget, cpy) in [(:getindex, :keys_getindex, :copy), (:view, :keys_view
@inbounds Base.$bget(parent(A), I...)
end

@inline function Base.$bget(A::KeyedArray, I::Union{Colon, CartesianIndex})
@inline function Base.$bget(A::KeyedArray, I::Union{Colon, CartesianIndex, BitArray})
@boundscheck checkbounds(parent(A), I)
@inbounds Base.$bget(parent(A), I)
end
Expand Down
11 changes: 10 additions & 1 deletion test/_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using Test, AxisKeys
@test R[:] == vec(R.data)
@test_broken R[1:2, 1, 1] == R.data[1:2, 1, 1] # trailing 1s are broken
@test axiskeys(R[:, [0.9,0.1,0.9,0.1] .> 0.5],2) == [10,30]
@test_broken ndims(R[R.data .> 0.5]) == 1 # BitArray{2} is broken
@test ndims(R[R.data .> 0.5]) == 1

@test_throws Exception R(:nope) # ideally ArgumentError
@test_throws Exception R('z') # ideally BoundsError?
Expand Down Expand Up @@ -197,6 +197,15 @@ end

end
end
@testset "bitarray" begin

x = wrapdims(rand(3,4), a=11:13, b=21:24.0)
b = rand(12) .> 0.5
@test length(x[b]) == sum(b)
m = rand(3,4) .> 0.5 # BitArray{2}
@test size(x[m]) == (sum(m),)

end
@testset "mutation" begin

V = wrapdims([3,5,7,11], μ=10:10:40)
Expand Down

0 comments on commit 214431c

Please sign in to comment.