@@ -290,12 +290,45 @@ function Base.oneunit(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
290290 return SumSpace (oneunit (first (S. spaces)))
291291end
292292
293- # maybe from the homspace
294- function TensorKit. insertrightunit (P:: ProductSpace{V,N} , :: Val{i} = Val (length (P));
293+ # oneunit for spaces whose elements all belong to the same sector
294+ function rightoneunit (S:: GradedSpace{<:BimoduleSector} )
295+ allequal (a. j for a in sectors (S)) ||
296+ throw (ArgumentError (" sectors of $S do not have the same rightone" ))
297+
298+ allequal (a. i for a in sectors (S)) ||
299+ throw (ArgumentError (" sectors of $S are not all equal" ))
300+
301+ sector = rightone (first (sectors (S)))
302+ return spacetype (S)(sector => 1 )
303+ end
304+
305+ function rightoneunit (S:: SumSpace{<:GradedSpace{<:BimoduleSector}} )
306+ @assert ! isempty (S) " Cannot determine type of empty space"
307+ return SumSpace (rightoneunit (first (S. spaces)))
308+ end
309+
310+ function leftoneunit (S:: GradedSpace{<:BimoduleSector} )
311+ allequal (a. i for a in sectors (S)) ||
312+ throw (ArgumentError (" sectors of $S do not have the same leftone" ))
313+
314+ allequal (a. j for a in sectors (S)) ||
315+ throw (ArgumentError (" sectors of $S are not all equal" ))
316+
317+ sector = leftone (first (sectors (S)))
318+ return spacetype (S)(sector => 1 )
319+ end
320+
321+ function leftoneunit (S:: SumSpace{<:GradedSpace{<:BimoduleSector}} )
322+ @assert ! isempty (S) " Cannot determine type of empty space"
323+ return SumSpace (leftoneunit (first (S. spaces)))
324+ end
325+
326+ function TensorKit. insertrightunit (P:: ProductSpace{V,N} , :: Val{i} ;
295327 conj:: Bool = false ,
296328 dual:: Bool = false ) where {i,V<: GradedSpace{I} ,N} where {I<: BimoduleSector }
297- # possible change to rightone of correct space for N = 0
298- u = N > 0 ? oneunit (P[1 ]) : error (" no unit object in $P " )
329+ i > N && error (" cannot insert a sensible right unit onto $P at index $(i+ 1 ) " )
330+ # possible change to rightone of correct space for N = 0
331+ u = N > 0 ? rightoneunit (P[i]) : error (" no unit object in $P " )
299332 if dual
300333 u = TensorKit. dual (u)
301334 end
@@ -305,10 +338,12 @@ function TensorKit.insertrightunit(P::ProductSpace{V,N}, ::Val{i}=Val(length(P))
305338 return ProductSpace (TupleTools. insertafter (P. spaces, i, (u,)))
306339end
307340
308- function TensorKit. insertleftunit (P:: ProductSpace{V,N} , :: Val{i} = Val (length (P) + 1 );
341+ # possible TODO : overwrite defaults at level of HomSpace and TensorMap?
342+ function TensorKit. insertleftunit (P:: ProductSpace{V,N} , :: Val{i} ; # want no defaults?
309343 conj:: Bool = false ,
310344 dual:: Bool = false ) where {i,V<: GradedSpace{I} ,N} where {I<: BimoduleSector }
311- u = N > 0 ? oneunit (P[1 ]) : error (" no unit object in $P " )
345+ i > N && error (" cannot insert a sensible left unit onto $P at index $i " ) # do we want this to error in the diagonal case?
346+ u = N > 0 ? leftoneunit (P[i]) : error (" no unit object in $P " )
312347 if dual
313348 u = TensorKit. dual (u)
314349 end
0 commit comments