Skip to content

Commit

Permalink
More ReshapedArray tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Apr 21, 2016
1 parent 72af884 commit 64745d7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,50 @@ a = reshape(b, (2, 2, 2, 2, 2))
@test a[2,2,2,2,2] == b[end]

# reshaping linearslow arrays
a = zeros(1, 5)
a = collect(reshape(1:5, 1, 5))
s = sub(a, :, [2,3,5])
@test length(reshape(s, length(s))) == 3
r = reshape(s, length(s))
@test length(r) == 3
@test r[1] == 2
@test r[3,1] == 5
@test r[Base.ReshapedIndex(CartesianIndex((1,2)))] == 3
@test parent(reshape(r, (1,3))) === r.parent === s
@test parentindexes(r) == (1:1, 1:3)
@test reshape(r, (3,)) === r
r[2] = -1
@test a[3] == -1
a = zeros(0, 5) # an empty linearslow array
s = sub(a, :, [2,3,5])
@test length(reshape(s, length(s))) == 0

@test reshape(1:5, (5,)) === 1:5
@test reshape(1:5, 5) === 1:5

# setindex! on a reshaped range
a = reshape(1:20, 5, 4)
for idx in ((3,), (2,2), (Base.ReshapedIndex(1),))
try
a[idx...] = 7
catch err
@test err.msg == "indexed assignment fails for a reshaped range; consider calling collect"
end
end

# operations with LinearFast ReshapedArray
b = collect(1:12)
a = Base.ReshapedArray(b, (4,3), ())
@test a[3,2] == 7
@test a[6] == 6
a[3,2] = -2
a[6] = -3
a[Base.ReshapedIndex(5)] = -4
@test b[5] == -4
@test b[6] == -3
@test b[7] == -2
b = reinterpret(Int, a, (3,4))
b[1] = -1
@test vec(b) == vec(a)

a = rand(1, 1, 8, 8, 1)
@test @inferred(squeeze(a, 1)) == @inferred(squeeze(a, (1,))) == reshape(a, (1, 8, 8, 1))
@test @inferred(squeeze(a, (1, 5))) == squeeze(a, (5, 1)) == reshape(a, (1, 8, 8))
Expand Down
2 changes: 1 addition & 1 deletion test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ b1 = bitrand(1, v1, 1)
@check_bit_operation cat(2, false, b1, true, true, b1) BitArray{3}

b1 = bitrand(n1, n2)
for m1 = 1 : n1 - 1r
for m1 = 1 : n1 - 1
for m2 = 1 : n2 - 1
@test isequal([b1[1:m1,1:m2] b1[1:m1,m2+1:end]; b1[m1+1:end,1:m2] b1[m1+1:end,m2+1:end]], b1)
end
Expand Down

0 comments on commit 64745d7

Please sign in to comment.