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

eigen and svd with Symmetric{Float16, ...} #54306

Closed
btmit opened this issue Apr 29, 2024 · 2 comments · Fixed by #54403
Closed

eigen and svd with Symmetric{Float16, ...} #54306

btmit opened this issue Apr 29, 2024 · 2 comments · Fixed by #54403
Labels

Comments

@btmit
Copy link

btmit commented Apr 29, 2024

eigen and svd of Symmetric{Float16, ...} returns values with element type Float32. This is not the case when the input is not wrapped in Symmetric. cholesky decompositions don't have this issue.

a = rand(Float16, 3, 3);
a = a*a'

svd(a)
# SVD{Float16, Float16, Matrix{Float16}, Vector{Float16}}

eigen(a)
# Eigen{Float16, Float16, Matrix{Float16}, Vector{Float16}}

cholesky(a)
# Cholesky{Float16, Matrix{Float16}}

svd(Symmetric(a))
# SVD{Float32, Float32, Matrix{Float32}, Vector{Float32}}

eigen(Symmetric(a))
# Eigen{Float32, Float32, Matrix{Float32}, Vector{Float32}}

cholesky(Symmetric(a))
# Cholesky{Float16, Matrix{Float16}}
@aravindh-krishnamoorthy
Copy link
Contributor

It seems that for svd, in

function svd(A::RealHermSymComplexHerm; full::Bool=false)
and for eigen in
function eigen(A::RealHermSymComplexHerm; sortby::Union{Function,Nothing}=nothing)
the matrix is promoted to Float32 for LAPACK but the result is not cast back to Float16.

Working cases: For plain vanilla svd(a), the result is cast back correctly in svd.jl and eigen(a) uses a specialised Float16 routine in eigen.jl. Furthermore, for cholesky, there's a special method for AbstractMatrix{Float16} here:

function cholesky(A::AbstractMatrix{Float16}, ::NoPivot=NoPivot(); check::Bool = true)
so the cholesky(Symmetric(a)) function is Ok.

@dkarrasch dkarrasch added the domain:linear algebra Linear algebra label May 1, 2024
@jishnub
Copy link
Contributor

jishnub commented May 3, 2024

A PR to add an analogous method is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants