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
8 changes: 8 additions & 0 deletions ext/TensorKitChainRulesCoreExt/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
return n, norm_pullback
end

function ChainRulesCore.rrule(::typeof(inv), A::AbstractTensorMap)
Ainv = inv(A)
inv_pullback = let Ainv = Ainv
inv_pullback(ΔAinv) = NoTangent(), -Ainv' * unthunk(ΔAinv) * Ainv'

Check warning on line 103 in ext/TensorKitChainRulesCoreExt/linalg.jl

View check run for this annotation

Codecov / codecov/patch

ext/TensorKitChainRulesCoreExt/linalg.jl#L100-L103

Added lines #L100 - L103 were not covered by tests
end
return Ainv, inv_pullback

Check warning on line 105 in ext/TensorKitChainRulesCoreExt/linalg.jl

View check run for this annotation

Codecov / codecov/patch

ext/TensorKitChainRulesCoreExt/linalg.jl#L105

Added line #L105 was not covered by tests
end

function ChainRulesCore.rrule(::typeof(real), a::AbstractTensorMap)
a_real = real(a)
real_pullback(Δa) = NoTangent(), eltype(a) <: Real ? Δa : complex(unthunk(Δa))
Expand Down
1 change: 1 addition & 0 deletions test/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Vlist = ((ℂ^2, (ℂ^3)', ℂ^3, ℂ^2, (ℂ^2)'),
E = randn(T, ⊗(V[1:i]...) ← ⊗(V[1:i]...))
test_rrule(LinearAlgebra.tr, E)
test_rrule(exp, E; check_inferred=false)
test_rrule(inv, E)
end

A = randn(T, V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5])
Expand Down
Loading