Skip to content

Commit

Permalink
SubArrays: add lots of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Nov 20, 2014
1 parent 032661c commit 6445fff
Show file tree
Hide file tree
Showing 3 changed files with 372 additions and 77 deletions.
76 changes: 0 additions & 76 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,82 +110,6 @@ ind = findin(a, b)
rt = Base.return_types(setindex!, (Array{Int32, 3}, UInt8, Vector{Int}, Float64, Range1{Int}))
@test length(rt) == 1 && rt[1] == Array{Int32, 3}

# sub
A = reshape(1:120, 3, 5, 8)
sA = sub(A, 2, 1:5, :)
@test parent(sA) == A
@test parentindexes(sA) == (2:2, 1:5, :)
@test Base.parentdims(sA) == [1:3]
@test size(sA) == (1, 5, 8)
@test sA[1, 2, 1:8][:] == [5:15:120]
sA[2:5:end] = -1
@test all(sA[2:5:end] .== -1)
@test all(A[5:15:120] .== -1)
@test strides(sA) == (1,3,15)
@test stride(sA,3) == 15
@test stride(sA,4) == 120
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)
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,2:5]
@test sA[:] == A[1:3,3,2:5][:]
sA = sub(A, 1:2:3, 1:3:5, 1:2:8)
@test Base.parentdims(sA) == [1:3]
@test strides(sA) == (2,9,30)
@test sA[:] == A[1:2:3, 1:3:5, 1:2:8][:]
# issue #8807
@test sub(sub([1:5], 1:5), 1:5) == [1:5]

# sub logical indexing #4763
A = sub([1:10], 5:8)
@test A[A.<7] == [5, 6]
B = reshape(1:16, 4, 4)
sB = sub(B, 2:3, 2:3)
@test sB[sB.>8] == [10, 11]

# slice
A = reshape(1:120, 3, 5, 8)
sA = slice(A, 2, :, 1:8)
@test parent(sA) == A
@test parentindexes(sA) == (2, :, 1:8)
@test Base.parentdims(sA) == [2:3]
@test size(sA) == (5, 8)
@test strides(sA) == (3,15)
@test sA[2, 1:8][:] == [5:15:120]
@test sA[:,1] == [2:3:14]
@test sA[2:5:end] == [5:15:110]
sA[2:5:end] = -1
@test all(sA[2:5:end] .== -1)
@test all(A[5:15:120] .== -1)
sA = slice(A, 1:3, 1:5, 5)
@test Base.parentdims(sA) == [1:2]
@test size(sA) == (3,5)
@test strides(sA) == (1,3)
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...][:]

a = [5:8]
@test parent(a) == a
@test parentindexes(a) == (1:4,)

# issue #6218 - logical indexing
A = rand(2, 2, 3)
msk = ones(Bool, 2, 2)
msk[2,1] = false
sA = sub(A, :, :, 1)
sA[msk] = 1.0
@test sA[msk] == ones(countnz(msk))

# get
let
A = reshape(1:24, 3, 8)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
testnames = [
"linalg", "core", "keywordargs", "numbers", "strings", "dates",
"collections", "hashing", "remote", "iobuffer", "staged", "arrayops",
"reduce", "reducedim",
"subarray", "reduce", "reducedim",
"simdloop", "blas", "fft", "dsp", "sparse", "bitarray", "math",
"functional", "bigint", "sorting", "statistics", "spawn",
"backtrace", "priorityqueue", "arpack", "file", "suitesparse", "version",
Expand Down
Loading

0 comments on commit 6445fff

Please sign in to comment.