Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added missing matrix exponentiation methods #29782

Merged
merged 6 commits into from Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/LinearAlgebra/src/dense.jl
Expand Up @@ -489,6 +489,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
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