fix(v1): don't warn on exactly-aligned @/dot under legacy (#849) - #850
Merged
FBumann merged 2 commits intoJul 20, 2026
Merged
Conversation
The legacy alignment path in LinearExpression._align_constant warned whenever the constant operand's size dict differed from the expression's. But a size difference can come purely from disjoint dims (e.g. `x @ C`, where C carries its own contracted-out dim) — that is ordinary broadcasting, not a shared-dim misalignment. v1 accepts it, so the legacy LinopySemanticsWarning was a false positive on already-aligned operands. Warn only when first_mismatched_dim reports a real shared-dim disagreement, mirroring the sizes-equal branch, and collapse the duplicated warn/branch into one. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Name the aligned result and return once instead of repeating the (self.const, ..., False) triple, and move the "positional when sizes match" comment onto the branch it describes. Behaviour unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #849. Stacked on
feat/arithmetic-convention(#717).Note
The following content was generated by AI.
Problem
Under legacy semantics, the alignment path warned on
@/doteven when the operands are already exactly aligned on the contracted dimension — a false positive, since v1 accepts the same expression and both produce identical results.Cause
LinearExpression._align_constantwarned whenever the constant operand's size dict differed from the expression's. But a size difference can come purely from disjoint dims (inx @ C, the constantCcarries its own contracted-out dim), which is ordinary broadcasting — not a shared-dim misalignment.first_mismatched_dimcorrectly returnedNone, yet the warn still fired.Fix
Warn only when
first_mismatched_dimreports an actual shared-dim disagreement, mirroring the sizes-equal branch, and collapse the duplicated warn/branch into one.Genuine divergences are unaffected: a same-size shared dim with different labels, or a reordered shared dim, still warn under legacy and raise under v1.
Test
TestBroadcastNonSharedDim::test_matmul_exactly_aligned_shared_dim_is_silent—x @ Cwith an identically-aligned contracted dim raises noLinopySemanticsWarningunder legacy.