Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/sparsearray.jl
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ Base.@propagate_inbounds Base.getindex(a::SparseArray{T,N}, I::Vararg{Int,N}) wh

@inline function Base.setindex!(a::SparseArray{T,N}, v, I::CartesianIndex{N}) where {T,N}
@boundscheck checkbounds(a, I)
if !iszero(v)
if v !== zero(v)
a.data[I] = v
else
delete!(a.data, I) # does not do anything if there was no key corresponding to I
Expand All@@ -44,14 +44,14 @@ Base.@propagate_inbounds Base.setindex!(a::SparseArray{T,N},

@inline function increaseindex!(a::SparseArray{T,N}, v, I::CartesianIndex{N}) where {T,N}
@boundscheck checkbounds(a, I)
iszero(v) && return
v == zero(v) && return
h = a.data
index = Base.ht_keyindex2!(h, I)
@inbounds begin
if index > 0
currentv = h.vals[index]
newv = currentv + convert(T, v)
if iszero(newv)
if v == zero(newv)
Base._delete!(h, index)
else
h.age += 1
Expand DownExpand Up@@ -110,7 +110,7 @@ SparseArray{T}(a::AbstractArray{<:Any,N}) where {T,N} = SparseArray{T,N}(a)
function SparseArray{T,N}(a::AbstractArray{<:Any,N}) where {T,N}
d = SparseArray{T,N}(undef, size(a))
for I in CartesianIndices(a)
iszero(a[I]) && continue
v == zero(a[I]) && continue
d[I] = a[I]
end
return d
Expand Down