diff --git a/Project.toml b/Project.toml index 0ed05bd..f765abd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HybridArrays" uuid = "1baab800-613f-4b0a-84e4-9cd3431bfbb9" authors = ["Mateusz Baran "] -version = "0.4.15" +version = "0.4.16" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/abstractarray.jl b/src/abstractarray.jl index bb20833..ad8871e 100644 --- a/src/abstractarray.jl +++ b/src/abstractarray.jl @@ -69,6 +69,14 @@ similar(::Type{<:HybridArray{S,T,N,M}},::Type{T2}) where {S,T,N,M,T2} = HybridAr similar(::Type{SA},::Type{T},s::Size{S}) where {SA<:HybridArray,T,S} = hybridarray_similar_type(T,s,StaticArrays.length_val(s))(undef) hybridarray_similar_type(::Type{T},s::Size{S},::Type{Val{D}}) where {T,S,D} = HybridArray{Tuple{S...},T,D,length(s)} +#disambiguation +function similar(a::HybridArray, t::Type{T2}, i::Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}) where T2 + return invoke(similar, Tuple{AbstractArray, Type, Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}}, a, t, i) +end +function similar(a::HybridArray, t::Type{T2}, i::Tuple{Int64, Vararg{Int64}}) where T2 + return invoke(similar, Tuple{AbstractArray, Type, Tuple{Int64, Vararg{Int64}}}, a, t, i) +end + # for internal use only (used in vcat and hcat) # TODO: try to make this less hacky # adding method to similar_type ends up being used in broadcasting for some reason? diff --git a/test/abstractarray.jl b/test/abstractarray.jl index e20f091..984bca5 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -138,4 +138,12 @@ using StaticArrays: Dynamic @test isa(M3, HybridArray{Tuple{Dynamic(),3,4},Int,3,3,Array{Int,3}}) @test size(M3) === (5, 3, 4) end + + @testset "getindex" begin + A = HybridArray{Tuple{2,2,StaticArrays.Dynamic()}}(randn(2,2,100)) + B = A[1:2] + @test B isa Vector + @test A[1] == B[1] + @test A[2] == B[2] + end end