Skip to content

sqrt(::Matrix{Float64}) is not type stable #1130

@LilithHafner

Description

@LilithHafner
julia> using StableRNGs

julia> rng = StableRNG(0)
StableRNGs.LehmerRNG(state=0x00000000000000000000000000000001)

julia> sqrt(rand(rng,3,3))
3×3 Matrix{ComplexF64}:
    0.410548+0.369007im      0.49482-0.209855im   0.394519-0.231836im
 -0.00928873+0.0595217im    0.935186-0.0338502im   0.11389-0.0373957im
    0.661866-0.458654im   -0.0589303+0.260838im   0.524852+0.288158im

julia> sqrt(rand(rng,3,3))
3×3 Matrix{Float64}:
 0.301226   0.392135   -0.452243
 0.183647   0.25732     1.14379
 0.185353  -0.0785732   0.578105

For scalars, we throw when sqrting a negative unless the negative is of a complex type in which case we return a complex result. IMO that is a much better solution. Switching to that would be breaking in the case of square rooting real matrices with negative real eigenvalues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions