@@ -7,6 +7,7 @@ _adjoint(alg::MAK.LAPACK_HouseholderLQ) = MAK.LAPACK_HouseholderQR(; alg.kwargs.
77_adjoint (alg:: MAK.LAPACK_HouseholderQL ) = MAK. LAPACK_HouseholderRQ (; alg. kwargs... )
88_adjoint (alg:: MAK.LAPACK_HouseholderRQ ) = MAK. LAPACK_HouseholderQL (; alg. kwargs... )
99_adjoint (alg:: MAK.PolarViaSVD ) = MAK. PolarViaSVD (_adjoint (alg. svd_alg))
10+ _adjoint (alg:: TruncatedAlgorithm ) = TruncatedAlgorithm (_adjoint (alg. alg), alg. trunc)
1011_adjoint (alg:: AbstractAlgorithm ) = alg
1112
1213_adjoint (alg:: MAK.CUSOLVER_HouseholderQR ) = MAK. LQViaTransposedQR (alg)
@@ -81,7 +82,7 @@ for (left_f, right_f) in zip(
8182end
8283
8384# 3-arg functions
84- for f in (:svd_full , :svd_compact )
85+ for f in (:svd_full , :svd_compact , :svd_trunc )
8586 f! = Symbol (f, :! )
8687 @eval function MAK. copy_input (:: typeof ($ f), t:: AdjointTensorMap )
8788 return adjoint (MAK. copy_input ($ f, adjoint (t)))
@@ -93,9 +94,16 @@ for f in (:svd_full, :svd_compact)
9394 return reverse (adjoint .(MAK. initialize_output ($ f!, adjoint (t), _adjoint (alg))))
9495 end
9596
96- @eval function MAK. $f! (t:: AdjointTensorMap , F, alg:: AbstractAlgorithm )
97- F′ = $ f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
98- return reverse (adjoint .(F′))
97+ if f === :svd_trunc
98+ function MAK. svd_trunc! (t:: AdjointTensorMap , F, alg:: AbstractAlgorithm )
99+ U, S, Vᴴ, ϵ = svd_trunc! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
100+ return Vᴴ' , S, U' , ϵ
101+ end
102+ else
103+ @eval function MAK. $f! (t:: AdjointTensorMap , F, alg:: AbstractAlgorithm )
104+ F′ = $ f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
105+ return reverse (adjoint .(F′))
106+ end
99107 end
100108
101109 # disambiguate by prohibition
@@ -111,6 +119,15 @@ function MAK.svd_compact!(t::AdjointTensorMap, F, alg::DiagonalAlgorithm)
111119 F′ = svd_compact! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
112120 return reverse (adjoint .(F′))
113121end
122+ function MAK. initialize_output (
123+ :: typeof (svd_trunc!), t:: AdjointTensorMap , alg:: TruncatedAlgorithm
124+ )
125+ return reverse (adjoint .(MAK. initialize_output (svd_trunc!, adjoint (t), _adjoint (alg))))
126+ end
127+ function MAK. svd_trunc! (t:: AdjointTensorMap , F, alg:: TruncatedAlgorithm )
128+ U, S, Vᴴ, ϵ = svd_trunc! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
129+ return Vᴴ' , S, U' , ϵ
130+ end
114131
115132function LinearAlgebra. isposdef (t:: AdjointTensorMap )
116133 return isposdef (adjoint (t))
0 commit comments