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

APL indexing #15431

Merged
merged 4 commits into from
May 1, 2016
Merged
Changes from 1 commit
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
Prev Previous commit
Add abstractarray tests for APL indexing
  • Loading branch information
mbauman committed May 1, 2016
commit 393fd7263c04e1b1e0673fdf962c0668cfbc39a6
20 changes: 20 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ function test_vector_indexing{T}(::Type{T}, shape, ::Type{TestAbstractArray})
# Test with containers that aren't Int[]
@test B[[]] == A[[]] == []
@test B[convert(Array{Any}, idxs)] == A[convert(Array{Any}, idxs)] == idxs

# Test adding dimensions with matrices
idx1 = rand(1:size(A, 1), 3)
idx2 = rand(1:Base.trailingsize(A, 2), 4, 5)
@test B[idx1, idx2] == A[idx1, idx2] == reshape(A[idx1, vec(idx2)], 3, 4, 5) == reshape(B[idx1, vec(idx2)], 3, 4, 5)
@test B[1, idx2] == A[1, idx2] == reshape(A[1, vec(idx2)], 4, 5) == reshape(B[1, vec(idx2)], 4, 5)

# test removing dimensions with 0-d arrays
idx0 = reshape([rand(1:size(A, 1))])
@test B[idx0, idx2] == A[idx0, idx2] == reshape(A[idx0[], vec(idx2)], 4, 5) == reshape(B[idx0[], vec(idx2)], 4, 5)
@test B[reshape([end]), reshape([end])] == A[reshape([end]), reshape([end])] == reshape([A[end,end]]) == reshape([B[end,end]])

# test logical indexing
mask = bitrand(shape)
@test B[mask] == A[mask] == B[find(mask)] == A[find(mask)] == find(mask)
@test B[vec(mask)] == A[vec(mask)] == find(mask)
mask1 = bitrand(size(A, 1))
mask2 = bitrand(Base.trailingsize(A, 2))
@test B[mask1, mask2] == A[mask1, mask2] == B[find(mask1), find(mask2)]
@test B[mask1, 1] == A[mask1, 1] == find(mask1)
end

function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray})
Expand Down