Skip to content

Commit 5228f10

Browse files
committed
Deprecate expm in favor of exp.
1 parent f87dea2 commit 5228f10

13 files changed

+52
-44
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ Deprecated or removed
296296
full path if you need access to executables or libraries in the `JULIA_HOME` directory, e.g.
297297
`joinpath(JULIA_HOME, "7z.exe")` for `7z.exe` ([#21540]).
298298

299+
* `expm` has been deprecated in favor of `exp` ([#23233]).
300+
299301
* Calling `union` with no arguments is deprecated; construct an empty set with an appropriate
300302
element type using `Set{T}()` instead ([#23144]).
301303

@@ -1156,3 +1158,5 @@ Command-line option changes
11561158
[#23117]: https://github.com/JuliaLang/julia/issues/23117
11571159
[#23144]: https://github.com/JuliaLang/julia/issues/23144
11581160
[#23157]: https://github.com/JuliaLang/julia/issues/23157
1161+
[#23187]: https://github.com/JuliaLang/julia/issues/23187
1162+
[#23233]: https://github.com/JuliaLang/julia/issues/23233

base/deprecated.jl

+11-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ for f in (:sin, :sinh, :sind, :asin, :asinh, :asind,
220220
:tan, :tanh, :tand, :atan, :atanh, :atand,
221221
:sinpi, :cosc, :ceil, :floor, :trunc, :round,
222222
:log1p, :expm1, :abs, :abs2,
223-
:log, :log2, :log10, :exp, :exp2, :exp10, :sinc, :cospi,
223+
:log, :log2, :log10, :exp2, :exp10, :sinc, :cospi,
224224
:cos, :cosh, :cosd, :acos, :acosd,
225225
:cot, :coth, :cotd, :acot, :acotd,
226226
:sec, :sech, :secd, :asech,
@@ -251,7 +251,7 @@ for f in (
251251
# base/special/gamma.jl
252252
:gamma, :lfact,
253253
# base/math.jl
254-
:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp, :exp2,
254+
:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp2,
255255
:expm1, :exp10, :sin, :cos, :tan, :asin, :acos, :acosh, :atanh,
256256
#=:log,=# :log2, :log10, :lgamma, #=:log1p,=# :sqrt,
257257
# base/floatfuncs.jl
@@ -1632,6 +1632,15 @@ function SymTridiagonal(dv::AbstractVector{T}, ev::AbstractVector{S}) where {T,S
16321632
SymTridiagonal(convert(Vector{R}, dv), convert(Vector{R}, ev))
16331633
end
16341634

1635+
# deprecate expm in favor of exp
1636+
@deprecate expm!(A::StridedMatrix{<:LinAlg.BlasFloat}) exp!(A)
1637+
@deprecate expm(A::StridedMatrix{<:LinAlg.BlasFloat}) exp(A)
1638+
@deprecate expm(A::StridedMatrix{<:Integer}) exp(A)
1639+
@deprecate expm(A::Hermitian) exp(A)
1640+
@deprecate expm(A::Symmetric) exp(A)
1641+
@deprecate expm(D::Diagonal) exp(D)
1642+
@deprecate expm(x::Number) exp(x)
1643+
16351644
# PR #23092
16361645
@eval LibGit2 begin
16371646
function prompt(msg::AbstractString; default::AbstractString="", password::Bool=false)

base/exports.jl

-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ export
581581
eigvals,
582582
eigvals!,
583583
eigvecs,
584-
expm,
585584
eye,
586585
factorize,
587586
givens,

base/linalg/dense.jl

+7-8
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ function (^)(A::AbstractMatrix{T}, p::Real) where T
420420
# Otherwise, use Schur decomposition
421421
return schurpow(A, p)
422422
end
423-
(^)(A::AbstractMatrix, p::Number) = expm(p*logm(A))
423+
(^)(A::AbstractMatrix, p::Number) = exp(p*logm(A))
424424

425425
# Matrix exponential
426426

427427
"""
428-
expm(A)
428+
exp(A::AbstractMatrix)
429429
430430
Compute the matrix exponential of `A`, defined by
431431
@@ -445,22 +445,21 @@ julia> A = eye(2, 2)
445445
1.0 0.0
446446
0.0 1.0
447447
448-
julia> expm(A)
448+
julia> exp(A)
449449
2×2 Array{Float64,2}:
450450
2.71828 0.0
451451
0.0 2.71828
452452
```
453453
"""
454-
expm(A::StridedMatrix{<:BlasFloat}) = expm!(copy(A))
455-
expm(A::StridedMatrix{<:Integer}) = expm!(float(A))
456-
expm(x::Number) = exp(x)
454+
exp(A::StridedMatrix{<:BlasFloat}) = exp!(copy(A))
455+
exp(A::StridedMatrix{<:Integer}) = exp!(float(A))
457456

458457
## Destructive matrix exponential using algorithm from Higham, 2008,
459458
## "Functions of Matrices: Theory and Computation", SIAM
460-
function expm!(A::StridedMatrix{T}) where T<:BlasFloat
459+
function exp!(A::StridedMatrix{T}) where T<:BlasFloat
461460
n = checksquare(A)
462461
if ishermitian(A)
463-
return full(expm(Hermitian(A)))
462+
return full(exp(Hermitian(A)))
464463
end
465464
ilo, ihi, scale = LAPACK.gebal!('B', A) # modifies A
466465
nA = norm(A, 1)

base/linalg/diagonal.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ end
326326
eye(::Type{Diagonal{T}}, n::Int) where {T} = Diagonal(ones(T,n))
327327

328328
# Matrix functions
329-
expm(D::Diagonal) = Diagonal(exp.(D.diag))
330-
expm(D::Diagonal{<:AbstractMatrix}) = Diagonal(expm.(D.diag))
329+
exp(D::Diagonal) = Diagonal(exp.(D.diag))
331330
logm(D::Diagonal) = Diagonal(log.(D.diag))
332331
logm(D::Diagonal{<:AbstractMatrix}) = Diagonal(logm.(D.diag))
333332
sqrtm(D::Diagonal) = Diagonal(sqrt.(D.diag))

base/linalg/linalg.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Base: \, /, *, ^, +, -, ==
66
import Base: A_mul_Bt, At_ldiv_Bt, A_rdiv_Bc, At_ldiv_B, Ac_mul_Bc, A_mul_Bc, Ac_mul_B,
77
Ac_ldiv_B, Ac_ldiv_Bc, At_mul_Bt, A_rdiv_Bt, At_mul_B
88
import Base: USE_BLAS64, abs, big, broadcast, ceil, conj, convert, copy, copy!,
9-
ctranspose, eltype, eye, findmax, findmin, fill!, floor, full, getindex,
9+
ctranspose, eltype, exp, eye, findmax, findmin, fill!, floor, full, getindex,
1010
hcat, imag, indices, inv, isapprox, isone, IndexStyle, kron, length, map,
1111
ndims, oneunit, parent, power_by_squaring, print_matrix, promote_rule, real, round,
1212
setindex!, show, similar, size, transpose, trunc, typed_hcat
@@ -80,7 +80,6 @@ export
8080
eigvals,
8181
eigvals!,
8282
eigvecs,
83-
expm,
8483
eye,
8584
factorize,
8685
givens,

base/linalg/symmetric.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,11 @@ function ^(A::Hermitian{T}, p::Real) where T
589589
end
590590
end
591591

592-
function expm(A::Symmetric)
592+
function exp(A::Symmetric)
593593
F = eigfact(A)
594594
return Symmetric((F.vectors * Diagonal(exp.(F.values))) * F.vectors')
595595
end
596-
function expm(A::Hermitian{T}) where T
596+
function exp(A::Hermitian{T}) where T
597597
n = checksquare(A)
598598
F = eigfact(A)
599599
retmat = (F.vectors * Diagonal(exp.(F.values))) * F.vectors'

doc/src/manual/linear-algebra.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ as well as whether hooks to various optimized methods for them in LAPACK are ava
177177

178178
| Matrix type | `+` | `-` | `*` | `\` | Other functions with optimized methods |
179179
|:------------------------- |:--- |:--- |:--- |:--- |:------------------------------------------------------------------- |
180-
| [`Symmetric`](@ref) | | | | MV | [`inv()`](@ref), [`sqrtm()`](@ref), [`expm()`](@ref) |
181-
| [`Hermitian`](@ref) | | | | MV | [`inv()`](@ref), [`sqrtm()`](@ref), [`expm()`](@ref) |
180+
| [`Symmetric`](@ref) | | | | MV | [`inv()`](@ref), [`sqrtm()`](@ref), [`exp()`](@ref) |
181+
| [`Hermitian`](@ref) | | | | MV | [`inv()`](@ref), [`sqrtm()`](@ref), [`exp()`](@ref) |
182182
| [`UpperTriangular`](@ref) | | | MV | MV | [`inv()`](@ref), [`det()`](@ref) |
183183
| [`LowerTriangular`](@ref) | | | MV | MV | [`inv()`](@ref), [`det()`](@ref) |
184184
| [`SymTridiagonal`](@ref) | M | M | MS | MV | [`eigmax()`](@ref), [`eigmin()`](@ref) |

test/linalg/dense.jl

+16-17
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ bimg = randn(n,2)/2
139139
A = zeros(eltya,1,1)
140140
A[1,1] = α
141141
@test diagm(α) == A # Test behavior of `diagm` when passed a scalar
142-
@test expm(α) == exp(α) # `expm` should behave like `exp` with scalar argument
143142
end
144143

145144
@testset "Factorize" begin
@@ -416,7 +415,7 @@ end
416415
eA1 = convert(Matrix{elty}, [147.866622446369 127.781085523181 127.781085523182;
417416
183.765138646367 183.765138646366 163.679601723179;
418417
71.797032399996 91.8825693231832 111.968106246371]')
419-
@test expm(A1) eA1
418+
@test exp(A1) eA1
420419

421420
A2 = convert(Matrix{elty},
422421
[29.87942128909879 0.7815750847907159 -2.289519314033932;
@@ -426,21 +425,21 @@ end
426425
[ 5496313853692458.0 -18231880972009236.0 -30475770808580460.0;
427426
-18231880972009252.0 60605228702221920.0 101291842930249760.0;
428427
-30475770808580480.0 101291842930249728.0 169294411240851968.0])
429-
@test expm(A2) eA2
428+
@test exp(A2) eA2
430429

431430
A3 = convert(Matrix{elty}, [-131 19 18;-390 56 54;-387 57 52])
432431
eA3 = convert(Matrix{elty}, [-1.50964415879218 -5.6325707998812 -4.934938326092;
433432
0.367879439109187 1.47151775849686 1.10363831732856;
434433
0.135335281175235 0.406005843524598 0.541341126763207]')
435-
@test expm(A3) eA3
434+
@test exp(A3) eA3
436435

437436
A4 = convert(Matrix{elty}, [0.25 0.25; 0 0])
438437
eA4 = convert(Matrix{elty}, [1.2840254166877416 0.2840254166877415; 0 1])
439-
@test expm(A4) eA4
438+
@test exp(A4) eA4
440439

441440
A5 = convert(Matrix{elty}, [0 0.02; 0 0])
442441
eA5 = convert(Matrix{elty}, [1 0.02; 0 1])
443-
@test expm(A5) eA5
442+
@test exp(A5) eA5
444443

445444
# Hessenberg
446445
@test hessfact(A1)[:H] convert(Matrix{elty},
@@ -454,20 +453,20 @@ end
454453
1/3 1/4 1/5 1/6;
455454
1/4 1/5 1/6 1/7;
456455
1/5 1/6 1/7 1/8])
457-
@test expm(logm(A4)) A4
456+
@test exp(logm(A4)) A4
458457

459458
A5 = convert(Matrix{elty}, [1 1 0 1; 0 1 1 0; 0 0 1 1; 1 0 0 1])
460-
@test expm(logm(A5)) A5
459+
@test exp(logm(A5)) A5
461460

462461
A6 = convert(Matrix{elty}, [-5 2 0 0 ; 1/2 -7 3 0; 0 1/3 -9 4; 0 0 1/4 -11])
463-
@test expm(logm(A6)) A6
462+
@test exp(logm(A6)) A6
464463

465464
A7 = convert(Matrix{elty}, [1 0 0 1e-8; 0 1 0 0; 0 0 1 0; 0 0 0 1])
466-
@test expm(logm(A7)) A7
465+
@test exp(logm(A7)) A7
467466
end
468467

469468
A8 = 100 * [-1+1im 0 0 1e-8; 0 1 0 0; 0 0 1 0; 0 0 0 1]
470-
@test expm(logm(A8)) A8
469+
@test exp(logm(A8)) A8
471470
end
472471

473472
@testset "issue 5116" begin
@@ -476,19 +475,19 @@ end
476475
0.006540706968939 -0.999786072879326 0.0 0.0
477476
0.0 0.0 1.0 0.0
478477
0.013081413937878 -3.999572145758650 0.0 1.0]
479-
@test expm(A9) eA9
478+
@test exp(A9) eA9
480479

481480
A10 = [ 0. 0. 0. 0. ; 0. 0. -im 0.; 0. im 0. 0.; 0. 0. 0. 0.]
482481
eA10 = [ 1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
483482
0.0+0.0im 1.543080634815244+0.0im 0.0-1.175201193643801im 0.0+0.0im
484483
0.0+0.0im 0.0+1.175201193643801im 1.543080634815243+0.0im 0.0+0.0im
485484
0.0+0.0im 0.0+0.0im 0.0+0.0im 1.0+0.0im]
486-
@test expm(A10) eA10
485+
@test exp(A10) eA10
487486
end
488487

489488
@testset "Additional matrix logarithm tests" for elty in (Float64, Complex{Float64})
490489
A11 = convert(Matrix{elty}, [3 2; -5 -3])
491-
@test expm(logm(A11)) A11
490+
@test exp(logm(A11)) A11
492491

493492
A12 = convert(Matrix{elty}, [1 -1; 1 -1])
494493
@test typeof(logm(A12)) == Array{Complex{Float64}, 2}
@@ -498,7 +497,7 @@ end
498497
0.2310490602 1.295566591 0.2651438179;
499498
0.2310490602 0.1969543025 1.363756107])
500499
@test logm(A1) logmA1
501-
@test expm(logm(A1)) A1
500+
@test exp(logm(A1)) A1
502501

503502
A4 = convert(Matrix{elty}, [1/2 1/3 1/4 1/5+eps();
504503
1/3 1/4 1/5 1/6;
@@ -509,7 +508,7 @@ end
509508
0.4462766564 2.994142974 -7.351095988 3.318413247;
510509
0.2414170219 0.5865285289 3.318413247 -5.444632124])
511510
@test logm(A4) logmA4
512-
@test expm(logm(A4)) A4
511+
@test exp(logm(A4)) A4
513512
end
514513

515514
@testset "issue #7181" begin
@@ -615,7 +614,7 @@ end
615614

616615
@testset "test ops on Numbers for $elty" for elty in [Float32,Float64,Complex64,Complex128]
617616
a = rand(elty)
618-
@test expm(a) == exp(a)
617+
@test exp(a) == exp(a)
619618
@test isposdef(one(elty))
620619
@test sqrtm(a) == sqrt(a)
621620
@test logm(a) log(a)

test/linalg/diagonal.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ srand(1)
6060
@test func(D) func(DM) atol=n^2*eps(relty)*(1+(elty<:Complex))
6161
end
6262
if relty <: BlasFloat
63-
for func in (expm,)
63+
for func in (exp,)
6464
@test func(D) func(DM) atol=n^3*eps(relty)
6565
end
6666
@test logm(Diagonal(abs.(D.diag))) logm(abs.(DM)) atol=n^3*eps(relty)
@@ -381,7 +381,7 @@ end
381381
@test ishermitian(Dherm) == true
382382
@test ishermitian(Dsym) == false
383383

384-
@test expm(D) == Diagonal([expm([1 2; 3 4]), expm([1 2; 3 4])])
384+
@test exp(D) == Diagonal([exp([1 2; 3 4]), exp([1 2; 3 4])])
385385
@test logm(D) == Diagonal([logm([1 2; 3 4]), logm([1 2; 3 4])])
386386
@test sqrtm(D) == Diagonal([sqrtm([1 2; 3 4]), sqrtm([1 2; 3 4])])
387387
end

test/linalg/lapack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ end
613613

614614
# Issue 13976
615615
let A = [NaN 0.0 NaN; 0 0 0; NaN 0 NaN]
616-
@test_throws ArgumentError expm(A)
616+
@test_throws ArgumentError exp(A)
617617
end
618618

619619
# Issue 14065 (and 14220)

test/linalg/symmetric.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ end
1212
@testset "Hermitian matrix exponential/log" begin
1313
A1 = randn(4,4) + im*randn(4,4)
1414
A2 = A1 + A1'
15-
@test expm(A2) expm(Hermitian(A2))
15+
@test exp(A2) exp(Hermitian(A2))
1616
@test logm(A2) logm(Hermitian(A2))
1717
A3 = A1 * A1' # posdef
18-
@test expm(A3) expm(Hermitian(A3))
18+
@test exp(A3) exp(Hermitian(A3))
1919
@test logm(A3) logm(Hermitian(A3))
2020

2121
A1 = randn(4,4)
2222
A3 = A1 * A1'
2323
A4 = A1 + A1.'
24-
@test expm(A4) expm(Symmetric(A4))
24+
@test exp(A4) exp(Symmetric(A4))
2525
@test logm(A3) logm(Symmetric(A3))
2626
@test logm(A3) logm(Hermitian(A3))
2727
end

test/linalg/triangular.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
174174
@test B == viewA1.'
175175
end
176176

177-
#expm/logm
177+
#exp/logm
178178
if (elty1 == Float64 || elty1 == Complex128) && (t1 == UpperTriangular || t1 == LowerTriangular)
179-
@test expm(full(logm(A1))) full(A1)
179+
@test exp(full(logm(A1))) full(A1)
180180
end
181181

182182
# scale

0 commit comments

Comments
 (0)