Skip to content

Commit 6aff0b6

Browse files
authored
Add a rule and tests for TensorMap(d::DiagonalTensorMap) (#553)
1 parent 3b28545 commit 6aff0b6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎ext/TensorKitChainRulesCoreExt/constructors.jl‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ function ChainRulesCore.rrule(::Type{DiagonalTensorMap}, t::AbstractTensorMap)
5757
return d, DiagonalTensorMap_pullback
5858
end
5959

60+
function ChainRulesCore.rrule(::Type{TensorMap}, d::DiagonalTensorMap)
61+
t = TensorMap(d)
62+
P = ProjectTo(d)
63+
TensorMap_pullback(Δt) = NoTangent(), P(unthunk(Δt))
64+
return t, TensorMap_pullback
65+
end
66+
6067
function ChainRulesCore.rrule(::typeof(Base.getproperty), t::TensorMap, prop::Symbol)
6168
if prop === :data
6269
function getdata_pullback(Δdata)

‎test/chainrules/linalg.jl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ for V in spacelist
8989

9090
test_rrule(DiagonalTensorMap, rand!(T1))
9191
test_rrule(DiagonalTensorMap, randn!(T))
92+
93+
test_rrule(TensorMap, D1)
94+
test_rrule(TensorMap, D)
9295
end
9396
end
9497

0 commit comments

Comments
 (0)