Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockTensorKit"
uuid = "5f87ffc2-9cf1-4a46-8172-465d160bd8cd"
version = "0.3.19"
version = "0.3.20"
authors = ["Lukas Devos <ldevos98@gmail.com> and contributors"]

[deps]
Expand Down
27 changes: 12 additions & 15 deletions src/tensors/abstractblocktensor/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
# ----------

function _copy_subblocks!(tdst, tsrc)
S = spacetype(tsrc)
N₁, N₂ = numout(tsrc), numin(tsrc)
for ((f₁, f₂), arr) in subblocks(tdst)
blockax = ntuple(N₁ + N₂) do i
return if i <= N₁
blockedrange(map(Base.Fix2(dim, f₁.uncoupled[i]), space(tsrc, i)))
else
blockedrange(map(Base.Fix2(dim, f₂.uncoupled[i - N₁]), space(tsrc, i)'))
end
end

for (k, v) in nonzero_pairs(tsrc)
indices = getindex.(blockax, Block.(Tuple(k)))
arr_slice = arr[indices...]
# need to check for empty since fusion tree pair might not be present
isempty(arr_slice) || copy!(arr_slice, v[f₁, f₂])
offsets = ntuple(i -> _sumspace_offsets(i <= N₁ ? codomain(tsrc)[i] : domain(tsrc)[i - N₁]), N₁ + N₂)
# a single `SubblockIterator` holds the structure: `tdst[f₁, f₂]` would look it up in TensorKit's locked cache every time
dstblocks = subblocks(tdst)
for (k, v) in nonzero_pairs(tsrc), ((f₁, f₂), src) in subblocks(v)
ranges = map(offsets, (f₁.uncoupled..., f₂.uncoupled...), Tuple(k)) do o, c, kᵢ
return (o[c][kᵢ] + 1):o[c][kᵢ + 1]
end
copy!(dstblocks[(f₁, f₂)][ranges...], src)
end
return tdst
end

# for every sector `c` of `V`, the cumulative dimensions of `c` over the summands of `V`
function _sumspace_offsets(V)
return SectorDict{sectortype(V), Vector{Int}}(c => cumsum(vcat(0, [dim(Vᵢ, c) for Vᵢ in V])) for c in sectors(V))
end

function Base.convert(::Type{TensorMap}, t::AbstractBlockTensorMap)
S = spacetype(t)
N₁, N₂ = numout(t), numin(t)
Expand Down
Loading