@@ -20,19 +20,24 @@ v = SparseContainer((a1,a2,a3,a4), (1,3,5,7))
2020@test v[7] == ones(3) .* 4
2121```
2222"""
23- struct SparseContainer{ET, SIM, T}
23+ struct SparseContainer{SIM, T}
2424 data:: T
25- function SparseContainer (compressed_data:: T , sparse_index_map:: Tuple ) where {T}
25+ function SparseContainer (
26+ compressed_data:: T ,
27+ sparse_index_map:: Tuple
28+ ) where {N, ET, T <: NTuple{N, ET} }
2629 @assert all (map (x-> eltype (compressed_data) .== typeof (x), compressed_data))
27- return new {eltype(compressed_data), sparse_index_map, T} (compressed_data)
30+ return new {sparse_index_map, T} (compressed_data)
2831 end
2932end
3033
3134Base. parent (sc:: SparseContainer ) = sc. data
32- @inline function Base. getindex (sc:: SparseContainer{ET} , i:: Int ) where {ET}
33- return _getindex_sparse (sc, Val (i)):: ET
35+ sc_eltype (:: Type{NTuple{N, T}} ) where {N, T} = T
36+ sc_eltype (:: SparseContainer{SIM, T} ) where {SIM, T} = sc_eltype (T)
37+ @inline function Base. getindex (sc:: SparseContainer , i:: Int )
38+ return _getindex_sparse (sc, Val (i)):: sc_eltype (sc)
3439end
35- @generated function _getindex_sparse (sc:: SparseContainer{ET, SIM} , :: Val{i} ):: ET where {ET, SIM, i}
40+ @generated function _getindex_sparse (sc:: SparseContainer{SIM} , :: Val{i} ) where {SIM, i}
3641 j = findfirst (k -> k == i, SIM)
3742 j == nothing && error (" No index $i found in sparse index map $(SIM) " )
3843 return :(sc. data[$ j])
0 commit comments