Skip to content

Commit

Permalink
Replace LinearAlgebra._iszero by Base.iszero (#36194)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Jun 12, 2020
1 parent 0c92375 commit e7a1b99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions stdlib/LinearAlgebra/src/structuredbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ function isstructurepreserving(::typeof(Base.literal_pow), ::Ref{typeof(^)}, ::S
end
isstructurepreserving(f, args...) = false

_iszero(n::Number) = iszero(n)
_iszero(x) = x == 0
fzeropreserving(bc) = (v = fzero(bc); !ismissing(v) && _iszero(v))
fzeropreserving(bc) = (v = fzero(bc); !ismissing(v) && iszero(v))
# Like sparse matrices, we assume that the zero-preservation property of a broadcasted
# expression is stable. We can test the zero-preservability by applying the function
# in cases where all other arguments are known scalars against a zero from the structured
Expand Down
18 changes: 18 additions & 0 deletions stdlib/LinearAlgebra/test/structuredbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,22 @@ end
@test typeof(tmp) <: Tridiagonal

end

struct Zero end
Base.iszero(::Zero) = true
Base.zero(::Type{Zero}) = Zero()
@testset "PR #36193" begin
z = Zero()
Z = [z z
z z]
zz = [z, z]
U = UpperTriangular(Z)
L = LowerTriangular(Z)
D = Diagonal(zz)
for a in [U, L, D]
@test identity.(a) isa typeof(a)
@test map(identity, a) isa typeof(a)
end
end

end

0 comments on commit e7a1b99

Please sign in to comment.