Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sparsearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function Base.show(io::IO, ::MIME"text/plain", sa::AbstractSparseArray)
end
Base.show(io::IO, sa::AbstractSparseArray) = show(io, _data(sa))

Base.eachindex(sa::AbstractSparseArray) = keys(_data(sa))

function Base.firstindex(sa::AbstractSparseArray, d)
return minimum(x -> x[d], _data(sa).indices)
end
Expand All @@ -89,7 +91,7 @@ end
"""
SparseArray{T,N, K <: NTuple{N,Any} }
Implementation of an AbstractSparseArray where data is stored
in a dictionary.
in a dictionary.
"""
struct SparseArray{T,N,K<:NTuple{N,Any}} <: AbstractSparseArray{T,N}
data::Dictionary{K,T}
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ end
@test typeof(SparseArray{Int,3,NTuple{3,String}}()) ==
SparseArray{Int,3,Tuple{String,String,String}}
@test length(SparseArray{Int,3,Tuple{String,String,String}}()) == 0

# indexing
indices = eachindex(car_cost)
@test length(indices) == 5
@test car_cost[first(indices)] == 200
end

@testset "Repurposed from SparseVarArray" begin
Expand Down
Loading