Skip to content

Commit 0a8d40c

Browse files
committed
use Base.promote_op in promote_operation_fallback
1 parent ea4b5cb commit 0a8d40c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/interface.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ function promote_operation_fallback(op::Function, x::Type{<:AbstractArray}, y::T
1111
# We replace it by a more helpful error here.
1212
error("`promote_operation($op, $x, $y)` not implemented yet, please report this.")
1313
end
14-
function promote_operation_fallback(::typeof(/), ::Type{S}, ::Type{T}) where {S,T}
15-
return typeof(zero(S) / oneunit(T))
14+
15+
function promote_operation_fallback(
16+
op::Function,
17+
::Type{S},
18+
::Type{T},
19+
) where {S,T}
20+
U = Base.promote_op(op, S, T)
21+
return return U == Union{} ? typeof(op(oneunit(S), oneunit(T))) : U
1622
end
1723
# Julia v1.0.x has trouble with inference with the `Vararg` method, see
1824
# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373
19-
function promote_operation_fallback(op::F, ::Type{S}, ::Type{T}) where {F<:Function,S,T}
20-
return typeof(op(zero(S), zero(T)))
21-
end
22-
function promote_operation_fallback(op::F, args::Vararg{Type,N}) where {F<:Function,N}
23-
return typeof(op(zero.(args)...))
25+
function promote_operation_fallback(
26+
op::F,
27+
args::Vararg{Type,N},
28+
) where {F<:Function,N}
29+
U = Base.promote_op(op, args...)
30+
return return U == Union{} ? typeof(op(oneunit.(args)...)) : U
2431
end
2532
promote_operation_fallback(::typeof(*), ::Type{T}) where {T} = T
2633
function promote_operation_fallback(

0 commit comments

Comments
 (0)