Skip to content

Commit e9386ae

Browse files
Katharine Hyattkshyatt
authored andcommitted
Make a specialization to avoid Diagonal batching for now
1 parent bd35abe commit e9386ae

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎src/factorizations/diagonal.jl‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,40 @@ function MAK.initialize_output(::typeof(eig_vals!), t::AbstractTensorMap, alg::D
7878
A = similarstoragetype(t, Tc)
7979
return SectorVector{Tc, sectortype(t), A}(undef, V_D)
8080
end
81+
82+
for (f!, bf!) in ((:svd_vals!, :batched_svd_vals!),)
83+
# diagonals don't support batching yet
84+
@eval function MAK.$f!(t::AbstractTensorMap, N, alg::DiagonalAlgorithm)
85+
@timeit_debug GLOBAL_TIMER $(string(f!)) begin
86+
foreachblock(t, N) do _, (tblock, Nblock)
87+
@timeit_debug GLOBAL_TIMER "dense: MatrixAlgebraKit" begin
88+
Nblock′ = $f!(tblock, Nblock, alg)
89+
# deal with the case where the output is not the same as the input
90+
Nblock === Nblock′ || copy!(Nblock, Nblock′)
91+
end
92+
return nothing
93+
end
94+
end
95+
return N
96+
end
97+
end
98+
99+
for (f!, bf!) in ((:svd_full!, :batched_svd_full!),)
100+
@eval function MAK.$f!(t::AbstractTensorMap, F, alg::DiagonalAlgorithm)
101+
@timeit_debug GLOBAL_TIMER $(string(f!)) begin
102+
U, S, Vᴴ = F
103+
foreachblock(t, U, S, Vᴴ) do _, (tblock, Fblocks...)
104+
@timeit_debug GLOBAL_TIMER "dense: MatrixAlgebraKit" begin
105+
Fblocks′ = $f!(tblock, Fblocks, alg)
106+
# deal with the case where the output is not in-place
107+
for (b′, b) in zip(Fblocks′, Fblocks)
108+
b === b′ || copy!(b, b′)
109+
end
110+
end
111+
return nothing
112+
end
113+
return F
114+
end
115+
end
116+
end
117+

‎src/factorizations/matrixalgebrakit.jl‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ for (f!, bf!) in ((:svd_compact!, :batched_svd_compact!), (:svd_full!, :batched_
6666
if !isempty(cs) && MAK.supports_ragged_batch(MAK.$f!, alg, driver, storagetype(t))
6767
As = [block(t, c) for c in cs]
6868
Fs = ([block(U, c) for c in cs], [block(S, c) for c in cs], [block(Vᴴ, c) for c in cs])
69-
if applicable(MAK.$bf!, As, Fs, alg)
70-
@timeit_debug GLOBAL_TIMER "batched: MatrixAlgebraKit" MAK.$bf!(As, Fs, alg)
71-
return F
72-
end
69+
@timeit_debug GLOBAL_TIMER "batched: MatrixAlgebraKit" MAK.$bf!(As, Fs, alg)
70+
return F
7371
end
7472
foreachblock(t, U, S, Vᴴ) do _, (tblock, Fblocks...)
7573
@timeit_debug GLOBAL_TIMER "dense: MatrixAlgebraKit" begin
@@ -116,10 +114,8 @@ for (f!, bf!) in ((:svd_vals!, :batched_svd_vals!),)
116114
cs = collect(union(blocksectors.((t, N))...))
117115
if !isempty(cs) && MAK.supports_ragged_batch(MAK.$f!, alg, driver, storagetype(t))
118116
As, Ns = [block(t, c) for c in cs], [block(N, c) for c in cs]
119-
if applicable(MAK.$bf!, As, Ns, alg)
120-
@timeit_debug GLOBAL_TIMER "batched: MatrixAlgebraKit" MAK.$bf!(As, Ns, alg)
121-
return N
122-
end
117+
@timeit_debug GLOBAL_TIMER "batched: MatrixAlgebraKit" MAK.$bf!(As, Ns, alg)
118+
return N
123119
end
124120
foreachblock(t, N) do _, (tblock, Nblock)
125121
@timeit_debug GLOBAL_TIMER "dense: MatrixAlgebraKit" begin

0 commit comments

Comments
 (0)