Skip to content

Commit

Permalink
Improve error message when source length is wrong in reshape (#53883)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Mar 28, 2024
1 parent 2a944fa commit 6f51966
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ end
reshape(B::BitArray, dims::Tuple{Vararg{Int}}) = _bitreshape(B, dims)
function _bitreshape(B::BitArray, dims::NTuple{N,Int}) where N
prod(dims) == length(B) ||
throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(B))"))
throw(DimensionMismatch("new dimensions $(dims) must be consistent with array length $(length(B))"))
Br = BitArray{N}(undef, ntuple(i->0,Val(N))...)
Br.chunks = B.chunks
Br.len = prod(dims)
Expand Down
2 changes: 1 addition & 1 deletion base/reshapedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ eltype(::Type{<:ReshapedArrayIterator{I}}) where {I} = @isdefined(I) ? ReshapedI
# reshaping to same # of dimensions
@eval function reshape(a::Array{T,M}, dims::NTuple{N,Int}) where {T,N,M}
throw_dmrsa(dims, len) =
throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $len"))
throw(DimensionMismatch("new dimensions $(dims) must be consistent with array length $len"))
len = Core.checked_dims(dims...) # make sure prod(dims) doesn't overflow (and because of the comparison to length(a))
if len != length(a)
throw_dmrsa(dims, length(a))
Expand Down

0 comments on commit 6f51966

Please sign in to comment.