File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -20,14 +20,26 @@ struct StrongPreserving <: ZeroPreserving end
2020struct WeakPreserving <: ZeroPreserving end
2121struct NonPreserving <: ZeroPreserving end
2222
23+ # Backport: remove in 1.12
24+ @static if ! isdefined (Base, :haszero )
25+ _haszero (T:: Type ) = false
26+ _haszero (:: Type{<:Number} ) = true
27+ else
28+ _haszero = Base. haszero
29+ end
30+
2331# warning: cannot automatically detect WeakPreserving since this would mean checking all values
2432function ZeroPreserving (f, A:: AbstractArray , Bs:: AbstractArray... )
2533 return ZeroPreserving (f, eltype (A), eltype .(Bs)... )
2634end
2735# TODO : the following might not properly specialize on the types
2836# TODO : non-concrete element types
2937function ZeroPreserving (f, T:: Type , Ts:: Type... )
30- return iszero (f (zero (T), zero .(Ts)... )) ? WeakPreserving () : NonPreserving ()
38+ if all (_haszero, (T, Ts... ))
39+ return iszero (f (zero (T), zero .(Ts)... )) ? WeakPreserving () : NonPreserving ()
40+ else
41+ return NonPreserving ()
42+ end
3143end
3244
3345const _WEAK_FUNCTIONS = (:+ , :- )
You can’t perform that action at this time.
0 commit comments