@@ -190,11 +190,17 @@ homogenize_shape(shape::Tuple{Vararg{HeterogeneousShape}}) = map(last, shape)
190190@inline function reshape (a:: StaticArray , s:: Tuple{SOneTo,Vararg{SOneTo}} )
191191 return __reshape (a, map (u -> last (u), s), homogenize_shape (s))
192192end
193- @inline function __reshape (a, shape, :: Size{S} ) where {S}
194- return SizedArray {Tuple{S...}} (Base. _reshape (a, shape))
193+ @inline function __reshape (a, shape, s :: Size )
194+ return _maybewrap_reshape (Base. _reshape (a, shape), Size (a), s )
195195end
196- @inline function __reshape (a:: SizedArray , shape, :: Size{S} ) where {S}
197- return SizedArray {Tuple{S...}} (Base. _reshape (a. data, shape))
196+ @inline function __reshape (a:: SizedArray , shape, s:: Size )
197+ return _maybewrap_reshape (Base. _reshape (a. data, shape), Size (a), s)
198+ end
199+ @inline function _maybewrap_reshape (a, :: Size{Sa} , :: Size{S} ) where {Sa,S}
200+ return SizedArray {Tuple{S...}} (a)
201+ end
202+ @inline function _maybewrap_reshape (a:: StaticArray , :: Size{S} , :: Size{S} ) where {S}
203+ return a
198204end
199205
200206reshape (a:: Vector , :: Size{S} ) where {S} = SizedArray {Tuple{S...}} (a)
0 commit comments