Commit 7f59ef7
authored
Integer matrix exponentiation in schurpow (#51992)
This improves type-inference by avoiding recursion, as the `A^p` method
calls `schurpow` if `p` is a float. After this, the result of `schurpow`
is inferred as a small `Union`:
```julia
julia> @inferred Union{Matrix{ComplexF64}, Matrix{Float64}} LinearAlgebra.schurpow([1.0 2; 3 4], 2.0)
2×2 Matrix{Float64}:
7.0 10.0
15.0 22.0
```
One concern here might be that for large `p`, the `A^Int(p)` computation
might be expensive by repeated multiplication, as opposed to
diagonalization. However, this may only be the case for really large
`p`, which may not be commonly encountered.
I've added a test, but I'm unsure if `schurpow` is deemed to be an
internal function, and this test is unwise. Unfortunately, the return
type of `A^p` isn't concretely inferred yet as there are too many
possible types that are returned, so I couldn't test for that.1 parent f3fe7d2 commit 7f59ef7
2 files changed
+7
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
493 | | - | |
| 493 | + | |
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | | - | |
| 504 | + | |
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1028 | 1028 | | |
1029 | 1029 | | |
1030 | 1030 | | |
1031 | | - | |
1032 | | - | |
| 1031 | + | |
| 1032 | + | |
1033 | 1033 | | |
1034 | 1034 | | |
1035 | 1035 | | |
| |||
1065 | 1065 | | |
1066 | 1066 | | |
1067 | 1067 | | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
1068 | 1071 | | |
1069 | 1072 | | |
1070 | 1073 | | |
| |||
0 commit comments