Skip to content

Commit

Permalink
Specialize haszero for Union{Missing,<:Number} types
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Oct 15, 2024
1 parent fe82988 commit d01e1a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ norm2(x::Union{Array{T},StridedVector{T}}) where {T<:BlasFloat} =
# Conservative assessment of types that have zero(T) defined for themselves
haszero(::Type) = false
haszero(::Type{T}) where {T<:Number} = isconcretetype(T)
haszero(::Type{Union{Missing,T}}) where {T<:Number} = haszero(T)
@propagate_inbounds _zero(M::AbstractArray{T}, inds...) where {T} = haszero(T) ? zero(T) : zero(M[inds...])

"""
Expand Down
8 changes: 8 additions & 0 deletions stdlib/LinearAlgebra/test/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,14 @@ end
@test istril(U, k) == istril(A, k)
end
end

@testset "Union eltype" begin
M = Matrix{Union{Int,Missing}}(missing,2,2)
U = triu(M)
@test iszero(U[2,1])
U = tril(M)
@test iszero(U[1,2])
end
end

@testset "indexing with a BandIndex" begin
Expand Down

0 comments on commit d01e1a1

Please sign in to comment.