Matrix Powers are type-unstable: sometime Real sometimes ComplexΒ #723
Description
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 do log(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)
Activity