@@ -96,17 +96,20 @@ reshape(parent::AbstractArray, dims::Int...) = reshape(parent, dims)
96
96
reshape (parent:: AbstractArray , dims:: Union{Int,Colon} ...) = reshape (parent, dims)
97
97
reshape (parent:: AbstractArray , dims:: Tuple{Vararg{Union{Int,Colon}}} ) = _reshape (parent, _reshape_uncolon (parent, dims))
98
98
@inline function _reshape_uncolon (A, dims)
99
- pre, post = _split_at_colon ((), dims... )
99
+ pre = _before_colon (dims... )
100
+ post = _after_colon (dims... )
100
101
if any (d -> d isa Colon, post)
101
102
throw (DimensionMismatch (" new dimensions $(dims) may have at most one omitted dimension specified by Colon()" ))
102
103
end
103
104
sz, remainder = divrem (length (A), prod (pre)* prod (post))
104
105
remainder == 0 || _throw_reshape_colon_dimmismatch (A, dims)
105
106
(pre... , sz, post... )
106
107
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) =
110
113
throw (DimensionMismatch (" array size $(length (A)) must be divisible by the product of the new dimensions $dims " ))
111
114
112
115
reshape (parent:: AbstractArray{T,N} , ndims:: Type{Val{N}} ) where {T,N} = parent
0 commit comments