Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f492460

Browse files
committedApr 29, 2016
Add abstractarray tests for APL indexing
1 parent 6e508b9 commit f492460

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎test/abstractarray.jl

+20
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,26 @@ function test_vector_indexing{T}(::Type{T}, shape, ::Type{TestAbstractArray})
198198
# Test with containers that aren't Int[]
199199
@test B[[]] == A[[]] == []
200200
@test B[convert(Array{Any}, idxs)] == A[convert(Array{Any}, idxs)] == idxs
201+
202+
# Test adding dimensions with matrices
203+
idx1 = rand(1:size(A, 1), 3)
204+
idx2 = rand(1:Base.trailingsize(A, 2), 4, 5)
205+
@test B[idx1, idx2] == A[idx1, idx2] == reshape(A[idx1, vec(idx2)], 3, 4, 5) == reshape(B[idx1, vec(idx2)], 3, 4, 5)
206+
@test B[1, idx2] == A[1, idx2] == reshape(A[1, vec(idx2)], 4, 5) == reshape(B[1, vec(idx2)], 4, 5)
207+
208+
# test removing dimensions with 0-d arrays
209+
idx0 = reshape([rand(1:size(A, 1))])
210+
@test B[idx0, idx2] == A[idx0, idx2] == reshape(A[idx0[], vec(idx2)], 4, 5) == reshape(B[idx0[], vec(idx2)], 4, 5)
211+
@test B[reshape([end]), reshape([end])] == A[reshape([end]), reshape([end])] == reshape([A[end,end]]) == reshape([B[end,end]])
212+
213+
# test logical indexing
214+
mask = bitrand(shape)
215+
@test B[mask] == A[mask] == B[find(mask)] == A[find(mask)] == find(mask)
216+
@test B[vec(mask)] == A[vec(mask)] == find(mask)
217+
mask1 = bitrand(size(A, 1))
218+
mask2 = bitrand(Base.trailingsize(A, 2))
219+
@test B[mask1, mask2] == A[mask1, mask2] == B[find(mask1), find(mask2)]
220+
@test B[mask1, 1] == A[mask1, 1] == find(mask1)
201221
end
202222

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

0 commit comments

Comments
 (0)
Please sign in to comment.