@@ -292,6 +292,84 @@ See [`twist!`](@ref) for storing the result in place.
292292"""
293293twist (t:: AbstractTensorMap , i; inv:: Bool = false ) = twist! (copy (t), i; inv)
294294
295+ """
296+ insertleftunit(tsrc::AbstractTensorMap, i::Int=numind(t) + 1;
297+ conj=false, dual=false, copy=false) -> tdst
298+
299+ Insert a trivial vector space, isomorphic to the underlying field, at position `i`.
300+ More specifically, adds a left monoidal unit or its dual.
301+
302+ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
303+
304+ See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
305+ """
306+ @constprop :aggressive function insertleftunit (t:: AbstractTensorMap ,
307+ i:: Int = numind (t) + 1 ; copy:: Bool = true ,
308+ conj:: Bool = false , dual:: Bool = false )
309+ W = insertleftunit (space (t), i; conj, dual)
310+ tdst = similar (t, W)
311+ for (c, b) in blocks (t)
312+ copy! (block (tdst, c), b)
313+ end
314+ return tdst
315+ end
316+ @constprop :aggressive function insertleftunit (t:: TensorMap , i:: Int = numind (t) + 1 ;
317+ copy:: Bool = false ,
318+ conj:: Bool = false , dual:: Bool = false )
319+ W = insertleftunit (space (t), i; conj, dual)
320+ return TensorMap {scalartype(t)} (copy ? Base. copy (t. data) : t. data, W)
321+ end
322+
323+ """
324+ insertrightunit(tsrc::AbstractTensorMap, i::Int=numind(t);
325+ conj=false, dual=false, copy=false) -> tdst
326+
327+ Insert a trivial vector space, isomorphic to the underlying field, after position `i`.
328+ More specifically, adds a right monoidal unit or its dual.
329+
330+ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
331+
332+ See also [`insertleftunit`](@ref) and [`removeunit`](@ref).
333+ """
334+ @constprop :aggressive function insertrightunit (t:: AbstractTensorMap , i:: Int = numind (t);
335+ copy:: Bool = true , kwargs... )
336+ W = insertrightunit (space (t), i; kwargs... )
337+ tdst = similar (t, W)
338+ for (c, b) in blocks (t)
339+ copy! (block (tdst, c), b)
340+ end
341+ return tdst
342+ end
343+ @constprop :aggressive function insertrightunit (t:: TensorMap , i:: Int = numind (t);
344+ copy:: Bool = false , kwargs... )
345+ W = insertrightunit (space (t), i; kwargs... )
346+ return TensorMap {scalartype(t)} (copy ? Base. copy (t. data) : t. data, W)
347+ end
348+
349+ """
350+ removeunit(tsrc::AbstractTensorMap, i::Int; copy=false) -> tdst
351+
352+ This removes a trivial tensor product factor at position `1 ≤ i ≤ N`.
353+ For this to work, that factor has to be isomorphic to the field of scalars.
354+
355+ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
356+
357+ This operation undoes the work of [`insertunit`](@ref).
358+ """
359+ @constprop :aggressive function removeunit (t:: TensorMap , i:: Int ; copy:: Bool = false )
360+ W = removeunit (space (t), i)
361+ return TensorMap {scalartype(t)} (copy ? Base. copy (t. data) : t. data, W)
362+ end
363+ @constprop :aggressive function removeunit (t:: AbstractTensorMap , i:: Int ;
364+ copy:: Bool = true )
365+ W = removeunit (space (t), i)
366+ tdst = similar (t, W)
367+ for (c, b) in blocks (t)
368+ copy! (block (tdst, c), b)
369+ end
370+ return tdst
371+ end
372+
295373# Fusing and splitting
296374# TODO : add functionality for easy fusing and splitting of tensor indices
297375
0 commit comments