Skip to content

Commit e839b0e

Browse files
committed
eliminate another turing machines from reshapedarray
1 parent fc1b896 commit e839b0e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

base/reshapedarray.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ reshape(parent::AbstractArray, dims::Int...) = reshape(parent, dims)
9696
reshape(parent::AbstractArray, dims::Union{Int,Colon}...) = reshape(parent, dims)
9797
reshape(parent::AbstractArray, dims::Tuple{Vararg{Union{Int,Colon}}}) = _reshape(parent, _reshape_uncolon(parent, dims))
9898
@inline function _reshape_uncolon(A, dims)
99-
pre, post = _split_at_colon((), dims...)
99+
pre = _before_colon(dims...)
100+
post = _after_colon(dims...)
100101
if any(d -> d isa Colon, post)
101102
throw(DimensionMismatch("new dimensions $(dims) may have at most one omitted dimension specified by Colon()"))
102103
end
103104
sz, remainder = divrem(length(A), prod(pre)*prod(post))
104105
remainder == 0 || _throw_reshape_colon_dimmismatch(A, dims)
105106
(pre..., sz, post...)
106107
end
107-
@inline _split_at_colon(pre, dim::Any, tail...) = _split_at_colon((pre..., dim), tail...)
108-
@inline _split_at_colon(pre, ::Colon, tail...) = (pre, tail)
109-
_throw_reshape_colon_dimmismatch(A, dims) =
108+
@inline _before_colon(dim::Any, tail...) = (dim, _before_colon(tail...)...)
109+
@inline _before_colon(dim::Colon, tail...) = ()
110+
@inline _after_colon(dim::Any, tail...) = _after_colon(tail...)
111+
@inline _after_colon(dim::Colon, tail...) = tail
112+
@noinline _throw_reshape_colon_dimmismatch(A, dims) =
110113
throw(DimensionMismatch("array size $(length(A)) must be divisible by the product of the new dimensions $dims"))
111114

112115
reshape(parent::AbstractArray{T,N}, ndims::Type{Val{N}}) where {T,N} = parent

0 commit comments

Comments
 (0)