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

Correctness issues with SHermitianCompact #1263

Closed
lxvm opened this issue Jun 23, 2024 · 2 comments
Closed

Correctness issues with SHermitianCompact #1263

lxvm opened this issue Jun 23, 2024 · 2 comments
Labels

Comments

@lxvm
Copy link
Contributor

lxvm commented Jun 23, 2024

I've been trying to use SHermitianCompact to speed up some interpolation and linear algebra, but I find it quite a difficult type to work with because it doesn't actually guarantee its values are Hermitian. The simplest example is multiplying a SHermitianCompact matrix by a complex number, which will generically result in a non-Hermitian matrix.

julia> using StaticArrays, LinearAlgebra

julia> y = rand(SHermitianCompact{3,Float64,6});

julia> x = rand(ComplexF64);

julia> norm(y*x - SMatrix(y)*x)
2.1996254891748803

julia> using Pkg

julia> Pkg.status("StaticArrays")
Status `/local/home/lxvm/projects/autobz/Project.toml`
  [90137ffa] StaticArrays v1.9.5

A summary of the problems I've encountered include:

  • (As shown above) multiplication of a SHermitianCompact by a complex number should promote to a SMatrix
  • The diagonal of a SHermitianCompact should always be real-valued, so that the ishermitian method, which is hard-coded to return true, is correct
  • The issymmetric method should be true when the element type is real, and otherwise there should be a numerical check

I think I can correct all of the above without changing the storage layout of SHermitianCompact in a small PR. Do the proposed changes seem reasonable and am I missing any others?

@mateuszbaran
Copy link
Collaborator

Multiplication by complex numbers indeed looks bugged. A small PR with a fix would be appreciated 🙂 .

@lxvm
Copy link
Contributor Author

lxvm commented Jun 27, 2024

This issue is resolved by #1264 and #1266

@lxvm lxvm closed this as completed Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants