Feat: change internal handling of Zero in hstack/vstack#702
Merged
Conversation
5 tasks
cako
approved these changes
Oct 13, 2025
Collaborator
cako
left a comment
There was a problem hiding this comment.
LGTM! I will leave it as approved but I suggest including this behavior in the class documentation and/or the gallery examples. It is important for people to know that if they use the proper operators (Zero as opposed to e.g., MatrixMult) they will get performance benefits.
Also, seems like no need for me to review #699?
Collaborator
Author
|
Thanks! Sure, let me add something to the example like I had done inhttps://github.com//pull/699 And yes, no need to look at #699... after I implemented that way I started to feel it was an overkill given the minimal overhead of |
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.
Motivation
PyLops' stacking operators allow one to pass PyLops multiple LinearOperators or numpy/scipy matrices. However, in many practical scenarios, especially for the
BlockOperator, one may have some zero blocks (either many small ones or few large ones). Currently, one must rely onpylops.Zeroto fill those zero blocks. However the inner working ofpylops.Zerois such that every time matvec/rmatvec is called a zero array is instantiated. For stacking operators, this is actually redundant as one could simply skip filling part of the output vector. The current approach is particularly problematic when using the CuPy backend as instantiating new arrays on GPU memory is tremendously slow and unefficient (compared to performing arithmetic operations).To solve this issue, this PR proposes to add a check prior to calling the matvec/rmatvec of an operator and skip it if the operator is of instance
ZeroDefinition of Done
HStackVStack⏰ This is a much simpler solution to the one initially proposed in #699