Skip to content

Commit 08a15ca

Browse files
OlivierHntdkarrasch
authored andcommitted
Replace v == zero(v) with _iszero (#610)
The purpose of this PR is to not call `==` directly, and use `_iszero` instead. This is to help integration with [IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl) since `==` for our `Interval` type does not always return a Boolean. Closes #609. I did not change two checks using `===` since this would break the behaviour for `-0.0`.
1 parent 7ec2889 commit 08a15ca

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/sparsematrix.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ function (+)(A::Array, B::SparseMatrixCSCUnion)
22832283
for j in axes(B,2)
22842284
for i in nzrange(B, j)
22852285
rowidx = rowinds[i]
2286-
C[rowidx,j] = A[rowidx,j] + nzvals[i]
2286+
C[rowidx,j] = A[rowidx,j] + nzvals[i]
22872287
end
22882288
end
22892289
return C
@@ -2452,7 +2452,7 @@ function Base._mapreduce(f, op::Union{typeof(Base.mul_prod),typeof(*)}, ::Base.I
24522452
else
24532453
v = f(zero(T))^(nzeros)
24542454
# Bail out early if initial reduction value is zero or if there are no stored elements
2455-
(v == zero(T) || nnzA == 0) ? v : v*Base._mapreduce(f, op, nzvalview(A))
2455+
(_iszero(v) || nnzA == 0) ? v : v*Base._mapreduce(f, op, nzvalview(A))
24562456
end
24572457
end
24582458

@@ -4611,6 +4611,6 @@ function copytrito!(M::AbstractMatrix, S::AbstractSparseMatrixCSC, uplo::Char)
46114611
(uplo == 'U' && row <= col) || (uplo == 'L' && row >= col) || continue
46124612
M[row, col] = nz[i]
46134613
end
4614-
end
4614+
end
46154615
return M
46164616
end

src/sparsevector.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ function _spmul!(y::AbstractVector, A::AbstractMatrix, x::AbstractSparseVector,
19321932
"Matrix A has $m rows, but vector y has a length $(length(y))"))
19331933
m == 0 && return y
19341934
β != one(β) && LinearAlgebra._rmul_or_fill!(y, β)
1935-
α == zero(α) && return y
1935+
_iszero(α) && return y
19361936

19371937
xnzind = nonzeroinds(x)
19381938
xnzval = nonzeros(x)
@@ -1960,7 +1960,7 @@ function _At_or_Ac_mul_B!(tfun::Function,
19601960
"Matrix A has $m columns, but vector y has a length $(length(y))"))
19611961
m == 0 && return y
19621962
β != one(β) && LinearAlgebra._rmul_or_fill!(y, β)
1963-
α == zero(α) && return y
1963+
_iszero(α) && return y
19641964

19651965
xnzind = nonzeroinds(x)
19661966
xnzval = nonzeros(x)
@@ -2055,7 +2055,7 @@ function _spmul!(y::AbstractVector, A::AbstractSparseMatrixCSC, x::AbstractSpars
20552055
"Matrix A has $m rows, but vector y has a length $(length(y))"))
20562056
m == 0 && return y
20572057
β != one(β) && LinearAlgebra._rmul_or_fill!(y, β)
2058-
α == zero(α) && return y
2058+
_iszero(α) && return y
20592059

20602060
xnzind = nonzeroinds(x)
20612061
xnzval = nonzeros(x)
@@ -2087,7 +2087,7 @@ function _At_or_Ac_mul_B!(tfun::Function,
20872087
"Matrix A has $m rows, but vector y has a length $(length(y))"))
20882088
n == 0 && return y
20892089
β != one(β) && LinearAlgebra._rmul_or_fill!(y, β)
2090-
α == zero(α) && return y
2090+
_iszero(α) && return y
20912091

20922092
xnzind = nonzeroinds(x)
20932093
xnzval = nonzeros(x)
@@ -2421,7 +2421,7 @@ import Base.fill!
24212421
function fill!(A::Union{AbstractCompressedVector, AbstractSparseMatrixCSC}, x)
24222422
T = eltype(A)
24232423
xT = convert(T, x)
2424-
if xT == zero(T)
2424+
if _iszero(xT)
24252425
fill!(nonzeros(A), xT)
24262426
else
24272427
_fillnonzero!(A, xT)

0 commit comments

Comments
 (0)