Skip to content

Commit

Permalink
Speed up SubArray tests
Browse files Browse the repository at this point in the history
* Just do spot-checks on throwing bounds errors
* Be more judicious in the index types tested
* Run the subarray test first
  • Loading branch information
mbauman committed Apr 23, 2016
1 parent a006074 commit d68315c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Upon return, `tests` is a vector of fully-expanded test names, and
""" ->
function choosetests(choices = [])
testnames = [
"linalg", "core", "inference", "keywordargs", "numbers", "printf",
"char", "string", "triplequote", "unicode",
"subarray", "linalg", "core", "inference", "keywordargs", "numbers",
"printf", "char", "string", "triplequote", "unicode",
"dates", "dict", "hashing", "remote", "iobuffer", "staged",
"arrayops", "tuple", "subarray", "reduce", "reducedim", "random",
"arrayops", "tuple", "reduce", "reducedim", "random",
"abstractarray", "intfuncs", "simdloop", "blas", "sparse",
"bitarray", "copy", "math", "fastmath", "functional",
"operators", "path", "ccall", "parse", "loading", "bigint",
Expand Down
17 changes: 10 additions & 7 deletions test/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ function runtests(A::Array, I...)
test_linear(S, C)
test_cartesian(S, C)
test_mixed(S, C)
test_bounds(S)
# slice
S = slice(A, I...)
test_linear(S, C)
test_cartesian(S, C)
test_mixed(S, C)
test_bounds(S)
end

function runtests(A::ANY, I...)
Expand Down Expand Up @@ -228,7 +226,6 @@ function runtests(A::ANY, I...)
test_linear(S, C)
test_cartesian(S, C)
test_mixed(S, C)
test_bounds(S)
# slice
try
S = slice(A, I...)
Expand All @@ -241,7 +238,6 @@ function runtests(A::ANY, I...)
test_linear(S, C)
test_cartesian(S, C)
test_mixed(S, C)
test_bounds(S)
end

# indexN is a cartesian index, indexNN is a linear index for 2 dimensions, and indexNNN is a linear index for 3 dimensions
Expand Down Expand Up @@ -280,9 +276,9 @@ runviews{T}(SB::AbstractArray{T,0}, indexN, indexNN, indexNNN) = nothing
testfull = Bool(parse(Int,(get(ENV, "JULIA_TESTFULL", "0"))))

### Views from Arrays ###
index5 = (1, :, 2:5, 1:2:5, [4,1,5], reshape([2]), sub(1:5,[2,1,5]), [2 3 4 1]) # all work with at least size 5
index25 = (3, :, 2:11, 12:3:22, [4,1,5,9], reshape([10]), sub(1:25,[13,22,24]), [19 15; 4 24])
index125 = (113, :, 85:121, 2:15:92, [99,14,103], reshape([72]), sub(1:125,[66,18,59]), reshape([25,4,102,67], 1, 2, 2))
index5 = (1, :, 2:5, [4,1,5], reshape([2]), sub(1:5,[2 3 4 1])) # all work with at least size 5
index25 = (3, :, 2:11, [19,9,7], reshape([10]), sub(1:25,[19 15; 4 24]))
index125 = (113, :, 85:121, [99,14,103], reshape([72]), sub(1:125,reshape([25,4,102,67], 1, 2, 2)))

if testfull
let A = copy(reshape(1:5*7*11, 11, 7, 5))
Expand Down Expand Up @@ -357,18 +353,21 @@ sA[2:5:end] = -1
@test strides(sA) == (1,3,15)
@test stride(sA,3) == 15
@test stride(sA,4) == 120
test_bounds(sA)
sA = sub(A, 1:3, 1:5, 5)
@test Base.parentdims(sA) == [1:2;]
sA[1:3,1:5] = -2
@test all(A[:,:,5] .== -2)
sA[:] = -3
@test all(A[:,:,5] .== -3)
@test strides(sA) == (1,3)
test_bounds(sA)
sA = sub(A, 1:3, 3, 2:5)
@test Base.parentdims(sA) == [1:3;]
@test size(sA) == (3,1,4)
@test sA == A[1:3,3:3,2:5]
@test sA[:] == A[1:3,3,2:5][:]
test_bounds(sA)
sA = sub(A, 1:2:3, 1:3:5, 1:2:8)
@test Base.parentdims(sA) == [1:3;]
@test strides(sA) == (2,9,30)
Expand All @@ -377,6 +376,7 @@ sA = sub(A, 1:2:3, 1:3:5, 1:2:8)
@test sub(sub([1:5;], 1:5), 1:5) == [1:5;]
# Test with mixed types
@test sA[:, Int16[1,2], big(2)] == [31 40; 33 42]
test_bounds(sA)

# sub logical indexing #4763
A = sub([1:10;], 5:8)
Expand All @@ -401,15 +401,18 @@ sA = slice(A, 2, :, 1:8)
sA[2:5:end] = -1
@test all(sA[2:5:end] .== -1)
@test all(A[5:15:120] .== -1)
test_bounds(sA)
sA = slice(A, 1:3, 1:5, 5)
@test Base.parentdims(sA) == [1:2;]
@test size(sA) == (3,5)
@test strides(sA) == (1,3)
test_bounds(sA)
sA = slice(A, 1:2:3, 3, 1:2:8)
@test Base.parentdims(sA) == [1,3]
@test size(sA) == (2,4)
@test strides(sA) == (2,30)
@test sA[:] == A[sA.indexes...][:]
test_bounds(sA)

a = [5:8;]
@test parent(a) == a
Expand Down

0 comments on commit d68315c

Please sign in to comment.