Skip to content

Commit 4f87420

Browse files
Jutholkdvos
authored andcommitted
some more review updates
1 parent a08a254 commit 4f87420

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/factorizations/adjoint.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ for (left_f, right_f) in zip(
6565
return reverse(adjoint.(MAK.initialize_output($left_f!, adjoint(t), _adjoint(alg))))
6666
end
6767

68-
@eval MAK.$left_f!(t::AdjointTensorMap, F, alg::AbstractAlgorithm) =
69-
$right_f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
70-
@eval MAK.$right_f!(t::AdjointTensorMap, F, alg::AbstractAlgorithm) =
71-
$left_f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
68+
@eval function MAK.$left_f!(t::AdjointTensorMap, F, alg::AbstractAlgorithm)
69+
F′ = $right_f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
70+
return reverse(adjoint.(F′))
71+
end
72+
@eval function MAK.$right_f!(t::AdjointTensorMap, F, alg::AbstractAlgorithm)
73+
F′ = $left_f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
74+
return reverse(adjoint.(F′))
75+
end
7276
end
7377

7478
# 3-arg functions
@@ -83,8 +87,8 @@ for f! in (:svd_full!, :svd_compact!, :svd_trunc!)
8387
return reverse(adjoint.(MAK.initialize_output($f!, adjoint(t), _adjoint(alg))))
8488
end
8589
@eval function MAK.$f!(t::AdjointTensorMap, F, alg::AbstractAlgorithm)
86-
$f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
87-
return F
90+
F′ = $f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
91+
return reverse(adjoint.(F′))
8892
end
8993

9094
# disambiguate by prohibition

src/factorizations/pullbacks.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ for pullback! in (:svd_pullback!, :eig_pullback!, :eigh_pullback!)
3232
Δt::AbstractTensorMap, t::AbstractTensorMap, F, ΔF, inds = _notrunc_ind(t);
3333
kwargs...
3434
)
35-
for (c, ind) in inds
36-
Δb = block(Δt, c)
37-
b = block(t, c)
35+
foreachblock(Δt, t) do c, (Δb, b)
3836
Fc = block.(F, Ref(c))
3937
ΔFc = block.(ΔF, Ref(c))
38+
ind = inds[c]
4039
MAK.$pullback!(Δb, b, Fc, ΔFc, ind; kwargs...)
4140
end
41+
# for (c, ind) in inds
42+
# Δb = block(Δt, c)
43+
# b = block(t, c)
44+
# Fc = block.(F, Ref(c))
45+
# ΔFc = block.(ΔF, Ref(c))
46+
# MAK.$pullback!(Δb, b, Fc, ΔFc, ind; kwargs...)
47+
# end
4248
return Δt
4349
end
4450
end

src/factorizations/truncation.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Truncation strategy to keep the first values for each sector when sorted accordi
2121
such that the resulting vector space is no greater than `V`.
2222
"""
2323
function truncspace(space::ElementarySpace; by = abs, rev::Bool = true)
24-
isdual(space) && throw(ArgumentError("resulting vector space is never dual"))
24+
isdual(space) && throw(ArgumentError("truncation space should not be dual"))
2525
return TruncationSpace(space, by, rev)
2626
end
2727

@@ -37,15 +37,15 @@ function truncate_domain!(tdst::AbstractTensorMap, tsrc::AbstractTensorMap, inds
3737
for (c, b) in blocks(tdst)
3838
I = get(inds, c, nothing)
3939
@assert !isnothing(I)
40-
copy!(b, @view(block(tsrc, c)[:, I]))
40+
copy!(b, view(block(tsrc, c), :, I))
4141
end
4242
return tdst
4343
end
4444
function truncate_codomain!(tdst::AbstractTensorMap, tsrc::AbstractTensorMap, inds)
4545
for (c, b) in blocks(tdst)
4646
I = get(inds, c, nothing)
4747
@assert !isnothing(I)
48-
copy!(b, @view(block(tsrc, c)[I, :]))
48+
copy!(b, view(block(tsrc, c), I, :))
4949
end
5050
return tdst
5151
end

0 commit comments

Comments
 (0)