Skip to content

fix(v1): don't warn on exactly-aligned @/dot under legacy (#849) - #850

Merged
FBumann merged 2 commits into
feat/arithmetic-conventionfrom
fix/849-matmul-aligned-warning
Jul 20, 2026
Merged

fix(v1): don't warn on exactly-aligned @/dot under legacy (#849)#850
FBumann merged 2 commits into
feat/arithmetic-conventionfrom
fix/849-matmul-aligned-warning

Conversation

@FBumann

@FBumann FBumann commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

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 @ / dot even 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_constant warned whenever the constant operand's size dict differed from the expression's. But a size difference can come purely from disjoint dims (in x @ C, the constant C carries its own contracted-out dim), which is ordinary broadcasting — not a shared-dim misalignment. first_mismatched_dim correctly returned None, yet the warn still fired.

Fix

Warn only when first_mismatched_dim reports 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_silentx @ C with an identically-aligned contracted dim raises no LinopySemanticsWarning under legacy.

FBumann and others added 2 commits July 20, 2026 08:27
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>
@FBumann
FBumann marked this pull request as ready for review July 20, 2026 06:48
@FBumann
FBumann merged commit 392ee7f into feat/arithmetic-convention Jul 20, 2026
2 checks passed
@FBumann
FBumann deleted the fix/849-matmul-aligned-warning branch July 20, 2026 06:48
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