|
2 | 2 | # ---------- |
3 | 3 |
|
4 | 4 | function _copy_subblocks!(tdst, tsrc) |
5 | | - S = spacetype(tsrc) |
6 | 5 | N₁, N₂ = numout(tsrc), numin(tsrc) |
7 | | - for ((f₁, f₂), arr) in subblocks(tdst) |
8 | | - blockax = ntuple(N₁ + N₂) do i |
9 | | - return if i <= N₁ |
10 | | - blockedrange(map(Base.Fix2(dim, f₁.uncoupled[i]), space(tsrc, i))) |
11 | | - else |
12 | | - blockedrange(map(Base.Fix2(dim, f₂.uncoupled[i - N₁]), space(tsrc, i)')) |
13 | | - end |
14 | | - end |
15 | | - |
16 | | - for (k, v) in nonzero_pairs(tsrc) |
17 | | - indices = getindex.(blockax, Block.(Tuple(k))) |
18 | | - arr_slice = arr[indices...] |
19 | | - # need to check for empty since fusion tree pair might not be present |
20 | | - isempty(arr_slice) || copy!(arr_slice, v[f₁, f₂]) |
| 6 | + offsets = ntuple(i -> _sumspace_offsets(i <= N₁ ? codomain(tsrc)[i] : domain(tsrc)[i - N₁]), N₁ + N₂) |
| 7 | + # a single `SubblockIterator` holds the structure: `tdst[f₁, f₂]` would look it up in TensorKit's locked cache every time |
| 8 | + dstblocks = subblocks(tdst) |
| 9 | + for (k, v) in nonzero_pairs(tsrc), ((f₁, f₂), src) in subblocks(v) |
| 10 | + ranges = map(offsets, (f₁.uncoupled..., f₂.uncoupled...), Tuple(k)) do o, c, kᵢ |
| 11 | + return (o[c][kᵢ] + 1):o[c][kᵢ + 1] |
21 | 12 | end |
| 13 | + copy!(dstblocks[(f₁, f₂)][ranges...], src) |
22 | 14 | end |
23 | 15 | return tdst |
24 | 16 | end |
25 | 17 |
|
| 18 | +# for every sector `c` of `V`, the cumulative dimensions of `c` over the summands of `V` |
| 19 | +function _sumspace_offsets(V) |
| 20 | + return SectorDict{sectortype(V), Vector{Int}}(c => cumsum(vcat(0, [dim(Vᵢ, c) for Vᵢ in V])) for c in sectors(V)) |
| 21 | +end |
| 22 | + |
26 | 23 | function Base.convert(::Type{TensorMap}, t::AbstractBlockTensorMap) |
27 | 24 | S = spacetype(t) |
28 | 25 | N₁, N₂ = numout(t), numin(t) |
|
0 commit comments