Skip to content

Allow linear combinations of operators and plain tensors - #234

Merged
mtfishman merged 2 commits into
mainfrom
mf/operator-state-algebra
Jul 28, 2026
Merged

Allow linear combinations of operators and plain tensors#234
mtfishman merged 2 commits into
mainfrom
mf/operator-state-algebra

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 28, 2026

Copy link
Copy Markdown
Member

Summary

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.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.74%. Comparing base (13f6336) to head (e46607a).

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              
Flag Coverage Δ
docs 26.58% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman
mtfishman force-pushed the mf/operator-state-algebra branch from e3fef80 to bb597c2 Compare July 28, 2026 03:07
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
mtfishman force-pushed the mf/operator-state-algebra branch from bb597c2 to 58b8efe Compare July 28, 2026 15:42
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
mtfishman enabled auto-merge (squash) July 28, 2026 18:18
@mtfishman
mtfishman merged commit f867b1a into main Jul 28, 2026
18 checks passed
@mtfishman
mtfishman deleted the mf/operator-state-algebra branch July 28, 2026 18:29
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