From 59703aca3b6b1a5190c91996426c9d93f77150f4 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Tue, 27 Oct 2026 10:56:00 -0400 Subject: [PATCH] Infer the axes of an ITensor Build the named axes behind a function barrier, indexing the names by position, since an `ITensor`'s parent is untyped and its names are a `Vector`. Co-Authored-By: Claude Opus 5.5 (1M context) --- Project.toml | 2 +- src/abstractnamedtensor.jl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 2640966..300a2b8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorBase" uuid = "4795dd04-0d67-49bb-8f44-b89c448a1dc7" -version = "0.16.3" +version = "0.16.4" authors = ["ITensor developers and contributors"] [workspace] diff --git a/src/abstractnamedtensor.jl b/src/abstractnamedtensor.jl index 9167f31..04380d2 100644 --- a/src/abstractnamedtensor.jl +++ b/src/abstractnamedtensor.jl @@ -251,8 +251,12 @@ Base.Array{<:Any, N}(a::AbstractNamedTensor) where {N} = Array{eltype(a), N}(a) # Read the parent's axes through TensorAlgebra's interface (not `Base.axes`) so a non-array # backend like a TensorMap, whose axes are its native spaces, is supported. function Base.axes(a::AbstractNamedTensor) - return NamedUnitRange.(TensorAlgebra.axes(unnamed(a)), Tuple(names(a))) + return namedaxes(TensorAlgebra.axes(unnamed(a)), names(a)) end +# A function barrier: an `ITensor`'s parent is untyped, so its axes are only known at runtime. +# The names are indexed by position rather than converted with `Tuple`, since they may be stored +# in a `Vector` whose length is unknown to the compiler. +namedaxes(axs::Tuple, ns) = ntuple(i -> NamedUnitRange(axs[i], ns[i]), Val(length(axs))) function Base.size(a::AbstractNamedTensor) return length.(axes(a)) end