Skip to content

Commit d1035bb

Browse files
committed
Fix creation of dense similar for linalg
1 parent cf8a145 commit d1035bb

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/auxiliary/blockarrays.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
similar_dense(::Type{Vector{T}}, sz::NTuple{N, Ti}) where {T,N,Ti} = Array{T, N}(undef, sz)
2+
similar_dense(::Type{TA}, sz) where {T,N,P,TA<:Base.SubArray{T,N,P}} = similar_dense(P, sz)
3+
similar_dense(::Type{TA}, sz) where {T,N,P,TA<:Base.ReshapedArray{T,N,P}} = similar_dense(P, sz)
4+
similar_dense(::Type{TA}, sz) where {T,N,TA<:AbstractArray{T,N}} = TA(undef, sz)
5+
function similar_dense(A::BlockMatrix{T, R}) where {T, R}
6+
Adense = similar_dense(eltype(R), size(A))
7+
return Adense
8+
end
9+
110
function copy_dense!(Adense, A)
211
for block_index in Iterators.product(blockaxes(A)...)
312
a = view(A, block_index...)

src/linalg/factorizations.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ for f! in (
2525
)
2626
@eval function MAK.$f!(t::AbstractBlockTensorMap, F, alg::AbstractAlgorithm)
2727
TensorKit.foreachblock(t, F...) do _, (tblock, Fblocks...)
28-
Fblocks′ = MAK.$f!(copy_dense!(similar(tblock, size(tblock)), tblock), alg)
28+
dense_block = similar_dense(tblock)
29+
Fblocks′ = MAK.$f!(copy_dense!(dense_block, tblock), alg)
2930
# deal with the case where the output is not in-place
3031
for (b′, b) in zip(Fblocks′, Fblocks)
3132
b === b′ || copy!(b, b′)
@@ -44,7 +45,8 @@ for f! in (
4445
)
4546
@eval function MAK.$f!(t::AbstractBlockTensorMap, N, alg::AbstractAlgorithm)
4647
TensorKit.foreachblock(t, N) do _, (tblock, Nblock)
47-
Nblock′ = MAK.$f!(copy_dense!(similar(tblock, size(tblock)), tblock), alg)
48+
dense_block = similar_dense(tblock)
49+
Nblock′ = MAK.$f!(copy_dense!(dense_block, tblock), alg)
4850
# deal with the case where the output is not the same as the input
4951
Nblock === Nblock′ || copy!(Nblock, Nblock′)
5052
return nothing

0 commit comments

Comments
 (0)