Skip to content

Commit 2e3265a

Browse files
committed
rename absorb and add out-of-place version
1 parent ba73109 commit 2e3265a

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/TensorKit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export leftorth, rightorth, leftnull, rightnull,
7676
isposdef, isposdef!, ishermitian, sylvester, rank, cond
7777
export braid, braid!, permute, permute!, transpose, transpose!, twist, twist!, repartition,
7878
repartition!
79-
export catdomain, catcodomain, embed!
79+
export catdomain, catcodomain, absorb, absorb!
8080

8181
export OrthogonalFactorizationAlgorithm, QR, QRpos, QL, QLpos, LQ, LQpos, RQ, RQpos,
8282
SVD, SDD, Polar

src/tensors/linalg.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,10 @@ function catcodomain(t1::TT, t2::TT) where {S,N₂,TT<:AbstractTensorMap{<:Any,S
513513
end
514514

515515
"""
516-
embed!(tdst::AbstactTensorMap, tsrc::AbstractTensorMap)
516+
absorb(tdst::AbstractTensorMap, tsrc::AbstractTensorMap)
517+
absorb!(tdst::AbstactTensorMap, tsrc::AbstractTensorMap)
517518
518-
Embed the contents of `tsrc` into `tdst`, which may have different sizes of data.
519+
Absorb the contents of `tsrc` into `tdst`, which may have different sizes of data.
519520
This is equivalent to the following operation on dense arrays, but also works for symmetric
520521
tensors. Note also that this only overwrites the regions that are shared, and will do
521522
nothing on the ones that are not, so it is up to the user to properly initialize the
@@ -526,7 +527,8 @@ sub_axes = map((x, y) -> 1:min(x, y), size(tdst), size(tsrc))
526527
tdst[sub_axes...] .= tsrc[sub_axes...]
527528
```
528529
"""
529-
function embed!(tdst::AbstractTensorMap, tsrc::AbstractTensorMap)
530+
absorb(tdst::AbstractTensorMap, tsrc::AbstractTensorMap) = absorb!(copy(tdst), tsrc)
531+
function absorb!(tdst::AbstractTensorMap, tsrc::AbstractTensorMap)
530532
numin(tdst) == numin(tsrc) && numout(tdst) == numout(tsrc) ||
531533
throw(DimensionError("Incompatible number of indices for source and destination"))
532534
S = spacetype(tdst)

test/tensors.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -739,17 +739,26 @@ for V in spacelist
739739
@test t t′
740740
end
741741
end
742-
@timedtestset "Tensor embedding" begin
743-
t1 = rand(V1 V1, V2 V3)
742+
@timedtestset "Tensor absorpsion" begin
743+
# absorbing small into large
744+
t1 = zeros(V1 V1, V2 V3)
744745
t2 = rand(V1, V2 V3)
745-
746-
# embedding small into large
747-
t3 = @constinferred embed!(zerovector(t1), t2)
746+
t3 = @constinferred absorb(t1, t2)
748747
@test norm(t3) norm(t2)
748+
@test norm(t1) == 0
749+
t4 = @constinferred absorb!(t1, t2)
750+
@test t1 === t4
751+
@test t3 t4
749752

750-
# embedding large into small
751-
t4 = @constinferred embed!(zerovector(t2), t1)
752-
@test norm(t4) < norm(t1)
753+
# absorbing large into small
754+
t1 = rand(V1 V1, V2 V3)
755+
t2 = zeros(V1, V2 V3)
756+
t3 = @constinferred absorb(t2, t1)
757+
@test norm(t3) < norm(t1)
758+
@test norm(t2) == 0
759+
t4 = @constinferred absorb!(t2, t1)
760+
@test t2 === t4
761+
@test t3 t4
753762
end
754763
end
755764
TensorKit.empty_globalcaches!()

0 commit comments

Comments
 (0)