@@ -184,6 +184,49 @@ function eigen!(A::AbstractMatrix, C::Cholesky; sortby::Union{Function,Nothing}=
184184 GeneralizedEigen (sorteig! (vals, vecs, sortby)... )
185185end
186186
187+ # Bunch-Kaufmann (LDLT) based solution for generalized eigenvalues and eigenvectors
188+ function eigen (A:: StridedMatrix{T} , B:: BunchKaufman{T,<:AbstractMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T<: BlasFloat }
189+ eigen! (copy (A), copy (B); sortby)
190+ end
191+ function eigen! (A:: StridedMatrix{T} , B:: BunchKaufman{T,<:StridedMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T<: BlasFloat }
192+ M, TD, p = getproperties! (B)
193+ # Compute generalized eigenvalues of equivalent matrix:
194+ # A' = inv(Tridiagonal(dl,d,du))*inv(M)*P*A*P'*inv(M')
195+ # See: https://github.com/JuliaLang/julia/pull/50471#issuecomment-1627836781
196+ permutecols! (A, p)
197+ permuterows! (A, p)
198+ ldiv! (M, A)
199+ rdiv! (A, M' )
200+ ldiv! (TD, A)
201+ vals, vecs = eigen! (A; sortby)
202+ # Compute generalized eigenvectors from 'vecs':
203+ # vecs = P'*inv(M')*vecs
204+ # See: https://github.com/JuliaLang/julia/pull/50471#issuecomment-1627836781
205+ M = B. uplo == ' U' ? UnitUpperTriangular {eltype(vecs)} (M) : UnitLowerTriangular {eltype(vecs)} (M) ;
206+ ldiv! (M' , vecs)
207+ invpermuterows! (vecs, p)
208+ GeneralizedEigen (sorteig! (vals, vecs, sortby)... )
209+ end
210+
211+ # LU based solution for generalized eigenvalues and eigenvectors
212+ function eigen (A:: StridedMatrix{T} , F:: LU{T,<:StridedMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T}
213+ return eigen! (copy (A), copy (F); sortby)
214+ end
215+ function eigen! (A:: StridedMatrix{T} , F:: LU{T,<:StridedMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T}
216+ L = UnitLowerTriangular (F. L)
217+ U = UpperTriangular (F. U)
218+ permuterows! (A, F. p)
219+ ldiv! (L, A)
220+ rdiv! (A, U)
221+ vals, vecs = eigen! (A; sortby)
222+ # Compute generalized eigenvectors from 'vecs':
223+ # vecs = P'*inv(M')*vecs
224+ # See: https://github.com/JuliaLang/julia/pull/50471#issuecomment-1627836781
225+ U = UpperTriangular {eltype(vecs)} (U)
226+ ldiv! (U, vecs)
227+ GeneralizedEigen (sorteig! (vals, vecs, sortby)... )
228+ end
229+
187230# Perform U' \ A / U in-place, where U::Union{UpperTriangular,Diagonal}
188231UtiAUi! (A, U) = _UtiAUi! (A, U)
189232UtiAUi! (A:: Symmetric , U) = Symmetric (_UtiAUi! (copytri! (parent (A), A. uplo), U), sym_uplo (A. uplo))
@@ -218,3 +261,36 @@ function eigvals!(A::AbstractMatrix{T}, C::Cholesky{T, <:AbstractMatrix}; sortby
218261 # Cholesky decomposition based eigenvalues
219262 return eigvals! (UtiAUi! (A, C. U); sortby)
220263end
264+
265+ # Bunch-Kaufmann (LDLT) based solution for generalized eigenvalues
266+ function eigvals (A:: StridedMatrix{T} , B:: BunchKaufman{T,<:AbstractMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T<: BlasFloat }
267+ eigvals! (copy (A), copy (B); sortby)
268+ end
269+ function eigvals! (A:: StridedMatrix{T} , B:: BunchKaufman{T,<:StridedMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T<: BlasFloat }
270+ M, TD, p = getproperties! (B)
271+ # Compute generalized eigenvalues of equivalent matrix:
272+ # A' = inv(Tridiagonal(dl,d,du))*inv(M)*P*A*P'*inv(M')
273+ # See: https://github.com/JuliaLang/julia/pull/50471#issuecomment-1627836781
274+ permutecols! (A, p)
275+ permuterows! (A, p)
276+ ldiv! (M, A)
277+ rdiv! (A, M' )
278+ ldiv! (TD, A)
279+ return eigvals! (A; sortby)
280+ end
281+
282+ # LU based solution for generalized eigenvalues
283+ function eigvals (A:: StridedMatrix{T} , F:: LU{T,<:StridedMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T}
284+ return eigvals! (copy (A), copy (F); sortby)
285+ end
286+ function eigvals! (A:: StridedMatrix{T} , F:: LU{T,<:StridedMatrix} ; sortby:: Union{Function,Nothing} = nothing ) where {T}
287+ L = UnitLowerTriangular (F. L)
288+ U = UpperTriangular (F. U)
289+ # Compute generalized eigenvalues of equivalent matrix:
290+ # A' = inv(L)*(P*A)*inv(U)
291+ # See: https://github.com/JuliaLang/julia/pull/50471#issuecomment-1627836781
292+ permuterows! (A, F. p)
293+ ldiv! (L, A)
294+ rdiv! (A, U)
295+ return eigvals! (A; sortby)
296+ end
0 commit comments