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

Allocations in powers with literal exponents #66

Open
rdeits opened this issue Jul 26, 2018 · 2 comments
Open

Allocations in powers with literal exponents #66

rdeits opened this issue Jul 26, 2018 · 2 comments

Comments

@rdeits
Copy link
Collaborator

rdeits commented Jul 26, 2018

It looks like we're not quite handling literal_pow correctly:

julia> using SimpleQP

julia> model = SimpleQP.MockModel()
SimpleQP.MockModel(SimpleQP.Parameter[], Base.RefValue{Int64}(1))

julia> p = Parameter(() -> 1.0, model)
Parameter{Float64, …}()

julia> e = @expression(p^2)
LazyExpression{FunctionWrapper{…}(LazyExpression{Base.#literal_pow, …}(…))}()

julia> e()
1.0

julia> SimpleQP.findallocs(e)
LazyExpression{FunctionWrapper{…}(LazyExpression{Base.#literal_pow, …}(…))}(): 48 bytes
  [1]: Base.#^
  [2]: Parameter{Float64, …}(): 0 bytes
  [3]: DataType
@tkoolen
Copy link
Owner

tkoolen commented Jul 30, 2018

This is because 1.0^2 becomes Base.literal_pow(^, 1.0, Val{2}), and Val{2} is a DataType (as opposed to Val{2}()), so dynamic dispatch happens. The issue is fixed on Julia master, so I'm inclined to just wait for 0.7.

@rdeits
Copy link
Collaborator Author

rdeits commented Jul 30, 2018

No problem. It's easy to replace with x * x until then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants