Skip to content

Commit

Permalink
Always return a value in 1-d circshift! of abstractarray.jl (JuliaLan…
Browse files Browse the repository at this point in the history
…g#53554)

Co-authored-by: Sukera <[email protected]>
Co-authored-by: Mosè Giordano <[email protected]>
  • Loading branch information
3 people authored Mar 3, 2024
1 parent 0f902bf commit 7179050
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3656,9 +3656,9 @@ end
## 1-d circshift ##
function circshift!(a::AbstractVector, shift::Integer)
n = length(a)
n == 0 && return
n == 0 && return a
shift = mod(shift, n)
shift == 0 && return
shift == 0 && return a
l = lastindex(a)
reverse!(a, firstindex(a), l-shift)
reverse!(a, l-shift+1, lastindex(a))
Expand Down
8 changes: 8 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,14 @@ end
oa = OffsetVector(copy(a), -1)
@test circshift!(oa, 1) === oa
@test oa == circshift(OffsetVector(a, -1), 1)

# 1d circshift! (#53554)
a = []
@test circshift!(a, 1) === a
@test circshift!(a, 1) == []
a = [1:5;]
@test circshift!(a, 10) === a
@test circshift!(a, 10) == 1:5
end

@testset "circcopy" begin
Expand Down

0 comments on commit 7179050

Please sign in to comment.