Skip to content
Open
Changes from 1 commit
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 number Diff line number Diff 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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should be v == zero(v) of course.

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should be v == zero(v) of course.

Base._delete!(h, index)
else
h.age += 1
Expand Down Expand 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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should be v == zero(v) of course.

d[I] = a[I]
end
return d
Expand Down