Skip to content

Commit

Permalink
News and compat annotation for #29782 (^(::Number, ::AbstractMatrix))
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi authored and fredrikekre committed Dec 3, 2018
1 parent dd2321b commit 75da558
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Standard library changes
* `current_project()` now searches the parent directories of a Git repository for a `Project.toml` file.
This also affects the behavior of the `--project` command line option when using the default
`--project=@.` ([#29108]).
* Exponentiation operator `^` now supports raising a `Irrational` to an `AbstractMatrix` power ([#29782]).

Compiler/Runtime improvements
-----------------------------
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ LinearAlgebra.pinv
LinearAlgebra.nullspace
Base.kron
LinearAlgebra.exp(::StridedMatrix{<:LinearAlgebra.BlasFloat})
Base.:^(::AbstractMatrix, ::Number)
Base.:^(::Number, ::AbstractMatrix)
LinearAlgebra.log(::StridedMatrix)
LinearAlgebra.sqrt(::StridedMatrix{<:Real})
LinearAlgebra.cos(::StridedMatrix{<:Real})
Expand Down
36 changes: 36 additions & 0 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,20 @@ function (^)(A::AbstractMatrix{T}, p::Real) where T
# Otherwise, use Schur decomposition
return schurpow(A, p)
end

"""
^(A::AbstractMatrix, p::Number)
Matrix power, equivalent to ``\\exp(p\\log(A))``
# Examples
```jldoctest
julia> [1 2; 0 3]^3
2×2 Array{Int64,2}:
1 26
0 27
```
"""
(^)(A::AbstractMatrix, p::Number) = exp(p*log(A))

# Matrix exponential
Expand Down Expand Up @@ -467,6 +481,28 @@ julia> exp(A)
exp(A::StridedMatrix{<:BlasFloat}) = exp!(copy(A))
exp(A::StridedMatrix{<:Union{Integer,Complex{<:Integer}}}) = exp!(float.(A))

"""
^(b::Number, A::AbstractMatrix)
Matrix exponential, equivalent to ``\\exp(\\log(b)A)``.
!!! compat "Julia 1.1"
Support for raising `Irrational` numbers (like `ℯ`)
to a matrix was added in Julia 1.1.
# Examples
```jldoctest
julia> 2^[1 2; 0 3]
2×2 Array{Float64,2}:
2.0 6.0
0.0 8.0
julia> ℯ^[1 2; 0 3]
2×2 Array{Float64,2}:
2.71828 17.3673
0.0 20.0855
```
"""
Base.:^(b::Number, A::AbstractMatrix) = exp!(log(b)*A)
# method for ℯ to explicitly elide the log(b) multiplication
Base.:^(::Irrational{:ℯ}, A::AbstractMatrix) = exp(A)
Expand Down

0 comments on commit 75da558

Please sign in to comment.