@@ -26,14 +26,13 @@ function svd_pullback!(
2626 degeneracy_atol:: Real = default_pullback_rank_atol (USVᴴ[2 ]),
2727 gauge_atol:: Real = default_pullback_gauge_atol (ΔUSVᴴ[1 ], ΔUSVᴴ[3 ])
2828 )
29-
3029 # Extract the SVD components
3130 U, Smat, Vᴴ = USVᴴ
3231 m, n = size (U, 1 ), size (Vᴴ, 2 )
33- (m, n) == size (ΔA) || throw (DimensionMismatch ())
32+ (m, n) == size (ΔA) || throw (DimensionMismatch (" size of ΔA ( $( size (ΔA)) ) does not match size of U*S*Vᴴ ( $m , $n ) " ))
3433 minmn = min (m, n)
3534 S = diagview (Smat)
36- length (S) == minmn || throw (DimensionMismatch ())
35+ length (S) == minmn || throw (DimensionMismatch (" length of S ( $( length (S)) ) does not matrix minimum dimension of U, Vᴴ ( $minmn ) " ))
3736 r = searchsortedlast (S, rank_atol; rev = true ) # rank
3837 Ur = view (U, :, 1 : r)
3938 Vᴴr = view (Vᴴ, 1 : r, :)
@@ -44,22 +43,22 @@ function svd_pullback!(
4443 UΔU = fill! (similar (U, (r, r)), 0 )
4544 VΔV = fill! (similar (Vᴴ, (r, r)), 0 )
4645 if ! iszerotangent (ΔU)
47- m == size (ΔU, 1 ) || throw (DimensionMismatch ())
46+ m == size (ΔU, 1 ) || throw (DimensionMismatch (" first dimension of ΔU ( $( size (ΔU, 1 )) ) does not match first dimension of U ( $m ) " ))
4847 pU = size (ΔU, 2 )
49- pU > r && throw (DimensionMismatch ())
48+ pU > r && throw (DimensionMismatch (" second dimension of ΔU ( $( size (ΔU, 2 )) ) does not match rank of S ( $r ) " ))
5049 indU = axes (U, 2 )[ind]
51- length (indU) == pU || throw (DimensionMismatch ())
50+ length (indU) == pU || throw (DimensionMismatch (" length of selected U columns ( $( length (indU)) ) does not match second dimension of ΔU ( $( size (ΔU, 2 )) ) " ))
5251 UΔUp = view (UΔU, :, indU)
5352 mul! (UΔUp, Ur' , ΔU)
5453 # ΔU -= Ur * UΔUp but one less allocation without overwriting ΔU
5554 ΔU = mul! (copy (ΔU), Ur, UΔUp, - 1 , 1 )
5655 end
5756 if ! iszerotangent (ΔVᴴ)
58- n == size (ΔVᴴ, 2 ) || throw (DimensionMismatch ())
57+ n == size (ΔVᴴ, 2 ) || throw (DimensionMismatch (" second dimension of ΔVᴴ ( $( size (ΔVᴴ, 2 )) ) does not match second dimension of Vᴴ ( $n ) " ))
5958 pV = size (ΔVᴴ, 1 )
60- pV > r && throw (DimensionMismatch ())
59+ pV > r && throw (DimensionMismatch (" first dimension of ΔVᴴ ( $( size (ΔVᴴ, 1 )) ) does not match rank of S ( $r ) " ))
6160 indV = axes (Vᴴ, 1 )[ind]
62- length (indV) == pV || throw (DimensionMismatch ())
61+ length (indV) == pV || throw (DimensionMismatch (" length of selected Vᴴ rows ( $( length (indV)) ) does not match first dimension of ΔVᴴ ( $( size (ΔVᴴ, 1 )) ) " ))
6362 VΔVp = view (VΔV, :, indV)
6463 mul! (VΔVp, Vᴴr, ΔVᴴ' )
6564 # ΔVᴴ -= VΔVp' * Vᴴr but one less allocation without overwriting ΔVᴴ
@@ -82,7 +81,7 @@ function svd_pullback!(
8281 ΔS = diagview (ΔSmat)
8382 pS = length (ΔS)
8483 indS = axes (S, 1 )[ind]
85- length (indS) == pS || throw (DimensionMismatch ())
84+ length (indS) == pS || throw (DimensionMismatch (" length of selected S diagonals ( $( length (indS)) ) does not match length of ΔS diagonal ( $( length (ΔS)) ) " ))
8685 view (diagview (UdΔAV), indS) .+ = real .(ΔS)
8786 end
8887 ΔA = mul! (ΔA, Ur, UdΔAV * Vᴴr, 1 , 1 ) # add the contribution to ΔA
0 commit comments