Skip to content

[Utilities] fix operate(vcat for VectorNonlinearFunction #2682

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

Merged
merged 4 commits into from
Mar 6, 2025
Merged

Conversation

odow
Copy link
Member

@odow odow commented Mar 5, 2025

#2553 got complicated to debug because of this 😄

Without this PR, this code:

scalars = MOI.Utilities.eachscalar(func)
t, x = scalars[1], scalars[2:end]
# Create f_new = [-x; x].
f_new = MOI.Utilities.operate(vcat, T, MOI.Utilities.operate(-, T, x), x)
# Add +t to each row of x
for i in 1:(2*(length(scalars)-1))
MOI.Utilities.operate_output_index!(+, T, i, f_new, t)
end

modifies the user's input function.

@@ -991,7 +991,11 @@ function operate(
append!(out, scalarize(a))
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to copy if it's the output of scalarize, I would rather copy in the two push! above

Copy link
Member Author

Choose a reason for hiding this comment

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

You don't need to copy if it's the output of scalarize

Ah but you do if you hit this method MOI.Utilities.scalarize(f::MOI.VectorNonlinearFunction) = f.rows.

The question of whether scalarize and vectorize are mutable hasn't really come up before, because they always produced unique objects.

Copy link
Member

Choose a reason for hiding this comment

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

😨

@odow odow merged commit f31be21 into master Mar 6, 2025
31 checks passed
@odow odow deleted the od/vcat branch March 6, 2025 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.

2 participants