Skip to content
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

Implement value for GenericQuadExpr. #1588

Merged
merged 5 commits into from
Nov 8, 2018
Merged

Implement value for GenericQuadExpr. #1588

merged 5 commits into from
Nov 8, 2018

Conversation

odow
Copy link
Member

@odow odow commented Nov 7, 2018

Closes #1563

@codecov
Copy link

codecov bot commented Nov 7, 2018

Codecov Report

Merging #1588 into master will increase coverage by 0.15%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1588      +/-   ##
==========================================
+ Coverage    90.8%   90.95%   +0.15%     
==========================================
  Files          28       28              
  Lines        3696     3769      +73     
==========================================
+ Hits         3356     3428      +72     
- Misses        340      341       +1
Impacted Files Coverage Δ
src/quad_expr.jl 91.46% <85.71%> (-0.54%) ⬇️
src/variables.jl 95.15% <0%> (+1.98%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6daac7a...4a56ac4. Read the comment docs.

src/quad_expr.jl Outdated
# Later, we're going to multiply two MapVarType together
MapVarType2 = Base.promote_op(*, MapVarType, MapVarType)
# We're also going to multiply a constant with ::MapVarType2
RetType = Base.promote_op(*, CoefType, MapVarType2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was once told that it is not safe to call promote_op on top of promote_op, see JuliaLang/julia#18218 (comment).
So maybe something like RetType = Base.promote_op((c, v) -> c * foo(v) * foo(v), CoefType, VarType) is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never understood the argument so I am not surprised to see that I am not following it :-P
In fact, it appears that using promote_op is just bad: JuliaLang/julia#26344 (comment)
So the best way is just to play with typeof, zero, one and oneunit. To choose whether to use one or oneunit you need to think what would happen if the type was frim Unitful. For choosing between zero and one, you have some freedom but you need to avoid dividing by zero.
Maybe the best way here is doing typeof(oneunit(CoefType) * oneunit(MapVarType) * oneunit(MapVarType)). We are kind of forced to use promote_op to get MapVarType since one ... would on JuMP.VariableRef would not really do what we want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to use promote_op here because the variables get passed through foo...

Alternatively, we just avoid the value result_value misdirection and write a result_value function knowing that it will get a Float64 back...

src/quad_expr.jl Outdated Show resolved Hide resolved
src/quad_expr.jl Outdated Show resolved Hide resolved
src/quad_expr.jl Outdated Show resolved Hide resolved
src/quad_expr.jl Outdated Show resolved Hide resolved
Copy link
Member

@mlubin mlubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming CI passes

@odow odow merged commit 913866a into master Nov 8, 2018
@odow odow deleted the od/get_value_QuadExpr branch November 8, 2018 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants