Skip to content

Commit 1eefd43

Browse files
committed
get insertleft/rightunit working without explicit indices + edit some homspaces
1 parent b64ca37 commit 1eefd43

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/spaces/productspace.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,11 @@ function insertleftunit(
269269
u = unitspace(spacetype(P))
270270
else
271271
N > 0 || throw(ArgumentError("cannot insert a sensible unit space in the empty product space"))
272-
i > N && throw(DomainError((P, i), "cannot insert a sensible left unit space"))
273-
u = leftunitspace(P[i])
272+
if i == N + 1
273+
u = rightunitspace(P[N])
274+
else
275+
u = leftunitspace(P[i])
276+
end
274277
end
275278
if dual
276279
u = TensorKit.dual(u)
@@ -300,7 +303,6 @@ function insertrightunit(
300303
u = unitspace(spacetype(P))
301304
else
302305
N > 0 || throw(ArgumentError("cannot insert a sensible unit space in the empty product space"))
303-
i == 0 && throw(DomainError((P, i), "cannot insert a sensible right unit space"))
304306
u = rightunitspace(P[i])
305307
end
306308
if dual

test/tensors/tensors.jl

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,16 @@ for V in spacelist
151151
end
152152
end
153153
@timedtestset "Trivial space insertion and removal" begin
154-
W = V1 ⊗ V2 V3 V4 ⊗ V5
154+
W = V1 ⊗ V2 V3 V4 ⊗ V5
155155
for T in (Float32, ComplexF64)
156156
t = @constinferred rand(T, W)
157-
if isa(UnitStyle(I), SimpleUnit)
158-
t2 = @constinferred insertleftunit(t)
159-
@test t2 == @constinferred insertrightunit(t)
160-
@test space(t2) == insertleftunit(space(t))
161-
@test @constinferred(removeunit(t2, $(numind(t2)))) == t
162-
t3 = @constinferred insertleftunit(t; copy = true)
163-
@test t3 == @constinferred insertrightunit(t; copy = true)
164-
@test @constinferred(removeunit(t3, $(numind(t3)))) == t
165-
else
166-
t2 = @constinferred insertleftunit(t, 5)
167-
@test t2 == @constinferred insertrightunit(t, 4)
168-
@test space(t2) == insertleftunit(space(t), 5)
169-
@test @constinferred(removeunit(t2, $(numind(t2) - 1))) == t
170-
t3 = @constinferred insertleftunit(t, 5; copy = true)
171-
@test t3 == @constinferred insertrightunit(t, 4; copy = true)
172-
@test @constinferred(removeunit(t3, $(numind(t3) - 1))) == t
173-
end
157+
t2 = @constinferred insertleftunit(t)
158+
@test t2 == @constinferred insertrightunit(t)
159+
@test space(t2) == insertleftunit(space(t))
160+
@test @constinferred(removeunit(t2, $(numind(t2)))) == t
161+
t3 = @constinferred insertleftunit(t; copy = true)
162+
@test t3 == @constinferred insertrightunit(t; copy = true)
163+
@test @constinferred(removeunit(t3, $(numind(t3)))) == t
174164
175165
@test numind(t2) == numind(t) + 1
176166
@test scalartype(t2) === T
@@ -182,7 +172,7 @@ for V in spacelist
182172
end
183173
184174
t4 = @constinferred insertrightunit(t, 3; dual = true)
185-
@test numin(t4) == numin(t) && numout(t4) == numout(t) + 1
175+
@test numin(t4) == numin(t) + 1 && numout(t4) == numout(t)
186176
for (c, b) in blocks(t)
187177
@test b == block(t4, c)
188178
end
@@ -288,6 +278,7 @@ for V in spacelist
288278
end
289279
end
290280
symmetricbraiding && @timedtestset "Full trace: test self-consistency" begin
281+
# TODO: extend to multifusion but keep these @tensor tests
291282
t = rand(ComplexF64, V1 ⊗ V2' V1 V2')
292283
s = @constinferred tr(t)
293284
@test conj(s) ≈ tr(t')
@@ -446,7 +437,7 @@ for V in spacelist
446437
end
447438
end
448439
@timedtestset "diag/diagm" begin
449-
W = V1 ⊗ V2 V3 V4 ⊗ V5
440+
W = V1 ⊗ V2 V3 V4 ⊗ V5
450441
t = randn(ComplexF64, W)
451442
d = LinearAlgebra.diag(t)
452443
D = LinearAlgebra.diagm(codomain(t), domain(t), d)

0 commit comments

Comments
 (0)