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

Update Coefficients in Cost with Copying Whole Vector #22131

Open
cohnt opened this issue Nov 5, 2024 · 2 comments
Open

Update Coefficients in Cost with Copying Whole Vector #22131

cohnt opened this issue Nov 5, 2024 · 2 comments
Assignees
Labels
component: mathematical program Formulating and solving mathematical programs; our autodiff and symbolic libraries type: feature request

Comments

@cohnt
Copy link
Contributor

cohnt commented Nov 5, 2024

In scenarios where we're solving a sequence of similar mathematical programs (e.g. #22084), we have to copy over the entire coefficient vector to update the cost. It would be much more efficient if we could just modify the internally held coefficient vector in-place. I specifically care about LinearCost, but I imagine it would be applicable to other costs as well.

cc @AlexandreAmice

@cohnt cohnt added type: feature request component: mathematical program Formulating and solving mathematical programs; our autodiff and symbolic libraries labels Nov 5, 2024
@hongkai-dai
Copy link
Contributor

@cohnt Currently UpdateCoefficients just copies the new coefficient vector to the internally held vector. I think you are suggesting something like this

LinearCost::UpdateCoefficientEntry(int i, double val) {
  a_[i] = val;
}

I wonder why this "update-in-place" is more efficient than copying a vector?

@cohnt
Copy link
Contributor Author

cohnt commented Nov 11, 2024

That method would be perfect for what I need.

If we have a large vector and we only need to change one or two entries of it (as in the generic ConvexSet::IsBounded method), I would think it's significantly faster to just modify the entry, rather than keeping an entirely separate vector around, changing the entry there, and then copying it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: mathematical program Formulating and solving mathematical programs; our autodiff and symbolic libraries type: feature request
Projects
None yet
Development

No branches or pull requests

2 participants