Skip to content

Route TensorMap in-place linear algebra through VectorInterface#207

Merged
mtfishman merged 1 commit into
mainfrom
mf/tensormap-inplace-ops
Jul 11, 2026
Merged

Route TensorMap in-place linear algebra through VectorInterface#207
mtfishman merged 1 commit into
mainfrom
mf/tensormap-inplace-ops

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 11, 2026

Copy link
Copy Markdown
Member

Summary

Defines TensorAlgebra.zero!, scale!, and add! for AbstractTensorMap as thin forwards to the corresponding VectorInterface methods, which are TensorKit's primary interface for these in-place linear operations. The generic AbstractArray definitions don't apply, since a TensorMap is not an AbstractArray, and routing through VectorInterface keeps a self-aliased call such as a .*= 2 or add!(a, a, α, β) a correct block-wise rescale instead of aliasing the destination with an operand through a broadcast. The add! method here is the non-permuting y = α*x + β*y. The permuting bipermutedimsopadd! still fuses a non-trivial codomain/domain permutation for the matricize, contract, and broadcast callers.

VectorInterface becomes a weak dependency on the TensorKit extension's trigger list. It is already a dependency of TensorKit, so loading TensorKit pulls it in and the effective load trigger is unchanged.

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.65%. Comparing base (f8749bd) to head (fa6eea7).

Files with missing lines Patch % Lines
ext/TensorAlgebraTensorKitExt.jl 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #207      +/-   ##
==========================================
- Coverage   81.03%   80.65%   -0.38%     
==========================================
  Files          24       24              
  Lines         907      910       +3     
==========================================
- Hits          735      734       -1     
- Misses        172      176       +4     
Flag Coverage Δ
docs 24.17% <0.00%> (-0.09%) ⬇️

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/tensormap-inplace-ops branch from 62de6fb to fa6eea7 Compare July 11, 2026 15:23
@mtfishman mtfishman merged commit 93bebac into main Jul 11, 2026
19 of 21 checks passed
@mtfishman mtfishman deleted the mf/tensormap-inplace-ops branch July 11, 2026 16:59
mtfishman added a commit to ITensor/ITensorBase.jl that referenced this pull request Jul 11, 2026
…ods (#217)

## Summary

Implements the full `VectorInterface` for named tensors and routes its
in-place operations through name-aware `TensorAlgebra` methods instead
of self-aliasing broadcasts. `scale!`/`add!` forward to
`TensorAlgebra.scale!`/`TensorAlgebra.add!`, which unname and align the
operands by name (reusing the `unnamed(x, dimnames(y))` view, which
carries a tuple permutation) before dispatching to the backend array's
block-wise in-place method. This fixes silent corruption when a
block-sparse backend drives an iterative solver: the previous `@. y =
y*β + x*α` put the destination on the right-hand side, and a graded
`copyto!` ran the `y*β` term as a self-aliased permute-add that zeroed
`y` before reading it. The out-of-place and `!!` variants allocate the
promoted scalar type, so scaling a real tensor by a complex coefficient
widens to a complex result.

`inner` forwards to `LinearAlgebra.dot` (previously a duplicate of the
same `(conj(x)*y)[]`), and `_permuteddims_to` drops its `AbstractArray`
restriction so the by-name alignment view also works for a `TensorMap`
backend.

The methods are defined as qualified `VectorInterface.` overloads, so
ITensorBase no longer imports the `VectorInterface` function names into
its namespace or re-exports them.

Builds on ITensor/TensorAlgebra.jl#207, which
adds the `TensorMap` `TensorAlgebra.scale!`/`add!`/`zero!` methods this
forwarding lands on.
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