Skip to content

Commit e7a1b99

Browse files
authored
Replace LinearAlgebra._iszero by Base.iszero (#36194)
1 parent 0c92375 commit e7a1b99

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

stdlib/LinearAlgebra/src/structuredbroadcast.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ function isstructurepreserving(::typeof(Base.literal_pow), ::Ref{typeof(^)}, ::S
104104
end
105105
isstructurepreserving(f, args...) = false
106106

107-
_iszero(n::Number) = iszero(n)
108-
_iszero(x) = x == 0
109-
fzeropreserving(bc) = (v = fzero(bc); !ismissing(v) && _iszero(v))
107+
fzeropreserving(bc) = (v = fzero(bc); !ismissing(v) && iszero(v))
110108
# Like sparse matrices, we assume that the zero-preservation property of a broadcasted
111109
# expression is stable. We can test the zero-preservability by applying the function
112110
# in cases where all other arguments are known scalars against a zero from the structured

stdlib/LinearAlgebra/test/structuredbroadcast.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,22 @@ end
205205
@test typeof(tmp) <: Tridiagonal
206206

207207
end
208+
209+
struct Zero end
210+
Base.iszero(::Zero) = true
211+
Base.zero(::Type{Zero}) = Zero()
212+
@testset "PR #36193" begin
213+
z = Zero()
214+
Z = [z z
215+
z z]
216+
zz = [z, z]
217+
U = UpperTriangular(Z)
218+
L = LowerTriangular(Z)
219+
D = Diagonal(zz)
220+
for a in [U, L, D]
221+
@test identity.(a) isa typeof(a)
222+
@test map(identity, a) isa typeof(a)
223+
end
224+
end
225+
208226
end

0 commit comments

Comments
 (0)