refactor _operator.py into multiple files#228
Merged
Conversation
Break the ~2400-line _operator.py into a _operator/ package: - base.py: AbstractLinearOperator and the singledispatch operation stubs - core.py: Matrix, PyTree, Jacobian, Function - structured.py: Identity, Diagonal, Tridiagonal - wrapper.py: Tagged, Tangent, Mul, Neg, Div - binary.py: Add, Composed - __init__.py re-exports the public API unchanged Operation registrations are co-located with their operators (the stubs stay in base.py), and repeated registrations are folded into loops (the core predicates and the structured checks). Cross-file helpers drop their leading underscore, and _try_sparse_materialise becomes try_structured_materialise. structured.py is ordered Identity -> Diagonal -> Tridiagonal, and the operator API docs are regrouped into core / structured / wrapper to match. Behaviour-preserving: the public imports are unchanged, and the operator, transpose, and adjoint test suites pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jpbrodrick89
force-pushed
the
jpb/refactor-operator
branch
from
June 4, 2026 20:28
92b101b to
d04591a
Compare
Collaborator
Author
|
This now targets dev branch, will merge when tests pass as only controversial change is documentation which can be reviewed anytime prior to next release. |
Collaborator
Author
|
failure is flaky due to GMRES' convergence criteria not allowing for round-off error when values of RHS differ in scale. Merging and fixing in a follow-up |
Owner
|
Beautiful! This all looks good to me. |
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.
Implements #227 breaking the ~2400-line _operator.py into a _operator/ package:
AbstractLinearOperatorand thesingledispatchoperation stubs (558 lines)__init__.pyre-exports the public API unchanged (53 lines)Operation registrations are co-located with their operators, and repeated registrations are folded into loops (the core predicates and the structured checks). Cross-file helpers drop their leading underscore (with
_frozensetrenamed toas_frozenset), and_try_sparse_materialisebecomestry_structured_materialise. structured.py is ordered Identity -> Diagonal -> Tridiagonal, and the operator API docs are regrouped into core / structured / wrapper to match. (@patrick-kidger the docs restructure is probably the thing you might be most opinionated about so I will hold off merging until you've confirmed comfort with that.)Behaviour-preserving: the public imports are unchanged, and the operator, transpose, and adjoint test suites pass (full suite will run in CI).
@BalzaniEdoardo a new
CirculantLinearOperator.pycan now fit cleanly intostructured.pywhich is only 382 lines after this refactor.