Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/TensorKitChainRulesCoreExt/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ function ChainRulesCore.rrule(::Type{DiagonalTensorMap}, t::AbstractTensorMap)
return d, DiagonalTensorMap_pullback
end

function ChainRulesCore.rrule(::Type{TensorMap}, d::DiagonalTensorMap)
t = TensorMap(d)
P = ProjectTo(d)
TensorMap_pullback(Δt) = NoTangent(), P(unthunk(Δt))
return t, TensorMap_pullback
end

function ChainRulesCore.rrule(::typeof(Base.getproperty), t::TensorMap, prop::Symbol)
if prop === :data
function getdata_pullback(Δdata)
Expand Down
3 changes: 3 additions & 0 deletions test/chainrules/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ for V in spacelist

test_rrule(DiagonalTensorMap, rand!(T1))
test_rrule(DiagonalTensorMap, randn!(T))

test_rrule(TensorMap, D1)
test_rrule(TensorMap, D)
end
end

Expand Down
Loading