Allow linear combinations of operators and plain tensors - #234
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #234 +/- ##
==========================================
+ Coverage 77.72% 77.74% +0.01%
==========================================
Files 30 30
Lines 1787 1788 +1
==========================================
+ Hits 1389 1390 +1
Misses 398 398
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mtfishman
force-pushed
the
mf/operator-state-algebra
branch
from
July 28, 2026 03:07
e3fef80 to
bb597c2
Compare
Linear combinations of an operator and a plain tensor now work: `o - t` (and `+`, and broadcasting generally) between a `NamedTensorOperator` and a non-operator tensor returns an operator instead of erroring. A plain tensor is treated as a trivial operator with no pairing, so the result inherits the operator operand's output/input split. Operator-operator broadcasting still requires the operators to pair their shared names consistently, but the check is now per-pair rather than on the whole output/input set. Operators that agree on every shared pairing combine and keep that pairing, while operators that pair a shared name two different ways (for example swapping its output/input roles) error. This also tightens a latent case where two such operators passed the old set-based check and silently adopted the first operand's split.
mtfishman
force-pushed
the
mf/operator-state-algebra
branch
from
July 28, 2026 15:42
bb597c2 to
58b8efe
Compare
Replace the occurrence-counting dictionary in `broadcast_operator_output_input` with a direct check on the merged pairs. The output names must be unique, the input names must be unique, and no name may be used as both. This is the same rule as before, that every shared name is paired the same way across operands, expressed on the result vectors instead of a per-name tally. Behavior is unchanged.
mtfishman
enabled auto-merge (squash)
July 28, 2026 18:18
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.
Summary
Linear combinations of an operator and a plain tensor now work:
o - t(and+, and broadcasting generally) between aNamedTensorOperatorand a non-operator tensor returns an operator instead of erroring. A plain tensor is treated as a trivial operator with no pairing, so the result inherits the operator operand's output/input split.Operator-operator broadcasting still requires the operators to pair their shared names consistently, but the check is now per-pair rather than on the whole output/input set. Operators that agree on every shared pairing combine and keep that pairing, while operators that pair a shared name two different ways (for example swapping its output/input roles) error. This also tightens a latent case where two such operators passed the old set-based check and silently adopted the first operand's split.