Skip to content

Commit f9a8231

Browse files
committed
Get _vals working?
1 parent 95b92c7 commit f9a8231

5 files changed

Lines changed: 24 additions & 21 deletions

File tree

‎src/factorizations/diagonal.jl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
_repack_diagonal(d::DiagonalTensorMap) = Diagonal(d.data)
44
_repack_diagonal(d::SectorVector) = Diagonal(parent(d))
55

6+
MAK.diagonal(t::SectorVector) = DiagonalTensorMap(t)
67
MAK.diagview(t::DiagonalTensorMap) = SectorVector(t.data, TensorKit.diagonalblockstructure(space(t)))
78

89
for f in (

‎src/factorizations/pullbacks.jl‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ for pullback! in (:svd_pullback!, :eig_pullback!, :eigh_pullback!)
5858
haskey(inds, c) || return nothing
5959
ind = inds[c]
6060
Fc = block.(F, Ref(c))
61-
ΔFc = block.(ΔF, Ref(c))
61+
ΔFc = map(ΔFc -> isnothing(ΔFc) ? nothing : block(ΔFc, c), ΔF)
6262
return MAK.$pullback!(Δb, nothing, Fc, ΔFc, ind; kwargs...)
6363
end
6464
return Δt
@@ -73,6 +73,11 @@ for pullback! in (:svd_pullback!, :eig_pullback!, :eigh_pullback!)
7373
)
7474
return MAK.$pullback!(Δt, nothing, F, ΔF, _notrunc_ind(Δt); kwargs...)
7575
end
76+
@eval function MAK.$pullback!(
77+
Δt::AbstractTensorMap, ::Nothing, F, ΔF, ::Colon; kwargs...
78+
)
79+
return MAK.$pullback!(Δt, nothing, F, ΔF, _notrunc_ind(Δt); kwargs...)
80+
end
7681
end
7782

7883
for pullback_trunc! in (:svd_trunc_pullback!, :eig_trunc_pullback!, :eigh_trunc_pullback!)

‎test/enzyme-factorizations/eig.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ eltypes = (Float64, ComplexF64)
1818
remove_eig_gauge_dependence!(ΔDV[2], DV...)
1919
EnzymeTestUtils.test_reverse(eig_full, Duplicated, (t, Duplicated); output_tangent = ΔDV, atol, rtol)
2020

21-
#D = eig_vals(t)
22-
#EnzymeTestUtils.test_reverse(eig_vals, Duplicated, (t, Duplicated); atol, rtol)
21+
D = eig_vals(t)
22+
EnzymeTestUtils.test_reverse(eig_vals, Duplicated, (t, Duplicated); atol, rtol)
2323

2424
V_trunc = spacetype(t)(c => min(size(b)...) ÷ 2 for (c, b) in blocks(t))
2525
trunc = truncspace(V_trunc)

‎test/enzyme-factorizations/eigh.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ eltypes = (Float64, ComplexF64)
1919
proj_eigh_full(t) = eigh_full(project_hermitian(t))
2020
EnzymeTestUtils.test_reverse(proj_eigh_full, Duplicated, (th, Duplicated); output_tangent = ΔDV, atol, rtol)
2121

22-
#D = eigh_vals(th)
23-
#EnzymeTestUtils.test_reverse(eigh_vals ∘ project_hermitian, Duplicated, (th, Duplicated); atol, rtol)
22+
D = eigh_vals(th)
23+
EnzymeTestUtils.test_reverse(eigh_vals ∘ project_hermitian, Duplicated, (th, Duplicated); atol, rtol)
2424

2525
V_trunc = spacetype(th)(c => min(size(b)...) ÷ 2 for (c, b) in blocks(t))
2626
trunc = truncspace(V_trunc)

‎test/enzyme-factorizations/svd.jl‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@ eltypes = (Float64, ComplexF64)
1313
atol = default_tol(T)
1414
rtol = default_tol(T)
1515

16-
#S = svd_vals(t)
17-
#EnzymeTestUtils.test_reverse(svd_vals, Duplicated, (t, Duplicated); atol, rtol)
16+
S = svd_vals(t)
17+
EnzymeTestUtils.test_reverse(svd_vals, Duplicated, (t, Duplicated); atol, rtol)
1818

1919
USVᴴ = svd_full(t)
2020
ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ)
2121
remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...)
2222
EnzymeTestUtils.test_reverse(svd_full, Duplicated, (t, Duplicated); output_tangent = ΔUSVᴴ, atol, rtol)
2323

24-
# ntuple related bug in Enzyme internals
25-
@static if VERSION >= v"1.11.0-rc"
26-
USVᴴ = svd_compact(t)
27-
ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ)
28-
remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...)
29-
EnzymeTestUtils.test_reverse(svd_compact, Duplicated, (t, Duplicated); output_tangent = ΔUSVᴴ, atol, rtol)
24+
USVᴴ = svd_compact(t)
25+
ΔUSVᴴ = EnzymeTestUtils.rand_tangent(USVᴴ)
26+
remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...)
27+
EnzymeTestUtils.test_reverse(svd_compact, Duplicated, (t, Duplicated); output_tangent = ΔUSVᴴ, atol, rtol)
3028

31-
V_trunc = spacetype(t)(c => min(size(b)...) ÷ 2 for (c, b) in blocks(t))
32-
trunc = truncspace(V_trunc)
33-
alg = MatrixAlgebraKit.select_algorithm(svd_trunc_no_error, t, nothing; trunc)
34-
USVᴴtrunc = svd_trunc_no_error(t, alg)
35-
ΔUSVᴴtrunc = EnzymeTestUtils.rand_tangent(USVᴴtrunc)
36-
remove_svd_gauge_dependence!(ΔUSVᴴtrunc[1], ΔUSVᴴtrunc[3], USVᴴtrunc...)
37-
EnzymeTestUtils.test_reverse(svd_trunc_no_error, Duplicated, (t, Duplicated), (alg, Const); output_tangent = ΔUSVᴴtrunc, atol, rtol)
38-
end
29+
V_trunc = spacetype(t)(c => min(size(b)...) ÷ 2 for (c, b) in blocks(t))
30+
trunc = truncspace(V_trunc)
31+
alg = MatrixAlgebraKit.select_algorithm(svd_trunc_no_error, t, nothing; trunc)
32+
USVᴴtrunc = svd_trunc_no_error(t, alg)
33+
ΔUSVᴴtrunc = EnzymeTestUtils.rand_tangent(USVᴴtrunc)
34+
remove_svd_gauge_dependence!(ΔUSVᴴtrunc[1], ΔUSVᴴtrunc[3], USVᴴtrunc...)
35+
EnzymeTestUtils.test_reverse(svd_trunc_no_error, Duplicated, (t, Duplicated), (alg, Const); output_tangent = ΔUSVᴴtrunc, atol, rtol)
3936
end

0 commit comments

Comments
 (0)