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

Improve performance of sum of products with nonlinear expressions #3470

Closed
wants to merge 1 commit into from

Conversation

blegat
Copy link
Member

@blegat blegat commented Aug 31, 2023

Closes #3469

@blegat blegat marked this pull request as ready for review August 31, 2023 11:22
@blegat
Copy link
Member Author

blegat commented Aug 31, 2023

Looking into an example where it gives an improvement to implement operate!! for more than one factor, I found this weird issue:
jump-dev/MutableArithmetics.jl#224

push!(x.args, y)
arg = *(args...)
if _MA.add_sub_op(op) != +
arg = _MA.add_sub_op(op)(arg)
Copy link
Member

Choose a reason for hiding this comment

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

I really think we should avoid this. If the user writes x + y - 2 * z, we should make -(+(x, y), *(2, z)), not `+(x, y, -(*(2, z))).

Julia has a parsing precedence order. Let's follow that where possible.

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 thought flatten! was doing that anyway

@odow
Copy link
Member

odow commented Aug 31, 2023

I also don't see how this fixes your issue. It just defines a separate method so that the other issue isn't hit. We'd still need the if statement if we added another AbstractJuMPScalar that was IsNotMutable.

x::GenericNonlinearExpr,
y::AbstractJuMPScalar,
Copy link
Member

Choose a reason for hiding this comment

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

I don't remember why I only wrote the binary case 😆

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.

StackOverflow with operate!! and NonlinearExpr
2 participants