@@ -512,6 +512,36 @@ function catcodomain(t1::TT, t2::TT) where {S,N₂,TT<:AbstractTensorMap{<:Any,S
512512 return t
513513end
514514
515+ """
516+ embed!(tdst::AbstactTensorMap, tsrc::AbstractTensorMap)
517+
518+ Embed the contents of `tsrc` into `tdst`, which may have different sizes of data.
519+ This is equivalent to the following operation on dense arrays, but also works for symmetric
520+ tensors. Note also that this only overwrites the regions that are shared, and will do
521+ nothing on the ones that are not, so it is up to the user to properly initialize the
522+ destination.
523+
524+ ```julia
525+ sub_axes = map((x, y) -> 1:min(x, y), size(tdst), size(tsrc))
526+ tdst[sub_axes...] .= tsrc[sub_axes...]
527+ ```
528+ """
529+ function embed! (tdst:: AbstractTensorMap , tsrc:: AbstractTensorMap )
530+ numin (tdst) == numin (tsrc) && numout (tdst) == numout (tsrc) ||
531+ throw (DimensionError (" Incompatible number of indices for source and destination" ))
532+ S = spacetype (tdst)
533+ S == spacetype (tsrc) || throw (SpaceMismatch (" incompatible spacetypes" ))
534+ dom = mapreduce (infimum, ⊗ , domain (tdst), domain (tsrc); init= one (S))
535+ cod = mapreduce (infimum, ⊗ , codomain (tdst), codomain (tsrc); init= one (S))
536+ for (f1, f2) in fusiontrees (cod ← dom)
537+ @inbounds data_dst = tdst[f1, f2]
538+ @inbounds data_src = tsrc[f1, f2]
539+ sub_axes = map (Base. OneTo ∘ min, size (data_dst), size (data_src))
540+ data_dst[sub_axes... ] .= data_src[sub_axes... ]
541+ end
542+ return tdst
543+ end
544+
515545# tensor product of tensors
516546"""
517547 ⊗(t1::AbstractTensorMap, t2::AbstractTensorMap, ...) -> TensorMap
0 commit comments