diff --git a/src/OffsetArrays.jl b/src/OffsetArrays.jl index 6fd5ece..e0b3381 100644 --- a/src/OffsetArrays.jl +++ b/src/OffsetArrays.jl @@ -376,16 +376,13 @@ _reshape2(A::OffsetArray, inds) = reshape(parent(A), inds) _reshape_nov(A, inds) = _reshape(no_offset_view(A), inds) # And for non-offset axes, we can just return a reshape of the parent directly -Base.reshape(A::OffsetArray, inds::Tuple{Union{Integer,Base.OneTo},Vararg{Union{Integer,Base.OneTo}}}) = _reshape_nov(A, inds) +Base.reshape(A::OffsetArray, inds::Tuple{Integer,Vararg{Integer}}) = _reshape_nov(A, inds) Base.reshape(A::OffsetArray, inds::Dims) = _reshape_nov(A, inds) -Base.reshape(A::OffsetVector, ::Colon) = A -Base.reshape(A::OffsetVector, ::Tuple{Colon}) = A -Base.reshape(A::OffsetArray, inds::Union{Int,Colon}...) = reshape(A, inds) -Base.reshape(A::OffsetArray, inds::Tuple{Vararg{Union{Int,Colon}}}) = _reshape_nov(A, inds) -# The following two additional methods for Colon are added to resolve method ambiguities to -# Base: https://github.com/JuliaLang/julia/pull/45387#issuecomment-1132859663 -Base.reshape(A::OffsetArray, inds::Colon) = reshape(parent(A), inds) -Base.reshape(A::OffsetArray, inds::Tuple{Colon}) = reshape(parent(A), inds) +if VERSION < v"1.10.7" + # the specialized reshape(parent::AbstractVector, ::Tuple{Colon}) is available in Base at least on this version + Base.reshape(A::OffsetVector, ::Tuple{Colon}) = A + Base.reshape(A::OffsetArray, inds::Tuple{Vararg{Union{Int,Colon}}}) = _reshape_nov(A, inds) +end # permutedims in Base does not preserve axes, and can not be fixed in a non-breaking way # This is a stopgap solution diff --git a/test/runtests.jl b/test/runtests.jl index fc1693d..772161b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1749,6 +1749,28 @@ end end end +# custom FillArray with BigInt axes, used to test `reshape` +struct MyBigFill{T,N} <: AbstractArray{T,N} + val :: T + axes :: NTuple{N,Base.OneTo{BigInt}} +end +MyBigFill(val, sz::NTuple{N,BigInt}) where {N} = MyBigFill(val, map(Base.OneTo, sz)) +MyBigFill(val, sz::Tuple{Vararg{Integer}}) = MyBigFill(val, map(BigInt, sz)) +Base.size(M::MyBigFill) = map(length, M.axes) +Base.axes(M::MyBigFill) = M.axes +function Base.getindex(M::MyBigFill{<:Any,N}, ind::Vararg{Integer,N}) where {N} + checkbounds(M, ind...) + M.val +end +function Base.isassigned(M::MyBigFill{<:Any,N}, ind::Vararg{BigInt,N}) where {N} + checkbounds(M, ind...) + true +end +function Base.reshape(M::MyBigFill, ind::NTuple{N,BigInt}) where {N} + length(M) == prod(ind) || throw(ArgumentError("length mismatch in reshape")) + MyBigFill(M.val, ind) +end + @testset "reshape" begin A0 = [1 3; 2 4] A = OffsetArray(A0, (-1,2)) @@ -1846,10 +1868,11 @@ end @test axes(R) == (1:2, 1:3) r = OffsetArray(ZeroBasedRange(3:4), 1); - @test reshape(r, 2) == 3:4 - @test reshape(r, (2,)) == 3:4 + @test reshape(r, 2) == reshape(r, big(2)) == 3:4 + @test reshape(r, (2,)) == reshape(r, (big(2),)) == 3:4 @test reshape(r, :) == 3:4 @test reshape(r, (:,)) == 3:4 + @test reshape(r, big(2), 1) == reshape(3:4, 2, 1) # getindex for a reshaped array that wraps an offset array is broken on 1.0 if VERSION >= v"1.1" @@ -1901,6 +1924,11 @@ end catch e e isa TypeError || rethrow() end + @testset "Tuple{Vararg{Integer}}" begin + M = MyBigFill(4, (2, 3)) + O = OffsetArray(M) + @test vec(O) isa MyBigFill + end end @testset "permutedims" begin