Skip to content

Commit b265dba

Browse files
authored
fix zero-dimensional reverse! (JuliaLang#58086)
Also changed the check to compare against the tuple argument, instead of against the method static parameter for the tuple length. Should be better when the length isn't known at compile time. Fixes JuliaLang#58085
1 parent 92cceb0 commit b265dba

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

base/arraymath.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ _reverse!(A::AbstractArray{<:Any,N}, ::Colon) where {N} = _reverse!(A, ntuple(id
7272
_reverse!(A, dim::Integer) = _reverse!(A, (Int(dim),))
7373
_reverse!(A, dims::NTuple{M,Integer}) where {M} = _reverse!(A, Int.(dims))
7474
function _reverse!(A::AbstractArray{<:Any,N}, dims::NTuple{M,Int}) where {N,M}
75+
dims === () && return A # nothing to reverse
7576
dimrev = ntuple(k -> k in dims, Val{N}()) # boolean tuple indicating reversed dims
7677

7778
if N < M || M != sum(dimrev)
7879
throw(ArgumentError("invalid dimensions $dims in reverse!"))
7980
end
80-
M == 0 && return A # nothing to reverse
8181

8282
# swapping loop only needs to traverse ≈half of the array
8383
halfsz = ntuple(k -> k == dims[1] ? size(A,k) ÷ 2 : size(A,k), Val{N}())

test/arrayops.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,12 @@ end
17611761
end
17621762
end
17631763

1764+
@testset "reverse zero dims" begin
1765+
a = fill(3)
1766+
@test a == reverse(a)
1767+
@test a === reverse!(a)
1768+
end
1769+
17641770
@testset "isdiag, istril, istriu" begin
17651771
# Scalar
17661772
@test isdiag(3)

0 commit comments

Comments
 (0)