Skip to content

Commit f32e189

Browse files
mtfishmanclaude
andauthored
Loosen linkdim(::AbstractITensorNetwork, ::AbstractEdge) signature (#373)
## Summary Drop the `where V` constraint on `linkdim(::AbstractITensorNetwork{V}, ::AbstractEdge{V})`. The previous form required the network's vertex-type parameter and the edge's vertex-type parameter to bind to the same `V`, which fails when the network's `V` is abstract and the edge's `V` is a concrete subtype (e.g. an `ITensorNetwork{Any}` paired with a `NamedEdge{Int}`). `linkinds` itself accepts the edge in that case, so the constraint was just blocking dispatch unnecessarily. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c0cb74d commit f32e189

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/abstractitensornetwork.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ function linkdim(tn::AbstractITensorNetwork, edge::Pair)
556556
return linkdim(tn, edgetype(tn)(edge))
557557
end
558558

559-
function linkdim(tn::AbstractITensorNetwork{V}, edge::AbstractEdge{V}) where {V}
559+
function linkdim(tn::AbstractITensorNetwork, edge::AbstractEdge)
560560
ls = linkinds(tn, edge)
561561
return prod([isnothing(l) ? 1 : dim(l) for l in ls])
562562
end

test/test_itensornetwork.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,16 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
250250
tn = random_tensornetwork(rng, is; link_space = 3)
251251
@test_broken swapprime(tn, 0, 2)
252252
end
253+
254+
# Regression test for https://github.com/ITensor/ITensorNetworks.jl/pull/373.
255+
@testset "linkdim accepts an AbstractEdge whose vertex type is a subtype" begin
256+
i = Index(2)
257+
A = ITensor(i)
258+
B = ITensor(i)
259+
tn = ITensorNetwork{Any}(Dictionary([1, 2], [A, B]))
260+
@test tn isa ITensorNetwork{Any}
261+
e = NamedEdge(1 => 2)
262+
@test e isa NamedEdge{Int}
263+
@test ITensorNetworks.linkdim(tn, e) == 2
264+
end
253265
end

0 commit comments

Comments
 (0)