Skip to content

Commit

Permalink
Fix #65
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Jul 21, 2023
1 parent eb63140 commit cf86d57
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HybridArrays"
uuid = "1baab800-613f-4b0a-84e4-9cd3431bfbb9"
authors = ["Mateusz Baran <mateuszbaran89@gmail.com>"]
version = "0.4.15"
version = "0.4.16"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
8 changes: 8 additions & 0 deletions src/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 8 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cf86d57

Please sign in to comment.