Skip to content

Commit 61e444d

Browse files
authored
Fix exponentiation with immutable matrix (#1289)
The following works after this: ```julia julia> using LinearAlgebra, StaticArrays julia> S = @smatrix [1 2; 3 4] 2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2): 1 2 3 4 julia> 2^S 2×2 SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2): 10.4827 14.1519 21.2278 31.7106 ```
1 parent 77475c1 commit 61e444d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/dense.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ julia> ℯ^[1 2; 0 3]
720720
0.0 20.0855
721721
```
722722
"""
723-
Base.:^(b::Number, A::AbstractMatrix) = exp!(log(b)*A)
723+
Base.:^(b::Number, A::AbstractMatrix) = exp_maybe_inplace(log(b)*A)
724724
# method for ℯ to explicitly elide the log(b) multiplication
725725
Base.:^(::Irrational{:ℯ}, A::AbstractMatrix) = exp(A)
726726

test/dense.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
1010
isdefined(Main, :FillArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FillArrays.jl"))
1111
import Main.FillArrays
1212

13+
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
14+
using Main.SizedArrays
15+
1316
@testset "Check that non-floats are correctly promoted" begin
1417
@test [1 0 0; 0 1 0]\[1,1] [1;1;0]
1518
end
@@ -1398,4 +1401,9 @@ end
13981401
@test_throws ArgumentError LinearAlgebra.copytri_maybe_inplace(Rc, 'X')
13991402
end
14001403

1404+
@testset "matrix exponentiation for immutable" begin
1405+
A = SizedArray{(2,2)}(reshape(1:4,2,2))
1406+
@test 2^A == 2^Matrix(A)
1407+
end
1408+
14011409
end # module TestDense

0 commit comments

Comments
 (0)