Skip to content

Commit 3fe0045

Browse files
Jutholeburgel
authored andcommitted
one more gpu attempt
1 parent 9469d79 commit 3fe0045

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎src/pullbacks/eigh.jl‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ function check_and_prepare_eigh_cotangents(
77
# Only the columns ind₀ of VᴴΔV and VᴴΔAV are computed; their rows ind₀ follow by antihermiticity
88
n, p = size(V)
99
ind₀ = select_indices(axes(D, 1), ind)
10-
k = length(ind₀)
1110
if !iszerotangent(ΔV)
1211
n == size(ΔV, 1) || throw(DimensionMismatch())
13-
k == size(ΔV, 2) || throw(DimensionMismatch())
12+
length(ind₀) == size(ΔV, 2) || throw(DimensionMismatch())
1413
VᴴΔV₀ = V' * ΔV
1514
if p == n
1615
ΔV₊ = zero(ΔV)
@@ -20,7 +19,7 @@ function check_and_prepare_eigh_cotangents(
2019
aVᴴΔV₀ = antihermitian_columns!(VᴴΔV₀, ind₀)
2120
else
2221
ΔV₊ = nothing
23-
aVᴴΔV₀ = zero!(similar(V, (p, k)))
22+
aVᴴΔV₀ = zero!(similar(V, (p, length(ind₀))))
2423
end
2524

2625
D₀ = D[ind₀]
@@ -35,8 +34,8 @@ function check_and_prepare_eigh_cotangents(
3534

3635
if !iszerotangent(ΔDmat)
3736
ΔD = diagview(ΔDmat)
38-
k == length(ΔD) || throw(DimensionMismatch())
39-
diagview(view(VᴴΔAV₀, ind₀, :)) .+= real.(ΔD)
37+
length(ind₀) == length(ΔD) || throw(DimensionMismatch())
38+
VᴴΔAV₀[ind₀ .+ p .* (0:(length(ind₀) - 1))] .+= real.(ΔD)
4039
else
4140
ΔD = nothing
4241
end

‎src/pullbacks/svd.jl‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function check_and_prepare_svd_cotangents(
2323
J₁ = findall(<=(r), indS)
2424
J₂ = findall(>(r), indS)
2525
ind₀ = indS[J₁]
26-
k = length(ind₀)
2726
full_rank = (ind₀ == 1:minmn)
2827

2928
if !iszerotangent(ΔU)
@@ -51,7 +50,7 @@ function check_and_prepare_svd_cotangents(
5150
Δgauge = max(Δgauge, ΔgaugeU)
5251
else
5352
ΔU₊ = nothing
54-
aUᴴΔU₁₀ = zero!(similar(U₁, (r, k)))
53+
aUᴴΔU₁₀ = zero!(similar(U₁, (r, length(ind₀))))
5554
end
5655
if !iszerotangent(ΔVᴴ)
5756
ΔgaugeV = zero(eltype(S))
@@ -78,7 +77,7 @@ function check_and_prepare_svd_cotangents(
7877
Δgauge = max(Δgauge, ΔgaugeV)
7978
else
8079
ΔV₊ᴴ = nothing
81-
aVᴴΔV₁₀ = zero!(similar(V₁ᴴ, (r, k)))
80+
aVᴴΔV₁₀ = zero!(similar(V₁ᴴ, (r, length(ind₀))))
8281
end
8382

8483
S₀ = S[ind₀] # view fails broadcasting below on GPU
@@ -91,7 +90,7 @@ function check_and_prepare_svd_cotangents(
9190
if !iszerotangent(ΔSmat)
9291
ΔS = diagview(ΔSmat)
9392
length(indS) == length(ΔS) || throw(DimensionMismatch(lazy"length of selected S values ($(length(indS))) does not match length of ΔS ($(length(ΔS)))"))
94-
diagview(view(hUᴴΔAV₁₀, ind₀, :)) .+= real.(view(ΔS, J₁)) # diagonal entries
93+
hUᴴΔAV₁₀[ind₀ .+ r .* (0:length(ind₀)-1)] .+= real.(view(ΔS, J₁)) # diagonal entries
9594
Δgauge = max(Δgauge, maximum(abs, view(ΔS, J₂); init = zero(Δgauge)))
9695
end
9796

0 commit comments

Comments
 (0)