Skip to content

Loosen generic tensor operations to accept non-array operands#195

Merged
mtfishman merged 1 commit into
mainfrom
mf/nonarray-tensor-operands
Jul 1, 2026
Merged

Loosen generic tensor operations to accept non-array operands#195
mtfishman merged 1 commit into
mainfrom
mf/nonarray-tensor-operands

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Loosens the generic tensor operations (contraction, factorizations, matrix functions, permuted-add) to accept operands that are not AbstractArrays, so a backend can flow its own tensor type through the generic orchestration by overloading a small set of hooks rather than subtyping AbstractArray.

The supporting refactors:

  • matricize/unmatricize split into permuting and non-permuting forms by name: the permuting forms are matricizeperm/unmatricizeperm/unmatricizeperm! (and matricizeop becomes matricizeopperm), while unmatricize is again the split-axes primitive unmatricize(m, codomain_axes, domain_axes). Distinguishing the two resolves the method ambiguities that had forced the flattened signature and restores the split-axes call.
  • Output allocation goes through the bipartitioned similar_map hook instead of a flat similar, so a map-shaped backend can build its codomain and domain directly.
  • A private PermutedDims lazy-permutation wrapper mirrors PermutedDimsArray for non-array operands, letting a downstream permuteddims hand a lazily-permuted operand to bipermutedimsopadd!.

The public matricizeop to matricizeopperm rename is breaking. The TensorKit backend that exercises these hooks lands in a follow-up PR.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.24731% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.38%. Comparing base (94ac951) to head (afe0300).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/matricize.jl 86.84% 5 Missing ⚠️
src/factorizations.jl 88.88% 3 Missing ⚠️
src/contract/contractalgorithm.jl 75.00% 1 Missing ⚠️
src/linearbroadcasted.jl 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #195      +/-   ##
==========================================
- Coverage   83.38%   83.38%   -0.01%     
==========================================
  Files          22       22              
  Lines         650      656       +6     
==========================================
+ Hits          542      547       +5     
- Misses        108      109       +1     
Flag Coverage Δ
docs 27.41% <30.58%> (-0.43%) ⬇️

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/nonarray-tensor-operands branch from 2fe138c to 0446bc9 Compare July 1, 2026 18:51
Loosens the generic tensor operations (contraction, factorizations, matrix functions, permuted-add) to accept operands that are not `AbstractArray`s, so a backend can flow its own tensor type through the generic orchestration by overloading a small set of hooks rather than subtyping `AbstractArray`.

The supporting refactors:

- `matricize`/`unmatricize` split into permuting and non-permuting forms by name: the permuting forms are `matricizeperm`/`unmatricizeperm`/`unmatricizeperm!` (and `matricizeop` becomes `matricizeopperm`), while `unmatricize` is again the split-axes primitive `unmatricize(m, codomain_axes, domain_axes)`. Distinguishing the two resolves the method ambiguities that had forced the flattened signature and restores the split-axes call.
- Output allocation goes through the bipartitioned `similar_map` hook instead of a flat `similar`, so a map-shaped backend can build its codomain and domain directly.
- A private `PermutedDims` lazy-permutation wrapper mirrors `PermutedDimsArray` for non-array operands, letting a downstream `permuteddims` hand a lazily-permuted operand to `bipermutedimsopadd!`.

The public `matricizeop` to `matricizeopperm` rename is breaking. The TensorKit backend that exercises these hooks lands in a follow-up PR.
@mtfishman mtfishman enabled auto-merge (squash) July 1, 2026 18:58
@mtfishman mtfishman force-pushed the mf/nonarray-tensor-operands branch from 0446bc9 to afe0300 Compare July 1, 2026 18:58
@mtfishman mtfishman merged commit 7420b03 into main Jul 1, 2026
21 checks passed
@mtfishman mtfishman deleted the mf/nonarray-tensor-operands branch July 1, 2026 19:20
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