JuliaArrays / JuliaArrays/StaticArrays.jl

`sqrt(Hermitian(A))` errors (due to fallback) for complex `A`

Open
#599 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug linear-algebra up for grabs
Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

I hope this isn't a duplicate; I couldn't find an issue though. Here's an example:

julia> A = @SMatrix(rand(2, 2)) + im*@SMatrix(rand(2,2))
2×2 SArray{Tuple{2,2},Complex{Float64},2,4}:
 0.911161+0.30874im   0.152706+0.0236032im
  0.55638+0.107542im  0.175589+0.100683im 

julia> B= A*A'
2×2 SArray{Tuple{2,2},Complex{Float64},2,4}:
 0.949411+0.0im        0.569345+0.0625584im
 0.569345-0.0625584im  0.362093+0.0im      

julia> sqrt(B)
2×2 SArray{Tuple{2,2},Complex{Float64},2,4}:
 0.859886+0.0im       0.455524+0.050052im
 0.455524-0.050052im  0.389982+0.0im     

julia> sqrt(Hermitian(B))
ERROR: setindex!(::SArray{Tuple{2,2},Complex{Float64},2,4}, value, ::Int) is not defined.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] setindex!(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Float64, ::Int64) at /Users/eh540/.julia/packages/StaticArrays/VyRz3/src/indexing.jl:3
 [3] macro expansion at /Users/eh540/.julia/packages/StaticArrays/VyRz3/src/indexing.jl:51 [inlined]
 [4] _setindex!_scalar at /Users/eh540/.julia/packages/StaticArrays/VyRz3/src/indexing.jl:39 [inlined]
 [5] setindex! at /Users/eh540/.julia/packages/StaticArrays/VyRz3/src/indexing.jl:35 [inlined]
 [6] sqrt(::Hermitian{Complex{Float64},SArray{Tuple{2,2},Complex{Float64},2,4}}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/symmetric.jl:832
 [7] top-level scope at none:0

As you can see, it works without the Hermitian wrapper, and it also works in the real case. I will just not use the Hermitian wrapper, but I thought maybe the problem should be noted somewhere.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the complex static-matrix example and start with the failing sqrt method at LinearAlgebra/src/symmetric.jl:832, then inspect StaticArrays indexing.jl from the stack trace. Confirm the fix with a regression test showing sqrt(Hermitian(B)) works for a complex SArray, while preserving the existing real case.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.