Skip to content

Commit f76aff9

Browse files
authored
replace zero checks with iszero (#61)
1 parent fc401ba commit f76aff9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/sparsematrix.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,10 +2102,9 @@ _mapreducerows!(pred::P, ::typeof(&), R::AbstractMatrix{Bool},
21022102

21032103
# findmax/min and argmax/min methods
21042104
# find first zero value in sparse matrix - return linear index in full matrix
2105-
# non-structural zeros are identified by x == 0 in line with the sparse constructors.
2105+
# non-structural zeros are identified by `iszero` in line with the sparse constructors.
21062106
function _findz(A::AbstractSparseMatrixCSC{Tv,Ti}, rows=1:size(A, 1), cols=1:size(A, 2)) where {Tv,Ti}
21072107
colptr = getcolptr(A); rowval = rowvals(A); nzval = nonzeros(A)
2108-
zval = 0
21092108
row = 0
21102109
rowmin = rows[1]; rowmax = rows[end]
21112110
allrows = (rows == 1:size(A, 1))
@@ -2117,7 +2116,7 @@ function _findz(A::AbstractSparseMatrixCSC{Tv,Ti}, rows=1:size(A, 1), cols=1:siz
21172116
(r1 <= r2 ) && (r2 = searchsortedlast(rowval, rowmax, r1, r2, Forward))
21182117
end
21192118
row = rowmin
2120-
while (r1 <= r2) && (row == rowval[r1]) && (nzval[r1] != zval)
2119+
while (r1 <= r2) && (row == rowval[r1]) && !iszero(nzval[r1])
21212120
r1 += 1
21222121
row += 1
21232122
end
@@ -2723,7 +2722,7 @@ function Base.fill!(V::SubArray{Tv, <:Any, <:AbstractSparseMatrixCSC{Tv}, <:Tupl
27232722
if (I[1] < 1 || I[end] > size(A, 1)) || (J[1] < 1 || J[end] > size(A, 2))
27242723
throw(BoundsError(A, (I, J)))
27252724
end
2726-
if x == 0
2725+
if iszero(x)
27272726
_spsetz_setindex!(A, I, J)
27282727
else
27292728
_spsetnz_setindex!(A, convert(Tv, x), I, J)
@@ -3539,7 +3538,7 @@ function is_hermsym(A::AbstractSparseMatrixCSC, check::Function)
35393538
row = rowval[p]
35403539

35413540
# Ignore stored zeros
3542-
if val == 0
3541+
if iszero(val)
35433542
continue
35443543
end
35453544

0 commit comments

Comments
 (0)