diff --git a/test/arrayops.jl b/test/arrayops.jl index 9867e062af864..9022fc0c18ce6 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -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)) diff --git a/test/bitarray.jl b/test/bitarray.jl index 290f2a0c5f3a6..e91156352385b 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -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