Skip to content

Feat: integers in stacking operators#699

Closed
mrava87 wants to merge 3 commits into
PyLops:devfrom
mrava87:feat-zerostack
Closed

Feat: integers in stacking operators#699
mrava87 wants to merge 3 commits into
PyLops:devfrom
mrava87:feat-zerostack

Conversation

@mrava87
Copy link
Copy Markdown
Collaborator

@mrava87 mrava87 commented Oct 3, 2025

Motivation

PyLops' stacking operators allow one to pass PyLops multiple LinearOperators or numpy/scipy matrices. However, in many practical scenarios, especially for the Block Operator, one may have some zero blocks (either many small ones or few large ones). Currently, one must rely on pylops.Zero to fill those zero blocks. However the inner working of pylops.Zero is 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 HStack and Block) and the number of zero rows (in VStack). By doing so, matvec/rmatvec simply do not perform any operation for the indices of the ops list that contain int values.

Definition of Done

  • Modify HStack
  • Modify VStack
  • Modify Block
  • Add tests
  • Add examples

#702 seems to solve the same issue with much less code changes - and since Zero instantiation has pretty much no overhead, this PR seems to be an overkill...

@mrava87 mrava87 requested a review from cako October 3, 2025 21:13
@mrava87
Copy link
Copy Markdown
Collaborator Author

mrava87 commented Oct 3, 2025

@cako would be great to get a feedback 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant