Skip to content

Commit 1a53c13

Browse files
Rm duplicate type information in SparseContainers
1 parent bc73858 commit 1a53c13

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/sparse_containers.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2932
end
3033

3134
Base.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)
3439
end
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

Comments
 (0)