Skip to content

Commit

Permalink
Fix missing iszero usage in linalg functions (#29668)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalum authored and StefanKarpinski committed Oct 16, 2018
1 parent 18b9fc2 commit 870f995
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ end
for i = 2:n
normu += abs2(x[i])
end
if normu == zero(normu)
if iszero(normu)
return zero(ξ1/normu)
end
normu = sqrt(normu)
Expand Down
12 changes: 6 additions & 6 deletions stdlib/LinearAlgebra/src/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ function naivesub!(A::UpperTriangular, b::AbstractVector, x::AbstractVector = b)
throw(DimensionMismatch("second dimension of left hand side A, $n, length of output x, $(length(x)), and length of right hand side b, $(length(b)), must be equal"))
end
@inbounds for j in n:-1:1
A.data[j,j] == zero(A.data[j,j]) && throw(SingularException(j))
iszero(A.data[j,j]) && throw(SingularException(j))
xj = x[j] = A.data[j,j] \ b[j]
for i in j-1:-1:1 # counterintuitively 1:j-1 performs slightly better
b[i] -= A.data[i,j] * xj
Expand Down Expand Up @@ -1173,7 +1173,7 @@ function naivesub!(A::LowerTriangular, b::AbstractVector, x::AbstractVector = b)
throw(DimensionMismatch("second dimension of left hand side A, $n, length of output x, $(length(x)), and length of right hand side b, $(length(b)), must be equal"))
end
@inbounds for j in 1:n
A.data[j,j] == zero(A.data[j,j]) && throw(SingularException(j))
iszero(A.data[j,j]) && throw(SingularException(j))
xj = x[j] = A.data[j,j] \ b[j]
for i in j+1:n
b[i] -= A.data[i,j] * xj
Expand Down Expand Up @@ -1209,7 +1209,7 @@ function ldiv!(transA::Transpose{<:Any,<:LowerTriangular}, b::AbstractVector, x:
for i in n:-1:j+1
z -= A.data[i,j] * x[i]
end
A.data[j,j] == zero(A.data[j,j]) && throw(SingularException(j))
iszero(A.data[j,j]) && throw(SingularException(j))
x[j] = A.data[j,j] \ z
end
x
Expand Down Expand Up @@ -1246,7 +1246,7 @@ function ldiv!(transA::Transpose{<:Any,<:UpperTriangular}, b::AbstractVector, x:
for i in 1:j-1
z -= A.data[i,j] * x[i]
end
A.data[j,j] == zero(A.data[j,j]) && throw(SingularException(j))
iszero(A.data[j,j]) && throw(SingularException(j))
x[j] = A.data[j,j] \ z
end
x
Expand Down Expand Up @@ -1283,7 +1283,7 @@ function ldiv!(adjA::Adjoint{<:Any,<:LowerTriangular}, b::AbstractVector, x::Abs
for i in n:-1:j+1
z -= A.data[i,j]' * x[i]
end
A.data[j,j] == zero(A.data[j,j]) && throw(SingularException(j))
iszero(A.data[j,j]) && throw(SingularException(j))
x[j] = A.data[j,j]' \ z
end
x
Expand Down Expand Up @@ -1320,7 +1320,7 @@ function ldiv!(adjA::Adjoint{<:Any,<:UpperTriangular}, b::AbstractVector, x::Abs
for i in 1:j-1
z -= A.data[i,j]' * x[i]
end
A.data[j,j] == zero(A.data[j,j]) && throw(SingularException(j))
iszero(A.data[j,j]) && throw(SingularException(j))
x[j] = A.data[j,j]' \ z
end
x
Expand Down

0 comments on commit 870f995

Please sign in to comment.