Skip to content

Commit

Permalink
use Base.promote_op in promote_operation_fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Feb 6, 2022
1 parent ea4b5cb commit 0a8d40c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ function promote_operation_fallback(op::Function, x::Type{<:AbstractArray}, y::T
# We replace it by a more helpful error here.
error("`promote_operation($op, $x, $y)` not implemented yet, please report this.")
end
function promote_operation_fallback(::typeof(/), ::Type{S}, ::Type{T}) where {S,T}
return typeof(zero(S) / oneunit(T))

function promote_operation_fallback(
op::Function,
::Type{S},
::Type{T},
) where {S,T}
U = Base.promote_op(op, S, T)
return return U == Union{} ? typeof(op(oneunit(S), oneunit(T))) : U
end
# Julia v1.0.x has trouble with inference with the `Vararg` method, see
# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373
function promote_operation_fallback(op::F, ::Type{S}, ::Type{T}) where {F<:Function,S,T}
return typeof(op(zero(S), zero(T)))
end
function promote_operation_fallback(op::F, args::Vararg{Type,N}) where {F<:Function,N}
return typeof(op(zero.(args)...))
function promote_operation_fallback(
op::F,
args::Vararg{Type,N},
) where {F<:Function,N}
U = Base.promote_op(op, args...)
return return U == Union{} ? typeof(op(oneunit.(args)...)) : U
end
promote_operation_fallback(::typeof(*), ::Type{T}) where {T} = T
function promote_operation_fallback(
Expand Down

0 comments on commit 0a8d40c

Please sign in to comment.