Skip to content

Commit

Permalink
Always return a value in 1-d circshift! of abstractarray.jl (#53554)
Browse files Browse the repository at this point in the history
Co-authored-by: Sukera <[email protected]>
Co-authored-by: Mosè Giordano <[email protected]>
(cherry picked from commit 7179050)
  • Loading branch information
erich-9 authored and KristofferC committed Mar 6, 2024
1 parent b63e086 commit c01ef98
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 @@ -3643,9 +3643,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 c01ef98

Please sign in to comment.