@@ -6,46 +6,54 @@ _adjoint(alg::MAK.LAPACK_HouseholderQR) = MAK.LAPACK_HouseholderLQ(; alg.kwargs.
66_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... )
9- _adjoint (alg:: MAK.PolarViaSVD ) = MAK. PolarViaSVD (_adjoint (alg. svdalg ))
9+ _adjoint (alg:: MAK.PolarViaSVD ) = MAK. PolarViaSVD (_adjoint (alg. svd_alg ))
1010_adjoint (alg:: AbstractAlgorithm ) = alg
1111
12- # 1-arg functions
13- function MAK. initialize_output (:: typeof (left_null!), t:: AdjointTensorMap , alg:: AbstractAlgorithm )
14- return adjoint (MAK. initialize_output (right_null!, adjoint (t), _adjoint (alg)))
15- end
16- function MAK. initialize_output (
17- :: typeof (right_null!), t:: AdjointTensorMap ,
18- alg:: AbstractAlgorithm
19- )
20- return adjoint (MAK. initialize_output (left_null!, adjoint (t), _adjoint (alg)))
12+ for f in
13+ [
14+ :svd_compact , :svd_full , :svd_vals ,
15+ :qr_compact , :qr_full , :qr_null ,
16+ :lq_compact , :lq_full , :lq_null ,
17+ :eig_full , :eig_vals , :eigh_full , :eigh_trunc , :eigh_vals ,
18+ :left_polar , :right_polar ,
19+ :project_hermitian , :project_antihermitian , :project_isometric ,
20+ ]
21+ f! = Symbol (f, :! )
22+ # just return the algorithm for the parent type since we are mapping this with
23+ # `_adjoint` afterwards anyways.
24+ # TODO : properly handle these cases
25+ @eval MAK. default_algorithm (:: typeof ($ f!), :: Type{T} ; kwargs... ) where {T <: AdjointTensorMap } =
26+ MAK. default_algorithm ($ f!, TensorKit. parenttype (T); kwargs... )
2127end
2228
23- function MAK. left_null! (t:: AdjointTensorMap , N, alg:: AbstractAlgorithm )
24- right_null! (adjoint (t), adjoint (N), _adjoint (alg))
25- return N
26- end
27- function MAK. right_null! (t:: AdjointTensorMap , N, alg:: AbstractAlgorithm )
28- left_null! (adjoint (t), adjoint (N), _adjoint (alg))
29- return N
30- end
29+ # 1-arg functions
30+ MAK. initialize_output (:: typeof (qr_null!), t:: AdjointTensorMap , alg:: AbstractAlgorithm ) =
31+ adjoint (MAK. initialize_output (lq_null!, adjoint (t), _adjoint (alg)))
32+ MAK. initialize_output (:: typeof (lq_null!), t:: AdjointTensorMap , alg:: AbstractAlgorithm ) =
33+ adjoint (MAK. initialize_output (qr_null!, adjoint (t), _adjoint (alg)))
3134
32- function MAK. is_left_isometry (t:: AdjointTensorMap ; kwargs... )
33- return is_right_isometry (adjoint (t); kwargs... )
34- end
35- function MAK. is_right_isometry (t:: AdjointTensorMap ; kwargs... )
36- return is_left_isometry (adjoint (t); kwargs... )
37- end
35+ MAK. qr_null! (t:: AdjointTensorMap , N, alg:: AbstractAlgorithm ) =
36+ lq_null! (adjoint (t), adjoint (N), _adjoint (alg))
37+ MAK. lq_null! (t:: AdjointTensorMap , N, alg:: AbstractAlgorithm ) =
38+ qr_null! (adjoint (t), adjoint (N), _adjoint (alg))
39+
40+ MAK. is_left_isometric (t:: AdjointTensorMap ; kwargs... ) =
41+ MAK. is_right_isometric (adjoint (t); kwargs... )
42+ MAK. is_right_isometric (t:: AdjointTensorMap ; kwargs... ) =
43+ MAK. is_left_isometric (adjoint (t); kwargs... )
3844
3945# 2-arg functions
40- for (left_f! , right_f! ) in zip (
41- (:qr_full! , :qr_compact! , :left_polar! , :left_orth! ),
42- (:lq_full! , :lq_compact! , :right_polar! , :right_orth! )
46+ for (left_f, right_f) in zip (
47+ (:qr_full , :qr_compact , :left_polar ),
48+ (:lq_full , :lq_compact , :right_polar )
4349 )
44- @eval function MAK. copy_input (:: typeof ($ left_f!), t:: AdjointTensorMap )
45- return adjoint (MAK. copy_input ($ right_f!, adjoint (t)))
50+ left_f! = Symbol (left_f, :! )
51+ right_f! = Symbol (right_f, :! )
52+ @eval function MAK. copy_input (:: typeof ($ left_f), t:: AdjointTensorMap )
53+ return adjoint (MAK. copy_input ($ right_f, adjoint (t)))
4654 end
47- @eval function MAK. copy_input (:: typeof ($ right_f! ), t:: AdjointTensorMap )
48- return adjoint (MAK. copy_input ($ left_f! , adjoint (t)))
55+ @eval function MAK. copy_input (:: typeof ($ right_f), t:: AdjointTensorMap )
56+ return adjoint (MAK. copy_input ($ left_f, adjoint (t)))
4957 end
5058
5159 @eval function MAK. initialize_output (
@@ -60,29 +68,31 @@ for (left_f!, right_f!) in zip(
6068 end
6169
6270 @eval function MAK. $left_f! (t:: AdjointTensorMap , F, alg:: AbstractAlgorithm )
63- $ right_f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
64- return F
71+ F′ = $ right_f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
72+ return reverse ( adjoint .(F′))
6573 end
6674 @eval function MAK. $right_f! (t:: AdjointTensorMap , F, alg:: AbstractAlgorithm )
67- $ left_f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
68- return F
75+ F′ = $ left_f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
76+ return reverse ( adjoint .(F′))
6977 end
7078end
7179
7280# 3-arg functions
73- for f! in (:svd_full! , :svd_compact! , :svd_trunc! )
74- @eval function MAK. copy_input (:: typeof ($ f!), t:: AdjointTensorMap )
75- return adjoint (MAK. copy_input ($ f!, adjoint (t)))
81+ for f in (:svd_full , :svd_compact )
82+ f! = Symbol (f, :! )
83+ @eval function MAK. copy_input (:: typeof ($ f), t:: AdjointTensorMap )
84+ return adjoint (MAK. copy_input ($ f, adjoint (t)))
7685 end
7786
7887 @eval function MAK. initialize_output (
7988 :: typeof ($ f!), t:: AdjointTensorMap , alg:: AbstractAlgorithm
8089 )
8190 return reverse (adjoint .(MAK. initialize_output ($ f!, adjoint (t), _adjoint (alg))))
8291 end
92+
8393 @eval function MAK. $f! (t:: AdjointTensorMap , F, alg:: AbstractAlgorithm )
84- $ f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
85- return F
94+ F′ = $ f! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
95+ return reverse ( adjoint .(F′))
8696 end
8797
8898 # disambiguate by prohibition
@@ -92,17 +102,9 @@ for f! in (:svd_full!, :svd_compact!, :svd_trunc!)
92102 throw (MethodError ($ f!, (t, alg)))
93103 end
94104end
105+
95106# avoid amgiguity
96- function MAK. initialize_output (
97- :: typeof (svd_trunc!), t:: AdjointTensorMap , alg:: TruncatedAlgorithm
98- )
99- return MAK. initialize_output (svd_compact!, t, alg. alg)
100- end
101- # to fix ambiguity
102- function MAK. svd_trunc! (t:: AdjointTensorMap , USVᴴ, alg:: TruncatedAlgorithm )
103- USVᴴ′ = svd_compact! (t, USVᴴ, alg. alg)
104- return MAK. truncate (svd_trunc!, USVᴴ′, alg. trunc)
105- end
106- function MAK. svd_compact! (t:: AdjointTensorMap , USVᴴ, alg:: DiagonalAlgorithm )
107- return MAK. svd_compact! (t, USVᴴ, alg. alg)
107+ function MAK. svd_compact! (t:: AdjointTensorMap , F, alg:: DiagonalAlgorithm )
108+ F′ = svd_compact! (adjoint (t), reverse (adjoint .(F)), _adjoint (alg))
109+ return reverse (adjoint .(F′))
108110end
0 commit comments