Skip to content

Commit

Permalink
fix issue pointed out by N5N3
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko committed Apr 29, 2024
1 parent 0dd2390 commit 30823c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions base/reshapedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,19 @@ reshape(parent::AbstractArray, dims::Tuple{Vararg{Union{Int,Colon}}}) = reshape(
_any_colon(post...) && throw1(dims)
post::Tuple{Vararg{Int}}
len = length(A)
sz, remainder = if iszero(len)
(0, 0)
sz, is_exact = if iszero(len)
(0, true)
else
let pr = Core.checked_dims(pre..., post...) # safe product
if iszero(pr)
throw2(A, dims)
end
divrem(len, pr)
(quo, rem) = divrem(len, pr)
(Int(quo), iszero(rem))
end
end::NTuple{2,Int}
remainder == 0 || throw2(A, dims)
(pre..., Int(sz), post...)::Tuple{Int,Vararg{Int}}
end::Tuple{Int,Bool}
is_exact || throw2(A, dims)
(pre..., sz, post...)::Tuple{Int,Vararg{Int}}
end
@inline _any_colon() = false
@inline _any_colon(dim::Colon, tail...) = true
Expand Down
8 changes: 8 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,14 @@ end
@test_throws ArgumentError reshape([7], (b, :, b))
@test reshape([], (b, :, b)) isa Array{<:Any, 3}
end
for iterator (7:6, 7:7, 7:8)
for it (iterator, map(BigInt, iterator))
@test reshape(it, (:, Int(length(it)))) isa AbstractMatrix
@test reshape(it, (Int(length(it)), :)) isa AbstractMatrix
@test reshape(it, (1, :)) isa AbstractMatrix
@test reshape(it, (:, 1)) isa AbstractMatrix
end
end
end

@testset "strides for ReshapedArray" begin
Expand Down

0 comments on commit 30823c9

Please sign in to comment.