Feat: integers in stacking operators#699
Closed
mrava87 wants to merge 3 commits into
Closed
Conversation
Collaborator
Author
|
@cako would be great to get a feedback 😄 |
This was referenced Oct 12, 2025
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 allow passing integer numbers (alongside LinearOperators or numpy/scipy matrices), which represent the number of zero columns (in
HStackandBlock) and the number of zero rows (inVStack). By doing so, matvec/rmatvec simply do not perform any operation for the indices of theopslist that containintvalues.Definition of Done
HStackVStackBlock⏰ #702 seems to solve the same issue with much less code changes - and since
Zeroinstantiation has pretty much no overhead, this PR seems to be an overkill...