diff --git a/src/utils.jl b/src/utils.jl index ba52fce7..b0a6812e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -8,7 +8,7 @@ _indexlength(i::Integer) = i _indexlength(i::Colon) = Colon() _offset(axparent::AbstractUnitRange, ax::AbstractUnitRange) = first(ax) - first(axparent) -_offset(axparent::AbstractUnitRange, ax::Integer) = 1 - first(axparent) +_offset(axparent::AbstractUnitRange, ::Union{Integer, Colon}) = 1 - first(axparent) """ OffsetArrays.AxisConversionStyle(typeof(indices)) diff --git a/test/runtests.jl b/test/runtests.jl index 3e18faba..c0751d2f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1363,6 +1363,27 @@ end @test reshape(OffsetArray(-1:0, -1:0), :) == OffsetArray(-1:0, -1:0) @test reshape(A, :) == reshape(A0, :) + # reshape with one Colon for AbstractArrays + B = reshape(A0, -10:-9, :) + @test B isa OffsetArray{Int,2} + @test parent(B) === A0 + @test axes(B, 1) == -10:-9 + @test axes(B, 2) == axes(A0, 2) + + B = reshape(A0, -10:-9, 3:3, :) + @test B isa OffsetArray{Int,3} + @test same_value(A0, B) + @test axes(B, 1) == -10:-9 + @test axes(B, 2) == 3:3 + @test axes(B, 3) == 1:2 + + B = reshape(A0, -10:-9, 3:4, :) + @test B isa OffsetArray{Int,3} + @test same_value(A0, B) + @test axes(B, 1) == -10:-9 + @test axes(B, 2) == 3:4 + @test axes(B, 3) == 1:1 + # pop the parent B = reshape(A, size(A)) @test B == A0