Repository navigation
Fix: scale the operator when dividing it by a scalar - #811
Merged
Merged
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 12 |
| Duplication | 19 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
mrava87
requested changes
Oct 8, 2026
mrava87
left a comment
Collaborator
There was a problem hiding this comment.
@raashish1601 thanks for tackling this issue.
Overall the fix is good and clean... I just left a few comments, mostly things that did not match with other common patterns in the codebase, please fix them before I can approve and merge 😄
Only real scalars are now tested, and the FFT test skips the fftw and scipy engines with CuPy arrays.
mrava87
requested changes
Oct 10, 2026
mrava87
left a comment
Collaborator
There was a problem hiding this comment.
@raashish1601 thanks for the changes!
I just left two minor comments, after they are addressed this is ready to be merged 😄
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.
Op / ysolvesy = Op x, butLinearOperator.__truediv__didn't check whetheryis a scalar. SoOp / np.sqrt(2)ran a solve against a constant data vector and returned an array, whileOp / 2.0failed deep insidecglsorlstsq(#803).This takes option 1 from the issue: a scalar divisor (anything with
np.ndim(y) == 0, so Python, NumPy and 0-d array scalars) now returnsself * (1 / y), the same scaled operatorOp * agives. Non-scalarystill goes through the solve as before.The FFT, FFT2D and FFTND operators override
__truediv__with their exact inverse, so they had the same problem (FFT(dims=8) / 2.0raisedAttributeError). Each of those overrides now hands a scalar to the base class first. I also added a sentence to thedivdocstring.Tests:
test_scalar_divisioninpytests/test_linearoperator.py(an explicitMatrixMultand a non-explicitVStack, real and complex, square and overdetermined) and inpytests/test_ffts.py(FFT, FFT2D and FFTND for each engine, skipping fftw and mkl_fft when they aren't installed). Both fail ondevand pass here.pytests/test_ffts.py,test_linearoperator.pyandtest_solver.pypass locally (fftw/mkl_fft not installed here), andruff check/ruff formatare clean on the changed files.AI assistance: this PR was prepared with an AI coding agent (Claude Code, Anthropic). It reproduced the issue, wrote the fix and tests, and ran them locally as described above.
Closes #803