Add Matrix/Vector conversion for named tensors#228
Merged
Conversation
## 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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mtfishman
enabled auto-merge (squash)
July 24, 2026 01:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Matrix(::AbstractNamedTensor)andVector(::AbstractNamedTensor)for densifying a named tensor whose rank is fixed by its leg count (e.g. the two-leg result ofmatricize), which reads more clearly at the call site than the genericArray. Both are handled by a singleArray{<:Any, N}method that defaults the eltype and forwards to the existingArray{T, N}conversion, so a rank mismatch (a non-two-leg tensor intoMatrix, a non-one-leg tensor intoVector) errors as expected.Also removes the
AbstractArray{T}/AbstractArray{T, N}constructors, and the_checkaxs/copyto_axcheck!helpers they used:AbstractNamedTensoris not anAbstractArray, so those constructors returned a named tensor from anAbstractArrayconstructor, and nothing called them.