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

Solving Lyapunov equation for matrices given in Adjoint form #38177

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1567,4 +1567,5 @@ function lyap(A::StridedMatrix{T}, C::StridedMatrix{T}) where {T<:BlasFloat}
rmul!(Q*(Y * adjoint(Q)), inv(scale))
end
lyap(A::StridedMatrix{T}, C::StridedMatrix{T}) where {T<:Integer} = lyap(float(A), float(C))
lyap(A::Adjoint{T,Matrix{T}}, C::Adjoint{T,Matrix{T}}) where T = lyap(Matrix(A), Matrix(C))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not generalize this to be an AbstractMatrix for both A and C:

lyap(A::AbstractMatrix{T}, C::AbstractMatrix{T}) where T = lyap(Matrix(A), Matrix(C))

That will allow for the adjoints to be passed in, as well as other matrix types to also be used (such as Tridiagonal, etc.) and make this bare-bones example code work (it will not currently work because it doesn't allow the Tridiagonal dispatch on the second argument).

A = randn(5,5)
B = randn(5,5)

lyap( A, Tridiagonal( B'*B ) )

Copy link
Member

Choose a reason for hiding this comment

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

This should be

function lyap(A::AbstractMatrix, C::AbstractMatrix)
    T = promote_type(float(eltype(A)), float(eltype(C)))
    return lyap(copy_to_array(A, T), copy_to_array(C, T))
end

This will make sure that the matrices are strided and have float eltype, in one go.

lyap(a::T, c::T) where {T<:Number} = -c/(2a)