Skip to content

Commit 9044222

Browse files
authored
reshape for offset AbstractVectors with Tuple{Colon} as indices (#41599)
1 parent 9023817 commit 9044222

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

base/reshapedarray.jl

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ reshape(parent::AbstractArray, dims::Dims) = _reshape(parent, dims)
113113

114114
# Allow missing dimensions with Colon():
115115
reshape(parent::AbstractVector, ::Colon) = parent
116+
reshape(parent::AbstractVector, ::Tuple{Colon}) = parent
116117
reshape(parent::AbstractArray, dims::Int...) = reshape(parent, dims)
117118
reshape(parent::AbstractArray, dims::Union{Int,Colon}...) = reshape(parent, dims)
118119
reshape(parent::AbstractArray, dims::Tuple{Vararg{Union{Int,Colon}}}) = reshape(parent, _reshape_uncolon(parent, dims))

test/abstractarray.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1565,3 +1565,8 @@ end
15651565
@test_throws ArgumentError keepat!(a, [2, 1])
15661566
@test isempty(keepat!(a, []))
15671567
end
1568+
1569+
@testset "reshape methods for AbstractVectors" begin
1570+
r = Base.IdentityUnitRange(3:4)
1571+
@test reshape(r, :) === reshape(r, (:,)) === r
1572+
end

test/offsetarray.jl

+6
Original file line numberDiff line numberDiff line change
@@ -795,3 +795,9 @@ end
795795
@test Iterators.partition(OffsetArray(reshape(collect(1:9),3,3), (3,3)), 5) |> collect == [1:5,6:9] #OffsetMatrix
796796
@test Iterators.partition(IdOffsetRange(2:7,10), 5) |> collect == [12:16,17:17] # IdOffsetRange
797797
end
798+
799+
@testset "reshape" begin
800+
a = OffsetArray(4:5, 5:6)
801+
@test reshape(a, :) === a
802+
@test reshape(a, (:,)) === a
803+
end

test/testhelpers/OffsetArrays.jl

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ Base.reshape(A::OffsetArray, inds::Tuple{Union{Integer,Base.OneTo},Vararg{Union{
297297
Base.reshape(A::OffsetArray, inds::Dims) = reshape(parent(A), inds)
298298
Base.reshape(A::OffsetArray, ::Colon) = reshape(parent(A), Colon())
299299
Base.reshape(A::OffsetVector, ::Colon) = A
300+
Base.reshape(A::OffsetVector, ::Tuple{Colon}) = A
300301
Base.reshape(A::OffsetArray, inds::Union{Int,Colon}...) = reshape(parent(A), inds)
301302
Base.reshape(A::OffsetArray, inds::Tuple{Vararg{Union{Int,Colon}}}) = reshape(parent(A), inds)
302303

0 commit comments

Comments
 (0)