Skip to content

Commit

Permalink
Circshift no longer throws error for empty array (#42288)
Browse files Browse the repository at this point in the history
* Test circshift with 0-dim array

* circshift returns dest array for a 0-dim array

* use isempty instead of checking size
  • Loading branch information
getzze authored Sep 21, 2021
1 parent 4f3a89e commit 144ed87
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ See also [`circshift`](@ref).
dest === src && throw(ArgumentError("dest and src must be separate arrays"))
inds = axes(src)
axes(dest) == inds || throw(ArgumentError("indices of src and dest must match (got $inds and $(axes(dest)))"))
isempty(src) && return dest
_circshift!(dest, (), src, (), inds, fill_to_length(shiftamt, 0, Val(N)))
end

Expand Down
6 changes: 6 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ end
@test res === dst == [5 6 4; 2 3 1]
res = circshift!(dst, src, (3.0, 2.0))
@test res === dst == [5 6 4; 2 3 1]

# https://github.com/JuliaLang/julia/issues/41402
src = Float64[]
@test circshift(src, 1) == src
src = zeros(Bool, (4,0))
@test circshift(src, 1) == src
end

@testset "circcopy" begin
Expand Down

0 comments on commit 144ed87

Please sign in to comment.