Skip to content

Commit

Permalink
Fix rrule for complex-valued determinants (#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

2 comments on commit f13e0a4

@sethaxen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/56969

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.28.1 -m "<description of version>" f13e0a45d10bb13f48d6208e9c9d5b4a52b96732
git push origin v1.28.1

Please sign in to comment.