-
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
Simplify promote_operation_fallback
#335
Conversation
68975a9
to
f99b96a
Compare
The JuMP tests fail because MA.promote_operation(MA.add_mul, QuadExpr, Int, GenericQuadExpr{ComplexF64, VariableRef}) returns GenericQuadExpr{CoefType, VariableRef} where CoefType instead of GenericQuadExpr{ComplexF64, VariableRef} as it did before |
The answer should be |
We can fix it with a PR to JuMP. At the moment, it's a performance issue with JuMP since the corresponding |
Do you mean this method? julia> using JuMP
julia> import JuMP._MA as MA
julia> begin
model = Model()
@variable(model, x)
ret = zero(QuadExpr)
f = (1.0 + 2.0im) * x^2
MA.add_mul(ret, 2, f)
end
(2 + 4im) x² What do you want to fix in JuMP? |
In JuMP, |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #335 +/- ##
==========================================
+ Coverage 90.50% 90.55% +0.05%
==========================================
Files 22 22
Lines 2253 2265 +12
==========================================
+ Hits 2039 2051 +12
Misses 214 214 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Should be fixed by jump-dev/JuMP.jl#4057 |
f99b96a
to
2e089c2
Compare
61de1dd
to
8d48c21
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered by tests
if isconcretetype(S) && isconcretetype(T) | ||
return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T))) | ||
else | ||
return promote_type(S, T) |
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
::Union{typeof(real),typeof(imag)}, | ||
::Type{Complex{T}}, | ||
) where {T} | ||
return T |
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
src/interface.jl
Outdated
::Type{S}, | ||
::Type{LinearAlgebra.UniformScaling{T}}, | ||
) where {S,T} | ||
return promote_operation(op, S, T) |
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.
How is this related to this PR ?
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.
promote_type(Number, LinearAlgebra.UniformScaling{Bool})
ends up as Any
, which is incorrect.
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.
Actually, this is avoidable
afc95c1
to
aaa3e5c
Compare
end | ||
|
||
function promote_operation_fallback( | ||
::Union{typeof(real),typeof(imag)}, |
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.
This should be promote_operation, it's not a fallback
Co-authored-by: Benoît Legat <benoit.legat@gmail.com>
aaa3e5c
to
777be85
Compare
Continuation of #334