Skip to content

Commit 0c10641

Browse files
authored
Revert "Replace LinearAlgebra._iszero by Base.iszero" (#38764)
* Revert "Replace LinearAlgebra._iszero by Base.iszero (#36194)" This reverts commit e7a1b99. * add test
1 parent 2f5fb47 commit 0c10641

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

stdlib/LinearAlgebra/src/structuredbroadcast.jl

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

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

stdlib/LinearAlgebra/test/structuredbroadcast.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,7 @@ end
206206

207207
end
208208

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
209+
# structured broadcast with function returning non-number type
210+
@test tuple.(Diagonal([1, 2])) == [(1,) (0,); (0,) (2,)]
225211

226212
end

0 commit comments

Comments
 (0)