Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,11 @@ function promote_operation_fallback(
)
end

_instantiate_zero(::Type{S}) where {S} = zero(S)
_instantiate_oneunit(::Type{S}) where {S} = oneunit(S)

# this is valid because Irrational numbers are defined in global scope as const
_instantiate(::Type{S}) where {S<:Irrational} = S()
_instantiate_zero(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S)
_instantiate_oneunit(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S)

# 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::Union{typeof(/),typeof(div)},
::Type{S},
::Type{T},
) where {S,T}
return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T)))
end

function promote_operation_fallback(
op::F,
::Type{S},
::Type{T},
) where {F<:Function,S,T}
return typeof(op(_instantiate_zero(S), _instantiate_zero(T)))
end

function promote_operation_fallback(
op::F,
::F,
args::Vararg{Type,N},
) where {F<:Function,N}
return typeof(op(_instantiate_zero.(args)...))
return promote_type(args...)
end

promote_operation_fallback(::typeof(*), ::Type{T}) where {T} = T
Expand Down
2 changes: 1 addition & 1 deletion test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
@test y == 5
# FIXME This should not allocate but I couldn't figure out where these
# allocations come from.
n = (VERSION >= v"1.11" ? 42 : 30) * sizeof(Int)
n = (VERSION >= v"1.11" ? 14 : 10) * sizeof(Int)
alloc_test(() -> MA.broadcast!!(+, a, b), n)
alloc_test(() -> MA.broadcast!!(+, a, c), 0)
end
Expand Down
5 changes: 0 additions & 5 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ Base.@irrational theodorus 1.73205080756887729353 sqrt(big(3))
i_theodorus() = MA.promote_operation(+, Int, typeof(theodorus))
@test i_theodorus() == Float64
alloc_test(i_theodorus, 0)
# test _instantiate(::Type{S}) where {S<:Irrational} return value
@test MA._instantiate(typeof(π)) == π
@test MA._instantiate(typeof(MathConstants.catalan)) ==
MathConstants.catalan
@test MA._instantiate(typeof(theodorus)) == theodorus
end
end

Expand Down
Loading