Skip to content

Commit c52822e

Browse files
authored
resolve reshape ambiguity to Base (#289)
* resolve reshape ambiguity to Base * debug: retrigger CI * add test
1 parent 5eeae03 commit c52822e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/OffsetArrays.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,12 @@ Base.reshape(A::OffsetArray, inds::Tuple{Union{Integer,Base.OneTo},Vararg{Union{
376376
Base.reshape(A::OffsetArray, inds::Dims) = _reshape_nov(A, inds)
377377
Base.reshape(A::OffsetVector, ::Colon) = A
378378
Base.reshape(A::OffsetVector, ::Tuple{Colon}) = A
379-
Base.reshape(A::OffsetArray, ::Colon) = reshape(A, (Colon(),))
380379
Base.reshape(A::OffsetArray, inds::Union{Int,Colon}...) = reshape(A, inds)
381380
Base.reshape(A::OffsetArray, inds::Tuple{Vararg{Union{Int,Colon}}}) = _reshape_nov(A, inds)
381+
# The following two additional methods for Colon are added to resolve method ambiguities to
382+
# Base: https://github.com/JuliaLang/julia/pull/45387#issuecomment-1132859663
383+
Base.reshape(A::OffsetArray, inds::Colon) = reshape(parent(A), inds)
384+
Base.reshape(A::OffsetArray, inds::Tuple{Colon}) = reshape(parent(A), inds)
382385

383386
# permutedims in Base does not preserve axes, and can not be fixed in a non-breaking way
384387
# This is a stopgap solution

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,11 @@ end
18351835
rp = parent(r)
18361836
@test axes(reshape(rp, 4:6), 1) == 4:6
18371837
@test axes(reshape(r, (3,1))) == (1:3, 1:1)
1838+
1839+
# reshape with one single colon becomes a `vec`
1840+
A = OffsetArray(rand(4, 4), -1, -1)
1841+
@test reshape(A, (:, )) == vec(A)
1842+
@test reshape(A, :) == vec(A)
18381843
end
18391844

18401845
@testset "permutedims" begin

0 commit comments

Comments
 (0)