@@ -28,14 +28,13 @@ function svd_pullback!(
2828 degeneracy_atol:: Real = tol,
2929 gauge_atol:: Real = tol
3030 )
31-
3231 # Extract the SVD components
3332 U, Smat, Vᴴ = USVᴴ
3433 m, n = size (U, 1 ), size (Vᴴ, 2 )
35- (m, n) == size (ΔA) || throw (DimensionMismatch ())
34+ (m, n) == size (ΔA) || throw (DimensionMismatch (" size of ΔA ( $( size (ΔA)) ) does not match size of U*S*Vᴴ ( $m , $n ) " ))
3635 minmn = min (m, n)
3736 S = diagview (Smat)
38- length (S) == minmn || throw (DimensionMismatch ())
37+ length (S) == minmn || throw (DimensionMismatch (" length of S ( $( length (S)) ) does not matrix minimum dimension of U, Vᴴ ( $minmn ) " ))
3938 r = searchsortedlast (S, rank_atol; rev = true ) # rank
4039 Ur = view (U, :, 1 : r)
4140 Vᴴr = view (Vᴴ, 1 : r, :)
@@ -46,22 +45,22 @@ function svd_pullback!(
4645 UΔU = fill! (similar (U, (r, r)), 0 )
4746 VΔV = fill! (similar (Vᴴ, (r, r)), 0 )
4847 if ! iszerotangent (ΔU)
49- m == size (ΔU, 1 ) || throw (DimensionMismatch ())
48+ m == size (ΔU, 1 ) || throw (DimensionMismatch (" first dimension of ΔU ( $( size (ΔU, 1 )) ) does not match first dimension of U ( $m ) " ))
5049 pU = size (ΔU, 2 )
51- pU > r && throw (DimensionMismatch ())
50+ pU > r && throw (DimensionMismatch (" second dimension of ΔU ( $( size (ΔU, 2 )) ) does not match rank of S ( $r ) " ))
5251 indU = axes (U, 2 )[ind]
53- length (indU) == pU || throw (DimensionMismatch ())
52+ length (indU) == pU || throw (DimensionMismatch (" length of selected U columns ( $( length (indU)) ) does not match second dimension of ΔU ( $( size (ΔU, 2 )) ) " ))
5453 UΔUp = view (UΔU, :, indU)
5554 mul! (UΔUp, Ur' , ΔU)
5655 # ΔU -= Ur * UΔUp but one less allocation without overwriting ΔU
5756 ΔU = mul! (copy (ΔU), Ur, UΔUp, - 1 , 1 )
5857 end
5958 if ! iszerotangent (ΔVᴴ)
60- n == size (ΔVᴴ, 2 ) || throw (DimensionMismatch ())
59+ n == size (ΔVᴴ, 2 ) || throw (DimensionMismatch (" second dimension of ΔVᴴ ( $( size (ΔVᴴ, 2 )) ) does not match second dimension of Vᴴ ( $n ) " ))
6160 pV = size (ΔVᴴ, 1 )
62- pV > r && throw (DimensionMismatch ())
61+ pV > r && throw (DimensionMismatch (" first dimension of ΔVᴴ ( $( size (ΔVᴴ, 1 )) ) does not match rank of S ( $r ) " ))
6362 indV = axes (Vᴴ, 1 )[ind]
64- length (indV) == pV || throw (DimensionMismatch ())
63+ length (indV) == pV || throw (DimensionMismatch (" length of selected Vᴴ rows ( $( length (indV)) ) does not match first dimension of ΔVᴴ ( $( size (ΔVᴴ, 1 )) ) " ))
6564 VΔVp = view (VΔV, :, indV)
6665 mul! (VΔVp, Vᴴr, ΔVᴴ' )
6766 # ΔVᴴ -= VΔVp' * Vᴴr but one less allocation without overwriting ΔVᴴ
@@ -84,7 +83,7 @@ function svd_pullback!(
8483 ΔS = diagview (ΔSmat)
8584 pS = length (ΔS)
8685 indS = axes (S, 1 )[ind]
87- length (indS) == pS || throw (DimensionMismatch ())
86+ length (indS) == pS || throw (DimensionMismatch (" length of selected S diagonals ( $( length (indS)) ) does not match length of ΔS diagonal ( $( length (ΔS)) ) " ))
8887 view (diagview (UdΔAV), indS) .+ = real .(ΔS)
8988 end
9089 ΔA = mul! (ΔA, Ur, UdΔAV * Vᴴr, 1 , 1 ) # add the contribution to ΔA
0 commit comments