Skip to content

Add Matrix/Vector conversion for named tensors#228

Merged
mtfishman merged 1 commit into
mainfrom
mf/matrix-vector-itensor
Jul 24, 2026
Merged

Add Matrix/Vector conversion for named tensors#228
mtfishman merged 1 commit into
mainfrom
mf/matrix-vector-itensor

Conversation

@mtfishman

Copy link
Copy Markdown
Member

Summary

Adds Matrix(::AbstractNamedTensor) and Vector(::AbstractNamedTensor) for densifying a named tensor whose rank is fixed by its leg count (e.g. the two-leg result of matricize), which reads more clearly at the call site than the generic Array. Both are handled by a single Array{<:Any, N} method that defaults the eltype and forwards to the existing Array{T, N} conversion, so a rank mismatch (a non-two-leg tensor into Matrix, a non-one-leg tensor into Vector) errors as expected.

Also removes the AbstractArray{T} / AbstractArray{T, N} constructors, and the _checkaxs / copyto_axcheck! helpers they used: AbstractNamedTensor is not an AbstractArray, so those constructors returned a named tensor from an AbstractArray constructor, and nothing called them.

## Summary

Adds `Matrix(::AbstractNamedTensor)` and `Vector(::AbstractNamedTensor)` for densifying a named tensor whose rank is fixed by its leg count (e.g. the two-leg result of `matricize`), which reads more clearly at the call site than the generic `Array`. Both are handled by a single `Array{<:Any, N}` method that defaults the eltype and forwards to the existing `Array{T, N}` conversion, so a rank mismatch (a non-two-leg tensor into `Matrix`, a non-one-leg tensor into `Vector`) errors as expected.

Also removes the `AbstractArray{T}` / `AbstractArray{T, N}` constructors, and the `_checkaxs` / `copyto_axcheck!` helpers they used: `AbstractNamedTensor` is not an `AbstractArray`, so those constructors returned a named tensor from an `AbstractArray` constructor, and nothing called them.
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.85%. Comparing base (6e469b8) to head (71bc0a5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #228      +/-   ##
==========================================
+ Coverage   77.29%   77.85%   +0.55%     
==========================================
  Files          29       29              
  Lines        1718     1707      -11     
==========================================
+ Hits         1328     1329       +1     
+ Misses        390      378      -12     
Flag Coverage Δ
docs 27.28% <0.00%> (+0.17%) ⬆️

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 enabled auto-merge (squash) July 24, 2026 01:05
@mtfishman
mtfishman merged commit 00c01c1 into main Jul 24, 2026
18 checks passed
@mtfishman
mtfishman deleted the mf/matrix-vector-itensor branch July 24, 2026 01:21
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