Skip to content

Commit 2845793

Browse files
getzzeKristofferC
authored andcommitted
Circshift no longer throws error for empty array (#42288)
* Test circshift with 0-dim array * circshift returns dest array for a 0-dim array * use isempty instead of checking size (cherry picked from commit 144ed87)
1 parent 33ebbac commit 2845793

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

base/multidimensional.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ See also [`circshift`](@ref).
11231123
dest === src && throw(ArgumentError("dest and src must be separate arrays"))
11241124
inds = axes(src)
11251125
axes(dest) == inds || throw(ArgumentError("indices of src and dest must match (got $inds and $(axes(dest)))"))
1126+
isempty(src) && return dest
11261127
_circshift!(dest, (), src, (), inds, fill_to_length(shiftamt, 0, Val(N)))
11271128
end
11281129

test/arrayops.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ end
748748
@test res === dst == [5 6 4; 2 3 1]
749749
res = circshift!(dst, src, (3.0, 2.0))
750750
@test res === dst == [5 6 4; 2 3 1]
751+
752+
# https://github.com/JuliaLang/julia/issues/41402
753+
src = Float64[]
754+
@test circshift(src, 1) == src
755+
src = zeros(Bool, (4,0))
756+
@test circshift(src, 1) == src
751757
end
752758

753759
@testset "circcopy" begin

0 commit comments

Comments
 (0)