perf: eliminate redundant matrix allocation in DenseProductMatrix via vector negation#466
Open
Omar-Abdo1 wants to merge 2 commits intoGeomScale:developfrom
Open
perf: eliminate redundant matrix allocation in DenseProductMatrix via vector negation#466Omar-Abdo1 wants to merge 2 commits intoGeomScale:developfrom
Omar-Abdo1 wants to merge 2 commits intoGeomScale:developfrom
Conversation
vissarion
reviewed
Mar 12, 2026
| // and next of y to y_out | ||
| Eigen::Map<VT> const x(const_cast<double*>(x_in), _rows); | ||
| VT const v = *A * x; | ||
| VT v = *A * x; |
Member
There was a problem hiding this comment.
Alternatively,
VT v = negative ? *A * x * -1 : *A * x;
Also negative could be a template parameter.
Author
There was a problem hiding this comment.
Thanks for the review! Updated to use the ternary operator as suggested. Let me know if there are any further changes needed.
vissarion
approved these changes
Mar 30, 2026
Member
vissarion
left a comment
There was a problem hiding this comment.
Thanks, I am OK with this change.
Member
|
@TolisChal what do you think? |
Author
|
Thank you for the approval @vissarion! @TolisChal — happy to make any further adjustments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the TODOs in EigenvaluesProblems.h regarding unnecessary matrix allocations.
The Problem:
Previously, the generalized eigenvalue solver allocated a new N×N matrix (_B = -1 * B) just to negate the sign. For high-dimensional polytopes (up to thousands of dimensions as targeted by VolEsti ), this O(N2) space and time allocation is a significant bottleneck.
The Solution:
I modified the DenseProductMatrix class to handle negation "lazily". By introducing a negative flag, the sign inversion is now performed on the intermediate vector v (where v=Ax) inside the perform_op and MultMv methods.
Key Benefits: