Skip to content

Commit 144ed87

Browse files
authored
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
1 parent 4f3a89e commit 144ed87

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
@@ -1147,6 +1147,7 @@ See also [`circshift`](@ref).
11471147
dest === src && throw(ArgumentError("dest and src must be separate arrays"))
11481148
inds = axes(src)
11491149
axes(dest) == inds || throw(ArgumentError("indices of src and dest must match (got $inds and $(axes(dest)))"))
1150+
isempty(src) && return dest
11501151
_circshift!(dest, (), src, (), inds, fill_to_length(shiftamt, 0, Val(N)))
11511152
end
11521153

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)