Skip to content

Commit 75da558

Browse files
mortenpifredrikekre
authored andcommitted
News and compat annotation for #29782 (^(::Number, ::AbstractMatrix))
1 parent dd2321b commit 75da558

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Standard library changes
8484
* `current_project()` now searches the parent directories of a Git repository for a `Project.toml` file.
8585
This also affects the behavior of the `--project` command line option when using the default
8686
`--project=@.` ([#29108]).
87+
* Exponentiation operator `^` now supports raising a `Irrational` to an `AbstractMatrix` power ([#29782]).
8788

8889
Compiler/Runtime improvements
8990
-----------------------------

stdlib/LinearAlgebra/docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ LinearAlgebra.pinv
371371
LinearAlgebra.nullspace
372372
Base.kron
373373
LinearAlgebra.exp(::StridedMatrix{<:LinearAlgebra.BlasFloat})
374+
Base.:^(::AbstractMatrix, ::Number)
375+
Base.:^(::Number, ::AbstractMatrix)
374376
LinearAlgebra.log(::StridedMatrix)
375377
LinearAlgebra.sqrt(::StridedMatrix{<:Real})
376378
LinearAlgebra.cos(::StridedMatrix{<:Real})

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,20 @@ function (^)(A::AbstractMatrix{T}, p::Real) where T
433433
# Otherwise, use Schur decomposition
434434
return schurpow(A, p)
435435
end
436+
437+
"""
438+
^(A::AbstractMatrix, p::Number)
439+
440+
Matrix power, equivalent to ``\\exp(p\\log(A))``
441+
442+
# Examples
443+
```jldoctest
444+
julia> [1 2; 0 3]^3
445+
2×2 Array{Int64,2}:
446+
1 26
447+
0 27
448+
```
449+
"""
436450
(^)(A::AbstractMatrix, p::Number) = exp(p*log(A))
437451

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

484+
"""
485+
^(b::Number, A::AbstractMatrix)
486+
487+
Matrix exponential, equivalent to ``\\exp(\\log(b)A)``.
488+
489+
!!! compat "Julia 1.1"
490+
Support for raising `Irrational` numbers (like `ℯ`)
491+
to a matrix was added in Julia 1.1.
492+
493+
# Examples
494+
```jldoctest
495+
julia> 2^[1 2; 0 3]
496+
2×2 Array{Float64,2}:
497+
2.0 6.0
498+
0.0 8.0
499+
500+
julia> ℯ^[1 2; 0 3]
501+
2×2 Array{Float64,2}:
502+
2.71828 17.3673
503+
0.0 20.0855
504+
```
505+
"""
470506
Base.:^(b::Number, A::AbstractMatrix) = exp!(log(b)*A)
471507
# method for ℯ to explicitly elide the log(b) multiplication
472508
Base.:^(::Irrational{:ℯ}, A::AbstractMatrix) = exp(A)

0 commit comments

Comments
 (0)