File tree Expand file tree Collapse file tree 2 files changed +4
-1
lines changed Expand file tree Collapse file tree 2 files changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,8 @@ norm2(x::Union{Array{T},StridedVector{T}}) where {T<:BlasFloat} =
114114Return whether a type `T` has a unique zero element defined using `zero(T)`.
115115If a type `M` specializes `zero(M)`, it may also choose to set `haszero(M)` to `true`.
116116By default, `haszero` is assumed to be `false`, in which case the zero elements
117- are deduced from values rather than the type.
117+ are deduced from values rather than the type. In general, if a type defines `zero(::Type{MyType})`,
118+ it should also define `haszero(::Type{MyType}) = true`.
118119
119120!!! note
120121 `haszero` is a conservative check that is used to dispatch to
Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ Random.seed!(1)
115115 struct TypeWithZero end
116116 Base. promote_rule (:: Type{TypeWithoutZero} , :: Type{TypeWithZero} ) = TypeWithZero
117117 Base. convert (:: Type{TypeWithZero} , :: TypeWithoutZero ) = TypeWithZero ()
118+ LinearAlgebra. haszero (:: Type{TypeWithoutZero} ) = true
119+ LinearAlgebra. haszero (:: Type{TypeWithZero} ) = true
118120 Base. zero (x:: Union{TypeWithoutZero, TypeWithZero} ) = zero (typeof (x))
119121 Base. zero (:: Type{<:Union{TypeWithoutZero, TypeWithZero}} ) = TypeWithZero ()
120122 LinearAlgebra. symmetric (:: TypeWithoutZero , :: Symbol ) = TypeWithoutZero ()
You can’t perform that action at this time.
0 commit comments