You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For other functions like log it is required that you give suitbale types.
i.e. log(-1) errors, you need to do log(complex(-1))
We should be demanding the same thing from matrix powers.
Give a complex input if you want a complex output.
Turnout this is really annoying for testing AD.
Making it error would not make it less annoying to test but rather remove the need to test it in the first place.
It breaks FiniteDifferences.jl (JuliaDiff/FiniteDifferences.jl#80) because FIniteDIfferences.jl really can'y handle when the number of inputs needing to be perterbed changes depending on the value of the input.
If it is a complex output there are twice as many things needed to perturbe.
julia>using LinearAlgebra, Test
julia> x = [1.02.0; 3.04.0]
2×2 Array{Float64,2}:1.02.03.04.0
julia>@inferred x^1# integer power is fine2×2 Array{Float64,2}:1.02.03.04.0
julia>@inferred x^1.0# float power is type-unstable
ERROR:return type Array{Float64,2} does not match inferred return type Any
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] top-level scope at REPL[23]:1
julia>@inferred x^complex(1.0) # complex power is type-stable2×2 Array{Complex{Float64},2}:1.0-2.35922e-16im2.0+5.55112e-17im3.0-8.32667e-17im4.0-3.33067e-16im
Another example is eigendecomposition:
julia>@inferredeigen(x)
ERROR:return type Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}} does not match inferred return type Union{Eigen{Complex{Float64},Complex{Float64},Array{Complex{Float64},2},Array{Complex{Float64},1}}, Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}}}
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] top-level scope at REPL[21]:1
oxinabox
changed the title
Matrix Powers are type-unstable: sometime Real somtimes Complex
Matrix Powers are type-unstable: sometime Real sometimes Complex
May 9, 2020
There are all kinds cases where for some matrix powers the result will be a real matrix,
and for others a complex matrix.
Such as here https://github.com/JuliaLang/julia/blob/70d27c22d6cdbbe4921b9a183ff4024bd20efb97/stdlib/LinearAlgebra/src/symmetric.jl#L874-L882
For other functions like
log
it is required that you give suitbale types.i.e.
log(-1)
errors, you need to dolog(complex(-1))
We should be demanding the same thing from matrix powers.
Give a complex input if you want a complex output.
This was introduced back in JuliaLang/julia#21184
Turnout this is really annoying for testing AD.
Making it error would not make it less annoying to test but rather remove the need to test it in the first place.
It breaks FiniteDifferences.jl (JuliaDiff/FiniteDifferences.jl#80) because FIniteDIfferences.jl really can'y handle when the number of inputs needing to be perterbed changes depending on the value of the input.
If it is a complex output there are twice as many things needed to perturbe.
It also really complicates [Zygote's tests](e.g https://github.com/FluxML/Zygote.jl/blob/ac4f1a0727d860b31197a336a02d04b33cb21219/src/lib/array.jl#L607)
The text was updated successfully, but these errors were encountered: