Skip to content

Overload MatrixAlgebraKit factorizations for named tensors#183

Merged
mtfishman merged 8 commits into
mainfrom
mf/v0.7
Jun 23, 2026
Merged

Overload MatrixAlgebraKit factorizations for named tensors#183
mtfishman merged 8 commits into
mainfrom
mf/v0.7

Conversation

@mtfishman

@mtfishman mtfishman commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Adapts ITensorBase to TensorAlgebra v0.10 and tightens the named-array surface, as one breaking release.

Defines ITensorBase's AbstractITensor factorizations as overloads of MatrixAlgebraKit's functions (qr_compact, svd_compact, left_orth, and the rest), each forwarding to the matching TensorAlgebra array-level method on the unnamed data. This mirrors how * on AbstractITensor forwards to TensorAlgebra.contract: a factorization of a named tensor acts as that factorization on its matricized form, with TensorAlgebra handling the matricization. It replaces the previous LinearAlgebra-style svd / qr / lq / eigen catch-alls, which overloaded LinearAlgebra for a type that is not an AbstractArray, and adopts the explicit factorization names TensorAlgebra v0.10 exposes (ITensor/TensorAlgebra.jl#180). For gram_eigh_full and gram_eigh_full_with_pinv, which have no MatrixAlgebraKit counterpart, the overloads target TensorAlgebra.MatrixAlgebra. Adds MatrixAlgebraKit as a direct dependency.

Renames the unnamed-array accessors dename / denamed to unname / unnamed throughout, including the Unnamed type, the unnamedtype and unnamed_prototype helpers, and internal locals.

Makes length and size of a named array or named unit range return a plain Int, and axes / eachindex return plain unnamed ranges, so the count and positional-index layer match Base and the AbstractArray contract that axes are AbstractUnitRange{Int}. The name stays on the elements (a[i], first, last, iteration) and on a tensor's named indices via inds / axes(::AbstractITensor). This lets length(::AbstractITensor) be the plain element count (the product of its size), which previously errored.

Bumps to 0.7.0 and requires TensorAlgebra 0.10.

…ames

Repoints ITensorBase's `AbstractITensor` factorization layer onto the explicit factorization names TensorAlgebra v0.10 exposes (introduced in ITensor/TensorAlgebra.jl#180), replacing the catch-all `svd` / `qr` / `lq` / `eigen` / `eigvals` / `svdvals` with MatrixAlgebraKit's explicit `svd_compact` / `svd_trunc` / `qr_compact` / `eigh_full` / `eig_full` / `eigh_vals` variants and the rest. Also drops the `LinearAlgebra` factorization overloads for named tensors, since overloading `LinearAlgebra` for a type that is not an `AbstractArray` is questionable and the factorizations are now exposed under the explicit names only.

Bumps to 0.7.0 and requires TensorAlgebra 0.10.
The README example used `LinearAlgebra.qr` on a named tensor, which relied on the LinearAlgebra factorization overload this branch drops. Switches it to `TensorAlgebra.qr_compact` and swaps the examples project's `LinearAlgebra` dependency for `TensorAlgebra` accordingly.
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.21311% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.14%. Comparing base (c6d3531) to head (231e233).

Files with missing lines Patch % Lines
src/tensoralgebra.jl 63.63% 28 Missing ⚠️
src/abstractitensor.jl 76.81% 16 Missing ⚠️
src/named.jl 26.66% 11 Missing ⚠️
src/abstractnamedarray.jl 50.00% 6 Missing ⚠️
src/broadcast.jl 76.00% 6 Missing ⚠️
src/namedunitrange.jl 75.00% 4 Missing ⚠️
src/lazyitensors/evaluation_order.jl 33.33% 2 Missing ⚠️
src/lazyitensors/lazyinterface.jl 0.00% 2 Missing ⚠️
...t/ITensorBaseMooncakeExt/ITensorBaseMooncakeExt.jl 0.00% 1 Missing ⚠️
src/itensor.jl 88.88% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
+ Coverage   71.05%   71.14%   +0.08%     
==========================================
  Files          28       28              
  Lines        1451     1438      -13     
==========================================
- Hits         1031     1023       -8     
+ Misses        420      415       -5     
Flag Coverage Δ
docs 15.96% <21.90%> (+0.20%) ⬆️

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.

Define the named-tensor factorizations as overloads of `MatrixAlgebraKit`'s
functions (`qr_compact`, `svd_compact`, `left_orth`, and the rest) on
`AbstractITensor`, each forwarding to the matching `TensorAlgebra` array-level
method on the unnamed data. This mirrors how `*` on `AbstractITensor` forwards
to `TensorAlgebra.contract`: `MatrixAlgebraKit.f(t)` acts as `f` on the
matricized tensor, with `TensorAlgebra` doing the matricization. For
`gram_eigh_full` and `gram_eigh_full_with_pinv`, which have no `MatrixAlgebraKit`
counterpart, overload `TensorAlgebra.MatrixAlgebra` instead, following the same
pattern. Adds `MatrixAlgebraKit` as a direct dependency.
@mtfishman mtfishman changed the title [WIP] Adapt named-tensor factorizations to TensorAlgebra v0.10's explicit names [WIP] Overload MatrixAlgebraKit factorizations for named tensors Jun 23, 2026
Renames the unnamed-array accessors `dename`/`denamed` to `unname`/`unnamed`
throughout, including the `Denamed`/`DenamedT` type and type parameter, the
`denamedtype` and `denamed_prototype` helpers, and the internal `*_denamed`
locals. `unnamed(a)` returns the unnamed array underlying a named tensor and
`unname(a, names)` returns it permuted to the given names.

Also moves the `ITensorOperator` `gram_eigh_full` and `gram_eigh_full_with_pinv`
methods (and their docstrings) onto the `TensorAlgebra.MatrixAlgebra` namespace,
matching where the `AbstractITensor` overloads live, so the operator entry
points dispatch to the named-tensor methods.
Makes `length` and `size` of a named array or named unit range return a plain
`Int` count, and `axes`/`eachindex` return plain unnamed ranges, so the count
and positional-index layer match Base and the `AbstractArray` contract (`axes`
must be `AbstractUnitRange{Int}`). The name stays on the elements (`a[i]`,
`first`, `last`, iteration) and on a tensor's named indices via `inds` /
`axes(::AbstractITensor)`, which are unchanged. Defines `length(::AbstractITensor)`
as the product of its size (the plain element count), which previously errored
because `size` returned named integers and `prod` has no named `*`. Removes the
now-redundant unwrapping at the count call sites.
With `length`/`size` of a named array or named unit range now returning a plain
`Int`, the `length(unnamed(x))` / `length ∘ unnamed` / `size`-then-unname wrapping
at the count call sites is redundant (`length(x) == length(unnamed(x))`). Drops it
in the contraction-cost and symbolic-tensor paths, the `NamedDimsCartesianIndices`
`axes`/`size`, and the TensorOperations extension.
Comment thread Project.toml Outdated
@mtfishman mtfishman marked this pull request as ready for review June 23, 2026 15:12
@mtfishman mtfishman changed the title [WIP] Overload MatrixAlgebraKit factorizations for named tensors Overload MatrixAlgebraKit factorizations for named tensors Jun 23, 2026
@mtfishman mtfishman merged commit 3082ca2 into main Jun 23, 2026
17 of 18 checks passed
@mtfishman mtfishman deleted the mf/v0.7 branch June 23, 2026 15:47
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