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
9 changes: 9 additions & 0 deletions src/auxiliary/blockarrays.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
similar_dense(::Type{Vector{T}}, sz::Dims{N}) where {T, N} = Array{T, N}(undef, sz)
similar_dense(::Type{TA}, sz) where {T, N, P, TA <: Base.SubArray{T, N, P}} = similar_dense(P, sz)
similar_dense(::Type{TA}, sz) where {T, N, P, TA <: Base.ReshapedArray{T, N, P}} = similar_dense(P, sz)
similar_dense(::Type{TA}, sz) where {T, N, TA <: AbstractArray{T, N}} = TA(undef, sz)
function similar_dense(A::BlockMatrix{T, R}) where {T, R}
Adense = similar_dense(eltype(R), size(A))
return Adense
end

function copy_dense!(Adense, A)
for block_index in Iterators.product(blockaxes(A)...)
a = view(A, block_index...)
Expand Down
6 changes: 4 additions & 2 deletions src/linalg/factorizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ for f! in (
)
@eval function MAK.$f!(t::AbstractBlockTensorMap, F, alg::AbstractAlgorithm)
TensorKit.foreachblock(t, F...) do _, (tblock, Fblocks...)
Fblocks′ = MAK.$f!(copy_dense!(similar(tblock, size(tblock)), tblock), alg)
dense_block = similar_dense(tblock)
Fblocks′ = MAK.$f!(copy_dense!(dense_block, tblock), alg)
# deal with the case where the output is not in-place
for (b′, b) in zip(Fblocks′, Fblocks)
b === b′ || copy!(b, b′)
Expand All @@ -44,7 +45,8 @@ for f! in (
)
@eval function MAK.$f!(t::AbstractBlockTensorMap, N, alg::AbstractAlgorithm)
TensorKit.foreachblock(t, N) do _, (tblock, Nblock)
Nblock′ = MAK.$f!(copy_dense!(similar(tblock, size(tblock)), tblock), alg)
dense_block = similar_dense(tblock)
Nblock′ = MAK.$f!(copy_dense!(dense_block, tblock), alg)
# deal with the case where the output is not the same as the input
Nblock === Nblock′ || copy!(Nblock, Nblock′)
return nothing
Expand Down
Loading