Skip to content

Commit aacafc1

Browse files
committed
update insertleft/rightunitspace
1 parent a8046b2 commit aacafc1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/spaces/productspace.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,15 @@ See also [`insertrightunitspace`](@ref insertrightunitspace(::ProductSpace, ::Va
257257
"""
258258
function insertleftunitspace(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
259259
conj::Bool=false, dual::Bool=false) where {i}
260-
u = unitspace(spacetype(P))
260+
N = length(P)
261+
I = sectortype(P)
262+
if UnitStyle(I) isa SimpleUnit
263+
u = unitspace(spacetype(P))
264+
else
265+
N > 0 || throw(ArgumentError("cannot insert a sensible unit space in the empty product space"))
266+
i > N && throw(DomainError((P, i), "cannot insert a sensible left unit space"))
267+
u = leftunitspace(P[i])
268+
end
261269
if dual
262270
u = TensorKit.dual(u)
263271
end
@@ -278,7 +286,15 @@ See also [`insertleftunitspace`](@ref insertleftunitspace(::ProductSpace, ::Val{
278286
"""
279287
function insertrightunitspace(P::ProductSpace, ::Val{i}=Val(length(P));
280288
conj::Bool=false, dual::Bool=false) where {i}
281-
u = unitspace(spacetype(P))
289+
N = length(P)
290+
I = sectortype(P)
291+
if UnitStyle(I) isa SimpleUnit
292+
u = unitspace(spacetype(P))
293+
else
294+
N > 0 || throw(ArgumentError("cannot insert a sensible unit space in the empty product space"))
295+
i == 0 && throw(DomainError((P, i), "cannot insert a sensible right unit space"))
296+
u = rightunitspace(P[i])
297+
end
282298
if dual
283299
u = TensorKit.dual(u)
284300
end

0 commit comments

Comments
 (0)