11"""
2- left_polar_pullback!(ΔA, A, WP, ΔWP)
2+ left_polar_pullback!(
3+ ΔA, A, WP, ΔWP;
4+ rank_atol::Real = default_pullback_rank_atol(WP[2]),
5+ gauge_atol::Real = default_pullback_gauge_atol(ΔWP...)
6+ )
37
48Adds the pullback from the left polar decomposition of `A` to `ΔA` given the output `WP` and
59cotangent `ΔWP` of `left_polar(A)`.
10+
11+ Eigenvalues of `P` smaller than `rank_atol` are treated as zero, in which case `A` is rank
12+ deficient and `W` is not uniquely determined on the null space of `P`. Components of `ΔW`
13+ along this null space are discarded.
614"""
7- function left_polar_pullback! (ΔA:: AbstractMatrix , A, WP, ΔWP; kwargs... )
15+ function left_polar_pullback! (
16+ ΔA:: AbstractMatrix , A, WP, ΔWP;
17+ rank_atol:: Real = default_pullback_rank_atol (WP[2 ]),
18+ gauge_atol:: Real = default_pullback_gauge_atol (ΔWP... )
19+ )
820 # Extract the Polar components
921 W, P = WP
1022
@@ -13,28 +25,47 @@ function left_polar_pullback!(ΔA::AbstractMatrix, A, WP, ΔWP; kwargs...)
1325 if ! iszerotangent (ΔP)
1426 ΔP = project_hermitian (ΔP)
1527 end
28+ D, U = eigh_full (P)
29+ d = diagview (D)
1630 M = zero (P)
1731 ! iszerotangent (ΔW) && mul! (M, W' , ΔW, 1 , 1 )
1832 ! iszerotangent (ΔP) && mul! (M, ΔP, P, - 1 , 1 )
19- C = _sylvester (P, P , M' - M)
33+ C, Δgauge = _sylvester_psd (U, d , M - M' , rank_atol )
2034 ! iszerotangent (ΔP) && (C .+ = ΔP)
2135 ΔA = mul! (ΔA, W, C, 1 , 1 )
2236 if ! iszerotangent (ΔW)
23- ΔWP = ΔW / P
24- WdΔWP = W' * ΔWP
25- ΔWP = mul! (ΔWP, W, WdΔWP, - 1 , 1 )
26- ΔA .+ = ΔWP
37+ # (1 - W * W') * ΔW * pinv(P)
38+ ΔWU = ΔW * U
39+ WᴴΔWU = W' * ΔWU
40+ ΔWU = mul! (ΔWU, W, WᴴΔWU, - 1 , 1 )
41+ Δgauge = max (Δgauge, maximum (abs, (abs .(transpose (d)) .< rank_atol) .* ΔWU; init = zero (real (eltype (ΔWU)))))
42+ ΔWU .*= transpose (inv_safe .(d, rank_atol))
43+ ΔA = mul! (ΔA, ΔWU, U' , 1 , 1 )
2744 end
45+ Δgauge ≤ gauge_atol ||
46+ @warn " `left_polar` cotangents sensitive to gauge choice: (|Δgauge| = $Δgauge )"
2847 return ΔA
2948end
3049
3150"""
32- right_polar_pullback!(ΔA, A, PWᴴ, ΔPWᴴ)
51+ right_polar_pullback!(
52+ ΔA, A, PWᴴ, ΔPWᴴ;
53+ rank_atol::Real = default_pullback_rank_atol(PWᴴ[1]),
54+ gauge_atol::Real = default_pullback_gauge_atol(ΔPWᴴ...)
55+ )
3356
34- Adds the pullback from the left polar decomposition of `A` to `ΔA` given the output `PWᴴ`
57+ Adds the pullback from the right polar decomposition of `A` to `ΔA` given the output `PWᴴ`
3558and cotangent `ΔPWᴴ` of `right_polar(A)`.
59+
60+ Eigenvalues of `P` smaller than `rank_atol` are treated as zero, in which case `A` is rank
61+ deficient and `Wᴴ` is not uniquely determined on the null space of `P`. Components of `ΔWᴴ`
62+ along this null space are discarded.
3663"""
37- function right_polar_pullback! (ΔA:: AbstractMatrix , A, PWᴴ, ΔPWᴴ; kwargs... )
64+ function right_polar_pullback! (
65+ ΔA:: AbstractMatrix , A, PWᴴ, ΔPWᴴ;
66+ rank_atol:: Real = default_pullback_rank_atol (PWᴴ[1 ]),
67+ gauge_atol:: Real = default_pullback_gauge_atol (ΔPWᴴ... )
68+ )
3869 # Extract the Polar components
3970 P, Wᴴ = PWᴴ
4071
@@ -43,17 +74,24 @@ function right_polar_pullback!(ΔA::AbstractMatrix, A, PWᴴ, ΔPWᴴ; kwargs...
4374 if ! iszerotangent (ΔP)
4475 ΔP = project_hermitian (ΔP)
4576 end
77+ D, U = eigh_full (P)
78+ d = diagview (D)
4679 M = zero (P)
4780 ! iszerotangent (ΔWᴴ) && mul! (M, ΔWᴴ, Wᴴ' , 1 , 1 )
4881 ! iszerotangent (ΔP) && mul! (M, P, ΔP, - 1 , 1 )
49- C = _sylvester (P, P , M' - M)
82+ C, Δgauge = _sylvester_psd (U, d , M - M' , rank_atol )
5083 ! iszerotangent (ΔP) && (C .+ = ΔP)
5184 ΔA = mul! (ΔA, C, Wᴴ, 1 , 1 )
5285 if ! iszerotangent (ΔWᴴ)
53- PΔWᴴ = P \ ΔWᴴ
54- PΔWᴴW = PΔWᴴ * Wᴴ'
55- PΔWᴴ = mul! (PΔWᴴ, PΔWᴴW, Wᴴ, - 1 , 1 )
56- ΔA .+ = PΔWᴴ
86+ # pinv(P) * ΔWᴴ * (1 - Wᴴ' * Wᴴ)
87+ UᴴΔWᴴ = U' * ΔWᴴ
88+ UᴴΔWᴴW = UᴴΔWᴴ * Wᴴ'
89+ UᴴΔWᴴ = mul! (UᴴΔWᴴ, UᴴΔWᴴW, Wᴴ, - 1 , 1 )
90+ Δgauge = max (Δgauge, maximum (abs, (abs .(d) .< rank_atol) .* UᴴΔWᴴ; init = zero (real (eltype (UᴴΔWᴴ)))))
91+ UᴴΔWᴴ .*= inv_safe .(d, rank_atol)
92+ ΔA = mul! (ΔA, U, UᴴΔWᴴ, 1 , 1 )
5793 end
94+ Δgauge ≤ gauge_atol ||
95+ @warn " `right_polar` cotangents sensitive to gauge choice: (|Δgauge| = $Δgauge )"
5896 return ΔA
5997end
0 commit comments