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
10 changes: 10 additions & 0 deletions ext/TensorKitChainRulesCoreExt/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ function ChainRulesCore.rrule(
return permute(tsrc, p; copy = true), permute_pullback
end

function ChainRulesCore.rrule(
::typeof(transpose), tsrc::AbstractTensorMap, p::Index2Tuple; copy::Bool = false
)
function transpose_pullback(Δtdst)
invp = TensorKit._canonicalize(TupleTools.invperm(linearize(p)), tsrc)
return NoTangent(), transpose(unthunk(Δtdst), invp; copy = true), NoTangent()
end
return transpose(tsrc, p; copy = true), transpose_pullback
end

function ChainRulesCore.rrule(::typeof(tr), A::AbstractTensorMap)
tr_pullback(Δtr) = NoTangent(), Δtr * id(domain(A))
return tr(A), tr_pullback
Expand Down
1 change: 1 addition & 0 deletions test/autodiff/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ for V in spacelist
C = randn(T, domain(A), codomain(A))
test_rrule(*, A, C)

test_rrule(transpose, A, ((2, 5, 4), (1, 3)))
symmetricbraiding && test_rrule(permute, A, ((1, 3, 2), (5, 4)))
test_rrule(twist, A, 1)
test_rrule(twist, A, [1, 3])
Expand Down
Loading