Skip to content
Merged
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
31 changes: 1 addition & 30 deletions src/ndsparsearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,52 +64,23 @@ function NDSparseArray(A::AbstractArray{T, N}; atol::Real = 0) where {T, N}
return sparse_array
end

# Required AbstractArray interface
Base.size(A::NDSparseArray) = A.dims
Base.IndexStyle(::Type{<:NDSparseArray}) = IndexCartesian()

# Linear indexing support
@inline function Base.getindex(A::NDSparseArray, i::Int)
@boundscheck checkbounds(A, i)
idx = CartesianIndices(A)[i]
haskey(A.data, idx) || throw(BoundsError(A, i))
return A.data[idx]
end

@inline function Base.setindex!(A::NDSparseArray, val, i::Int)
@boundscheck checkbounds(A, i)
idx = CartesianIndices(A)[i]
A.data[idx] = val
return val
end

# Indexing
# Indexing methods
@inline function Base.getindex(A::NDSparseArray{T, N}, I::Vararg{Int, N}) where {T, N}
@boundscheck checkbounds(A, I...)
idx = CartesianIndex(I)
haskey(A.data, idx) || throw(BoundsError(A, I))
return A.data[idx]
end

@inline function Base.getindex(A::NDSparseArray, I::CartesianIndex)
@boundscheck checkbounds(A, I)
haskey(A.data, I) || throw(BoundsError(A, I))
return A.data[I]
end

@inline function Base.setindex!(A::NDSparseArray{T, N}, val, I::Vararg{Int, N}) where {T, N}
@boundscheck checkbounds(A, I...)
idx = CartesianIndex(I)
A.data[idx] = val
return val
end

@inline function Base.setindex!(A::NDSparseArray, val, I::CartesianIndex)
@boundscheck checkbounds(A, I)
A.data[I] = val
return val
end

# Delete methods
"""
delete!(A::NDSparseArray, I...)
Expand Down
Loading