Skip to content

Commit 2bec113

Browse files
committed
use Base.promote_op in promote_operation_fallback
1 parent 4be0722 commit 2bec113

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/interface.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,23 @@ function promote_operation_fallback(
1717
"`promote_operation($op, $x, $y)` not implemented yet, please report this.",
1818
)
1919
end
20+
2021
function promote_operation_fallback(
21-
::typeof(/),
22+
op::Function,
2223
::Type{S},
2324
::Type{T},
2425
) where {S,T}
25-
return typeof(zero(S) / oneunit(T))
26+
U = Base.promote_op(op, S, T)
27+
return return U == Union{} ? typeof(op(oneunit(S), oneunit(T))) : U
2628
end
2729
# Julia v1.0.x has trouble with inference with the `Vararg` method, see
2830
# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373
29-
function promote_operation_fallback(
30-
op::F,
31-
::Type{S},
32-
::Type{T},
33-
) where {F<:Function,S,T}
34-
return typeof(op(zero(S), zero(T)))
35-
end
3631
function promote_operation_fallback(
3732
op::F,
3833
args::Vararg{Type,N},
3934
) where {F<:Function,N}
40-
return typeof(op(zero.(args)...))
35+
U = Base.promote_op(op, args...)
36+
return return U == Union{} ? typeof(op(oneunit.(args)...)) : U
4137
end
4238
promote_operation_fallback(::typeof(*), ::Type{T}) where {T} = T
4339
function promote_operation_fallback(

0 commit comments

Comments
 (0)