-
Notifications
You must be signed in to change notification settings - Fork 10
Simplify promote_operation_fallback
#335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e4698ee
109d156
ccb12f8
4d1c87e
97059ac
07ce2fc
aadf53f
777be85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,22 +40,46 @@ function promote_operation_fallback( | |
::Type{S}, | ||
::Type{T}, | ||
) where {S,T} | ||
return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T))) | ||
if isconcretetype(S) && isconcretetype(T) | ||
return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T))) | ||
else | ||
return promote_type(S, T) | ||
end | ||
end | ||
|
||
function promote_operation_fallback( | ||
op::typeof(/), | ||
::Type{S}, | ||
::Type{T}, | ||
) where {S<:Integer,T<:Integer} | ||
if isconcretetype(S) && isconcretetype(T) | ||
return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T))) | ||
else | ||
return promote_type(float(S), float(T)) | ||
end | ||
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))) | ||
if isconcretetype(S) && isconcretetype(T) | ||
return typeof(op(_instantiate_zero(S), _instantiate_zero(T))) | ||
else | ||
return promote_type(S, T) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not covered by tests |
||
end | ||
end | ||
|
||
function promote_operation_fallback( | ||
op::F, | ||
args::Vararg{Type,N}, | ||
) where {F<:Function,N} | ||
return typeof(op(_instantiate_zero.(args)...)) | ||
if all(isconcretetype, args) | ||
return typeof(op(_instantiate_zero.(args)...)) | ||
else | ||
return promote_type(args...) | ||
end | ||
end | ||
|
||
promote_operation_fallback(::typeof(*), ::Type{T}) where {T} = T | ||
|
@@ -103,6 +127,13 @@ function promote_operation_fallback( | |
) | ||
end | ||
|
||
function promote_operation( | ||
::Union{typeof(real),typeof(imag)}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be promote_operation, it's not a fallback |
||
::Type{Complex{T}}, | ||
) where {T} | ||
return T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not covered by tests |
||
end | ||
|
||
""" | ||
promote_operation(op::Function, ArgsTypes::Type...) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered by tests