diff --git a/src/abstractarray.jl b/src/abstractarray.jl index d45aead4..14f74904 100644 --- a/src/abstractarray.jl +++ b/src/abstractarray.jl @@ -86,9 +86,9 @@ similar_type(::Type{SA},::Type{T},s::Size{S}) where {SA<:Union{MVector,MMatrix,M mutable_similar_type(::Type{T}, s::Size{S}, ::Type{Val{D}}) where {T,S,D} = MArray{Tuple{S...},T,D,prod(s)} -# Should `SizedArray` stay the same, and also take over an `Array`? -#similar_type{SA<:SizedArray,T,S}(::Type{SA},::Type{T},s::Size{S}) = sizedarray_similar_type(T,s,length_val(s)) -#similar_type{A<:Array,T,S}(::Type{A},::Type{T},s::Size{S}) = sizedarray_similar_type(T,s,length_val(s)) +similar_type(::Type{<:SizedArray},::Type{T},s::Size{S}) where {S,T} = sizedarray_similar_type(T,s,length_val(s)) +# Should SizedArray also be used for normal Array? +#similar_type(::Type{<:Array},::Type{T},s::Size{S}) where {S,T} = sizedarray_similar_type(T,s,length_val(s)) sizedarray_similar_type(::Type{T},s::Size{S},::Type{Val{D}}) where {T,S,D} = SizedArray{Tuple{S...},T,D,length(s)} @@ -238,4 +238,3 @@ end @inbounds return similar_type(a, promote_type(eltype(a), eltype(b)), Size($Snew))(tuple($(exprs...))) end end - diff --git a/test/SizedArray.jl b/test/SizedArray.jl index 3644b7d9..27d573ac 100644 --- a/test/SizedArray.jl +++ b/test/SizedArray.jl @@ -99,4 +99,12 @@ @test @inferred(promote_type(SizedVector{2,Int,1}, SizedVector{2,Float64,1})) === SizedVector{2,Float64,1} @test @inferred(promote_type(SizedMatrix{2,3,Float32,2}, SizedMatrix{2,3,Complex{Float64},2})) === SizedMatrix{2,3,Complex{Float64},2} end + + @testset "reshaping" begin + y = rand(4,1,2) + sy = SizedArray{Tuple{size(y)...}}(y) + + @test vec(sy) isa SizedArray{Tuple{8}, Float64} + @test reshape(sy, Size(2,4)) isa SizedArray{Tuple{2, 4}, Float64} + end end