Skip to content

Commit d4f8d2e

Browse files
committed
use Base.promote_op in promote_operation_fallback
1 parent 6833e46 commit d4f8d2e

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/interface.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,22 @@ function promote_operation_fallback(
2020
end
2121

2222
function promote_operation_fallback(
23-
::typeof(/),
23+
op::Function,
2424
::Type{S},
2525
::Type{T},
2626
) where {S,T}
27-
return typeof(zero(S) / oneunit(T))
27+
U = Base.promote_op(op, S, T)
28+
return return U == Union{} ? typeof(op(oneunit(S), oneunit(T))) : U
2829
end
2930

3031
# Julia v1.0.x has trouble with inference with the `Vararg` method, see
3132
# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373
32-
function promote_operation_fallback(
33-
op::F,
34-
::Type{S},
35-
::Type{T},
36-
) where {F<:Function,S,T}
37-
return typeof(op(zero(S), zero(T)))
38-
end
39-
4033
function promote_operation_fallback(
4134
op::F,
4235
args::Vararg{Type,N},
4336
) where {F<:Function,N}
44-
return typeof(op(zero.(args)...))
37+
U = Base.promote_op(op, args...)
38+
return return U == Union{} ? typeof(op(oneunit.(args)...)) : U
4539
end
4640

4741
promote_operation_fallback(::typeof(*), ::Type{T}) where {T} = T

0 commit comments

Comments
 (0)