Skip to content

Commit

Permalink
added missing matrix exponentiation methods (#29782)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExpandingMan authored and StefanKarpinski committed Oct 30, 2018
1 parent aa72f72 commit de278a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ julia> exp(A)
exp(A::StridedMatrix{<:BlasFloat}) = exp!(copy(A))
exp(A::StridedMatrix{<:Union{Integer,Complex{<:Integer}}}) = exp!(float.(A))

Base.:^(b::Number, A::AbstractMatrix) = exp!(log(b)*A)
# method for ℯ to explicitly elide the log(b) multiplication
Base.:^(::Irrational{:ℯ}, A::AbstractMatrix) = exp(A)

## Destructive matrix exponential using algorithm from Higham, 2008,
## "Functions of Matrices: Theory and Computation", SIAM
function exp!(A::StridedMatrix{T}) where T<:BlasFloat
Expand Down
7 changes: 7 additions & 0 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ end
end
end

@testset "^ tests" for elty in (Float32, Float64, ComplexF32, ComplexF64, Int32, Int64)
# should all be exact as the lhs functions are simple aliases
@test^(fill(elty(2), (4,4))) == exp(fill(elty(2), (4,4)))
@test 2^(fill(elty(2), (4,4))) == exp(log(2)*fill(elty(2), (4,4)))
@test 2.0^(fill(elty(2), (4,4))) == exp(log(2.0)*fill(elty(2), (4,4)))
end

A8 = 100 * [-1+1im 0 0 1e-8; 0 1 0 0; 0 0 1 0; 0 0 0 1]
@test exp(log(A8)) A8
end
Expand Down

0 comments on commit de278a5

Please sign in to comment.