Skip to content

Use the field-based PermutedDims to align permuted broadcasts#201

Merged
mtfishman merged 2 commits into
mainfrom
mf/permuteddims-field-wrapper
Jul 1, 2026
Merged

Use the field-based PermutedDims to align permuted broadcasts#201
mtfishman merged 2 commits into
mainfrom
mf/permuteddims-field-wrapper

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Aligns a misaligned operand in named-tensor broadcasting with TensorAlgebra.PermutedDims instead of Base.PermutedDimsArray. PermutedDimsArray encodes the permutation in a type parameter, so a runtime permutation forces a type-unstable, allocating construction on every permuted add. PermutedDims stores the permutation in a field, builds cheaply and type-stably, and is a broadcast leaf the linear-combination fold absorbs via bipermutedimsopadd!, so a permuted add no longer pays that type-construction floor and closes most of the gap to an aligned add. The wrapper stays confined to the broadcast alignment path (broadcasted_unnamed) and is never returned by the public unnamed(a, names).

Builds on the broadcast-friendly PermutedDims from ITensor/TensorAlgebra.jl#198.

## Summary

Aligns a misaligned operand in named-tensor addition with `TensorAlgebra.PermutedDims` instead of `Base.PermutedDimsArray`. `PermutedDimsArray` encodes the permutation in a type parameter, so a runtime permutation forces a type-unstable, allocating construction on every permuted add. `PermutedDims` stores the permutation in a field, builds cheaply and type-stably, and is a broadcast leaf the linear-combination fold absorbs, so a permuted add no longer pays that type-construction floor and closes most of the gap to an aligned add.

Builds on the broadcast-friendly `PermutedDims` from ITensor/TensorAlgebra.jl#198.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.03%. Comparing base (a1a0926) to head (4ed4c8b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #201      +/-   ##
==========================================
+ Coverage   74.00%   74.03%   +0.03%     
==========================================
  Files          28       28              
  Lines        1500     1502       +2     
==========================================
+ Hits         1110     1112       +2     
  Misses        390      390              
Flag Coverage Δ
docs 24.38% <100.00%> (-0.18%) ⬇️

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.

The public `unnamed(a, names)` keeps returning a `Base.PermutedDimsArray` (a full array), so callers outside broadcasting are unaffected. Only `broadcasted_unnamed` aligns a misaligned operand with `TensorAlgebra.PermutedDims`, whose minimal array interface stays confined to the broadcast hot path and is never handed to users. Also removes the `[sources]` pin now that TensorAlgebra 0.15.1 is registered, and switches a GPU-unsafe `dot` test to eager `unname`.
@mtfishman mtfishman changed the title [WIP] Build permuted named-tensor add on the field-based PermutedDims Use the field-based PermutedDims to align permuted broadcasts Jul 1, 2026
@mtfishman mtfishman marked this pull request as ready for review July 1, 2026 23:44
@mtfishman mtfishman enabled auto-merge (squash) July 1, 2026 23:45
@mtfishman mtfishman merged commit 08440b8 into main Jul 1, 2026
25 of 28 checks passed
@mtfishman mtfishman deleted the mf/permuteddims-field-wrapper branch July 1, 2026 23:57
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