Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eigen and eigvals rules for StridedMatrix #321

Merged
merged 24 commits into from
Dec 9, 2020
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Add implementation of eigvals
  • Loading branch information
sethaxen committed Dec 4, 2020
commit 876bc9031bd17245ae7b10df1e200fe1c2f673dd
26 changes: 26 additions & 0 deletions src/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ function _findrealmaxabs2(x)
return imax
end

#####
##### `eigvals`
#####

function frule((_, ΔA), ::typeof(eigvals), A::StridedMatrix{T}; kwargs...) where {T<:Union{Real,Complex}}
F = eigen(A; kwargs...)
λ, V = F.values, F.vectors
ΔA isa AbstractZero && return λ, ΔA
∂K = V \ ΔA * V
idx = diagind(∂K)
∂λ = eltype(λ) <: Real ? real.(getindex.(Ref(∂K), idx)) : ∂K[idx]
return λ, ∂λ
end

function rrule(::typeof(eigvals), A::StridedMatrix{T}; kwargs...) where {T<:Union{Real,Complex}}
F = eigen(A; kwargs...)
λ = F.values
function eigvals_pullback(Δλ)
V = F.vectors
∂A = V' \ Diagonal(Δλ) * V'
return NO_FIELDS, T <: Real ? real(∂A) : ∂A
end
eigvals_pullback(Δλ::AbstractZero) = (NO_FIELDS, Δλ)
return λ, eigvals_pullback
end

#####
##### `cholesky`
#####
Expand Down