Skip to content

Commit

Permalink
Fix rrule for complex-valued determinants (JuliaDiff#601)
Browse files Browse the repository at this point in the history
* Fix rrule for det of complex matrix

* Add test of rules for complex determinant

* `ΔΩ * inv(x)'` ⇒ `inv(x)' * dot(Ω, ΔΩ)`

Co-authored-by: Seth Axen <[email protected]>

* Use a random matrix as a seed for the unitary

* Bump patch number

* Use `U = exp(B - B')` as complex `det` test matrix

Co-authored-by: Seth Axen <[email protected]>

Co-authored-by: Seth Axen <[email protected]>
  • Loading branch information
goerz and sethaxen authored Mar 20, 2022
1 parent 9023d89 commit f13e0a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.28.0"
version = "1.28.1"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
2 changes: 1 addition & 1 deletion src/rulesets/LinearAlgebra/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ frule((_, Δx), ::typeof(det), x::Number) = (det(x), Δx)
function rrule(::typeof(det), x::Union{Number, AbstractMatrix})
Ω = det(x)
function det_pullback(ΔΩ)
∂x = x isa Number ? ΔΩ : Ω * ΔΩ * inv(x)'
∂x = x isa Number ? ΔΩ : inv(x)' * dot(Ω, ΔΩ)
return (NoTangent(), ∂x)
end
return Ω, det_pullback
Expand Down
6 changes: 6 additions & 0 deletions test/rulesets/LinearAlgebra/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
test_rrule(f, B)
end
end
@testset "$f(complex determinant)" begin
B = randn(ComplexF64, 4, 4)
U = exp(B - B')
test_frule(f, U)
test_rrule(f, U)
end
end
@testset "logabsdet(::Matrix{$T})" for T in (Float64, ComplexF64)
B = randn(T, 4, 4)
Expand Down

0 comments on commit f13e0a4

Please sign in to comment.