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

Wrap indices used in macros in let/local #584

Merged
merged 1 commit into from
Sep 13, 2015
Merged

Wrap indices used in macros in let/local #584

merged 1 commit into from
Sep 13, 2015

Conversation

joehuchette
Copy link
Contributor

Ref #582, this seems like a reasonable change in that it makes JuMP behave more like a DSL. Haven't added v0.3 support yet, nor done perf testing to see if this slows things down.

@@ -130,6 +137,26 @@ end

getloopedcode(c, code, condition, idxvars, idxsets, idxpairs, sym) = code

localvar(x::Expr) = Expr(:block, _localvar(x)...)
_localvar(x::Symbol) = :(local $(esc(x)))
function _localvar(x::Expr)
Copy link
Member

Choose a reason for hiding this comment

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

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handles this gross case from the tests:

@defVar(m, tri_3[(i,j)=[(i,i+2) for i in 1:5],k=i:j])

and gives you

local i
local j
for (i,j) = [(i,i + 2) for i = 1:5]
    ...
end

@joehuchette
Copy link
Contributor Author

Not seeing any performance regressions. On master:

test/perf❯ j speed.jl                          JuMP/git/master
PMEDIAN BUILD MIN=0.642807454  MED=0.806141951
PMEDIAN WRITE MIN=2.21950597  MED=2.448302863
CONT5 BUILD   MIN=0.282755884  MED=0.338333321
CONT5 WRITE   MIN=1.964233636  MED=1.988693638

test/perf❯ j macro.jl                          JuMP/git/master
  Running N=20...
    N=20 min 0.008439511
    N=20 min 0.021468948
  Running N=50...
    N=50 min 0.159582901
    N=50 min 0.410900603
  Running N=100...
    N=100 min 1.538156
    N=100 min 3.739682569

and this PR:

test/perf❯ j speed.jl               JuMP/git/localvars
PMEDIAN BUILD MIN=0.620035225  MED=0.805018357
PMEDIAN WRITE MIN=2.225878204  MED=2.530214445
CONT5 BUILD   MIN=0.265568488  MED=0.329455468
CONT5 WRITE   MIN=1.961389032  MED=1.985305759

test/perf❯ j macro.jl                       JuMP/git/localvars
  Running N=20...
    N=20 min 0.008394612
    N=20 min 0.021188721
  Running N=50...
    N=50 min 0.165039593
    N=50 min 0.412274769
  Running N=100...
    N=100 min 1.512589045
    N=100 min 3.707197417

@mlubin
Copy link
Member

mlubin commented Sep 12, 2015

Could you compare with 0.3 just for sanity check?

Also need lots of new tests here.

end
cnt = 4
for i in 5:8
@defVar(m, y[i=2:4,j=1:3] ≤ i)
Copy link
Member

Choose a reason for hiding this comment

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

Check the upper bounds on y?

if t.head == :tuple
append!(args, map(_localvar, t.args))
else
error("Internal error; please file an issue")
Copy link
Member

Choose a reason for hiding this comment

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

How? Maybe add the URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add that separately.

joehuchette added a commit that referenced this pull request Sep 13, 2015
Wrap indices used in macros in let/local
@joehuchette joehuchette merged commit 6c2b9d4 into master Sep 13, 2015
@mlubin
Copy link
Member

mlubin commented Sep 13, 2015

I'm a bit worried that this will subtly break something. I think it needs a bit of time to settle in. Not sure if it should go into 0.10.2.

@joehuchette
Copy link
Contributor Author

Agreed, since this is technically breaking.

@joehuchette
Copy link
Contributor Author

Should maybe get a NEWS entry then

@mlubin mlubin deleted the localvars branch February 6, 2017 16:20
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.

2 participants