-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
^(::Matrix{Float64},::Float64)
not type stable
#460
Comments
I have thought about this before and I guess it could be reasonable to not rewrap in |
After looking at this in more detail, it looks like a more general issue to me than just Hermitian and Symmetric matrices, the result of julia> [1. 1.;0. 1.]^.5
2×2 Array{Float64,2}:
1.0 0.5
0.0 1.0
julia> [1. 1.;0. -1.]^.5
2×2 Array{Complex{Float64},2}:
1.0+0.0im 0.5-0.5im
0.0+0.0im 0.0+1.0im This is inconsistent with how scalars are handled: julia> 1.^.5
1.0
julia> (-1.)^.5
ERROR: DomainError:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
Stacktrace:
[1] nan_dom_err at .\math.jl:300 [inlined]
[2] ^(::Float64, ::Float64) at .\math.jl:699 i.e., you always get a Float64 (or a DomainError). |
@fredrikekre , by "rewrapping" do you mean that the input matrix A is of type Symmetric and the return type is also of type Symmetric (sometimes)? It looks like there is not only "rewrapping" but also "wrapping" going on, i.e. the input type doesn't have to be Symmetric to sometimes get a Symmetric return type: julia> [1. 0.;0. 1.]^2.
2×2 Array{Float64,2}:
1.0 0.0
0.0 1.0
julia> [1. 0.;0. 1.]^.5
2×2 Symmetric{Float64,Array{Float64,2}}:
1.0 0.0
0.0 1.0 |
This seems almost a dup of #21 (except for symmetry). If the design decision was made that julia> sqrtm([1. 0;0 1])
2×2 Array{Float64,2}:
1.0 0.0
0.0 1.0 but julia> [1. 0.;0. 1.]^.5
2×2 Symmetric{Float64,Array{Float64,2}}:
1.0 0.0
0.0 1.0 I guess it would make more sense that both |
Yes, that is what I was suggesting; that we should not re-wrap into |
Part of the problem here is that, compared to the scalar case, it is much more costly to convert to complex before the computation so requiring the user to do that would be unfortunate. The alternative is to always return a complex result. I'd be in favor of that because most non-symmetric matrices will have a complex solution anyway. |
Fixed on master. |
Would be good with a test. |
Wait, how is this solved? I get julia> @code_warntype [1. 1.;1. 0.]^2.
Variables
#self#::Core.Const(^)
A::Matrix{Float64}
p::Float64
@_4::Union{Nothing, Tuple{Int64, Int64}}
retmat::Matrix{Float64}
TT::Type{Float64}
n::Int64
i::Int64
Body::Any
... on master. |
@code_warntype [1. 1.;1. 0.]^2.
shows return typeAny
, same holds for Complex types, i.e. the testfails (both on Julia 0.6 and 0.7). This issue is related to but different from JuliaLang/julia#23366 (Float64 vs Int64).
The text was updated successfully, but these errors were encountered: