Skip to content

Commit 65f07e6

Browse files
committed
Deprecate logm in favor of log.
1 parent 109b0b4 commit 65f07e6

13 files changed

+79
-50
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ Deprecated or removed
338338

339339
* `expm` has been deprecated in favor of `exp` ([#23233]).
340340

341+
* `logm` has been deprecated in favor of `log` ([#CATS]).
342+
341343
* Calling `union` with no arguments is deprecated; construct an empty set with an appropriate
342344
element type using `Set{T}()` instead ([#23144]).
343345

base/deprecated.jl

+6-3
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, :exp2, :exp10, :sinc, :cospi,
223+
:log2, :log10, :exp2, :exp10, :sinc, :cospi,
224224
:cos, :cosh, :cosd, :acos, :acosd,
225225
:cot, :coth, :cotd, :acot, :acotd,
226226
:sec, :sech, :secd, :asech,
@@ -247,13 +247,13 @@ for f in (
247247
# base/special/trig.jl
248248
:sinpi, :cospi, :sinc, :cosc,
249249
# base/special/log.jl
250-
:log, :log1p,
250+
:log1p,
251251
# base/special/gamma.jl
252252
:gamma, :lfact,
253253
# base/math.jl
254254
:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp2,
255255
:expm1, :exp10, :sin, :cos, :tan, :asin, :acos, :acosh, :atanh,
256-
#=:log,=# :log2, :log10, :lgamma, #=:log1p,=# :sqrt,
256+
:log2, :log10, :lgamma, #=:log1p,=# :sqrt,
257257
# base/floatfuncs.jl
258258
:abs, :abs2, :angle, :isnan, :isinf, :isfinite,
259259
# base/complex.jl
@@ -1664,6 +1664,9 @@ end
16641664
@deprecate expm! exp!
16651665
@deprecate expm exp
16661666

1667+
# deprecate logm in favor of log
1668+
@deprecate logm log
1669+
16671670
# PR #23092
16681671
@eval LibGit2 begin
16691672
function prompt(msg::AbstractString; default::AbstractString="", password::Bool=false)

base/exports.jl

-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ export
589589
linreg,
590590
logabsdet,
591591
logdet,
592-
logm,
593592
lu,
594593
lufact!,
595594
lufact,

base/linalg/dense.jl

+9-14
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function (^)(A::AbstractMatrix{T}, p::Real) where T
426426
# Otherwise, use Schur decomposition
427427
return schurpow(A, p)
428428
end
429-
(^)(A::AbstractMatrix, p::Number) = exp(p*logm(A))
429+
(^)(A::AbstractMatrix, p::Number) = exp(p*log(A))
430430

431431
# Matrix exponential
432432

@@ -556,7 +556,7 @@ function rcswap!(i::Integer, j::Integer, X::StridedMatrix{<:Number})
556556
end
557557

558558
"""
559-
logm(A{T}::StridedMatrix{T})
559+
log(A{T}::StridedMatrix{T})
560560
561561
If `A` has no negative real eigenvalue, compute the principal matrix logarithm of `A`, i.e.
562562
the unique matrix ``X`` such that ``e^X = A`` and ``-\\pi < Im(\\lambda) < \\pi`` for all
@@ -580,25 +580,25 @@ julia> A = 2.7182818 * eye(2)
580580
2.71828 0.0
581581
0.0 2.71828
582582
583-
julia> logm(A)
583+
julia> log(A)
584584
2×2 Symmetric{Float64,Array{Float64,2}}:
585585
1.0 0.0
586586
0.0 1.0
587587
```
588588
"""
589-
function logm(A::StridedMatrix{T}) where T
589+
function log(A::StridedMatrix{T}) where T
590590
# If possible, use diagonalization
591591
if issymmetric(A) && T <: Real
592-
return logm(Symmetric(A))
592+
return log(Symmetric(A))
593593
end
594594
if ishermitian(A)
595-
return logm(Hermitian(A))
595+
return log(Hermitian(A))
596596
end
597597

598598
# Use Schur decomposition
599599
n = checksquare(A)
600600
if istriu(A)
601-
return full(logm(UpperTriangular(complex(A))))
601+
return full(log(UpperTriangular(complex(A))))
602602
else
603603
if isreal(A)
604604
SchurF = schurfact(real(A))
@@ -607,19 +607,14 @@ function logm(A::StridedMatrix{T}) where T
607607
end
608608
if !istriu(SchurF.T)
609609
SchurS = schurfact(complex(SchurF.T))
610-
logT = SchurS.Z * logm(UpperTriangular(SchurS.T)) * SchurS.Z'
610+
logT = SchurS.Z * log(UpperTriangular(SchurS.T)) * SchurS.Z'
611611
return SchurF.Z * logT * SchurF.Z'
612612
else
613-
R = logm(UpperTriangular(complex(SchurF.T)))
613+
R = log(UpperTriangular(complex(SchurF.T)))
614614
return SchurF.Z * R * SchurF.Z'
615615
end
616616
end
617617
end
618-
function logm(a::Number)
619-
b = log(complex(a))
620-
return imag(b) == 0 ? real(b) : b
621-
end
622-
logm(a::Complex) = log(a)
623618

624619
"""
625620
sqrtm(A)

base/linalg/diagonal.jl

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

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

base/linalg/linalg.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Base: A_mul_Bt, At_ldiv_Bt, A_rdiv_Bc, At_ldiv_B, Ac_mul_Bc, A_mul_Bc, Ac
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!,
99
adjoint, eltype, exp, eye, findmax, findmin, fill!, floor, full, getindex,
10-
hcat, imag, indices, inv, isapprox, isone, IndexStyle, kron, length, map,
10+
hcat, imag, indices, inv, isapprox, isone, IndexStyle, kron, length, log, map,
1111
ndims, oneunit, parent, power_by_squaring, print_matrix, promote_rule, real, round,
1212
setindex!, show, similar, size, transpose, trunc, typed_hcat
1313
using Base: hvcat_fill, iszero, IndexLinear, _length, promote_op, promote_typeof,
@@ -101,7 +101,6 @@ export
101101
linreg,
102102
logabsdet,
103103
logdet,
104-
logm,
105104
lu,
106105
lufact,
107106
lufact!,

base/linalg/symmetric.jl

+34-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ function exp(A::Hermitian{T}) where T
607607
end
608608
end
609609

610-
for (funm, func) in ([:logm,:log], [:sqrtm,:sqrt])
610+
for (funm, func) in ([:sqrtm,:sqrt],)
611611
@eval begin
612612
function ($funm)(A::Symmetric{T}) where T<:Real
613613
F = eigfact(A)
@@ -639,3 +639,36 @@ for (funm, func) in ([:logm,:log], [:sqrtm,:sqrt])
639639
end
640640
end
641641
end
642+
643+
for func in (:log, #=:sqrtm=#)
644+
@eval begin
645+
function ($func)(A::Symmetric{T}) where T<:Real
646+
F = eigfact(A)
647+
if all-> λ 0, F.values)
648+
retmat = (F.vectors * Diagonal(($func).(F.values))) * F.vectors'
649+
else
650+
retmat = (F.vectors * Diagonal(($func).(complex.(F.values)))) * F.vectors'
651+
end
652+
return Symmetric(retmat)
653+
end
654+
655+
function ($func)(A::Hermitian{T}) where T
656+
n = checksquare(A)
657+
F = eigfact(A)
658+
if all-> λ 0, F.values)
659+
retmat = (F.vectors * Diagonal(($func).(F.values))) * F.vectors'
660+
if T <: Real
661+
return Hermitian(retmat)
662+
else
663+
for i = 1:n
664+
retmat[i,i] = real(retmat[i,i])
665+
end
666+
return Hermitian(retmat)
667+
end
668+
else
669+
retmat = (F.vectors * Diagonal(($func).(complex(F.values)))) * F.vectors'
670+
return retmat
671+
end
672+
end
673+
end
674+
end

base/linalg/triangular.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ powm(A::LowerTriangular, p::Real) = powm(A.', p::Real).'
17891789
# Based on the code available at http://eprints.ma.man.ac.uk/1851/02/logm.zip,
17901790
# Copyright (c) 2011, Awad H. Al-Mohy and Nicholas J. Higham
17911791
# Julia version relicensed with permission from original authors
1792-
function logm(A0::UpperTriangular{T}) where T<:Union{Float64,Complex{Float64}}
1792+
function log(A0::UpperTriangular{T}) where T<:Union{Float64,Complex{Float64}}
17931793
maxsqrt = 100
17941794
theta = [1.586970738772063e-005,
17951795
2.313807884242979e-003,
@@ -1961,9 +1961,9 @@ function logm(A0::UpperTriangular{T}) where T<:Union{Float64,Complex{Float64}}
19611961

19621962
return UpperTriangular(Y)
19631963
end
1964-
logm(A::LowerTriangular) = logm(A.').'
1964+
log(A::LowerTriangular) = log(A.').'
19651965

1966-
# Auxiliary functions for logm and matrix power
1966+
# Auxiliary functions for matrix logarithm and matrix power
19671967

19681968
# Compute accurate diagonal of A = A0^s - I
19691969
# Al-Mohy, "A more accurate Briggs method for the logarithm",
@@ -2117,7 +2117,7 @@ end
21172117
unw(x::Real) = 0
21182118
unw(x::Number) = ceil((imag(x) - pi) / (2 * pi))
21192119

2120-
# End of auxiliary functions for logm and matrix power
2120+
# End of auxiliary functions for matrix logarithm and matrix power
21212121

21222122
function sqrtm(A::UpperTriangular)
21232123
realmatrix = false

doc/src/stdlib/linalg.md

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Base.repmat
9292
Base.kron
9393
Base.SparseArrays.blkdiag
9494
Base.LinAlg.linreg
95-
Base.LinAlg.logm
9695
Base.LinAlg.sqrtm
9796
Base.LinAlg.lyap
9897
Base.LinAlg.sylvester

test/linalg/dense.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,20 @@ end
453453
1/3 1/4 1/5 1/6;
454454
1/4 1/5 1/6 1/7;
455455
1/5 1/6 1/7 1/8])
456-
@test exp(logm(A4)) A4
456+
@test exp(log(A4)) A4
457457

458458
A5 = convert(Matrix{elty}, [1 1 0 1; 0 1 1 0; 0 0 1 1; 1 0 0 1])
459-
@test exp(logm(A5)) A5
459+
@test exp(log(A5)) A5
460460

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

464464
A7 = convert(Matrix{elty}, [1 0 0 1e-8; 0 1 0 0; 0 0 1 0; 0 0 0 1])
465-
@test exp(logm(A7)) A7
465+
@test exp(log(A7)) A7
466466
end
467467

468468
A8 = 100 * [-1+1im 0 0 1e-8; 0 1 0 0; 0 0 1 0; 0 0 0 1]
469-
@test exp(logm(A8)) A8
469+
@test exp(log(A8)) A8
470470
end
471471

472472
@testset "issue 5116" begin
@@ -487,28 +487,28 @@ end
487487

488488
@testset "Additional matrix logarithm tests" for elty in (Float64, Complex{Float64})
489489
A11 = convert(Matrix{elty}, [3 2; -5 -3])
490-
@test exp(logm(A11)) A11
490+
@test exp(log(A11)) A11
491491

492492
A12 = convert(Matrix{elty}, [1 -1; 1 -1])
493-
@test typeof(logm(A12)) == Array{Complex{Float64}, 2}
493+
@test typeof(log(A12)) == Array{Complex{Float64}, 2}
494494

495495
A1 = convert(Matrix{elty}, [4 2 0; 1 4 1; 1 1 4])
496-
logmA1 = convert(Matrix{elty}, [1.329661349 0.5302876358 -0.06818951543;
496+
logA1 = convert(Matrix{elty}, [1.329661349 0.5302876358 -0.06818951543;
497497
0.2310490602 1.295566591 0.2651438179;
498498
0.2310490602 0.1969543025 1.363756107])
499-
@test logm(A1) logmA1
500-
@test exp(logm(A1)) A1
499+
@test log(A1) logA1
500+
@test exp(log(A1)) A1
501501

502502
A4 = convert(Matrix{elty}, [1/2 1/3 1/4 1/5+eps();
503503
1/3 1/4 1/5 1/6;
504504
1/4 1/5 1/6 1/7;
505505
1/5 1/6 1/7 1/8])
506-
logmA4 = convert(Matrix{elty}, [-1.73297159 1.857349738 0.4462766564 0.2414170219;
506+
logA4 = convert(Matrix{elty}, [-1.73297159 1.857349738 0.4462766564 0.2414170219;
507507
1.857349738 -5.335033737 2.994142974 0.5865285289;
508508
0.4462766564 2.994142974 -7.351095988 3.318413247;
509509
0.2414170219 0.5865285289 3.318413247 -5.444632124])
510-
@test logm(A4) logmA4
511-
@test exp(logm(A4)) A4
510+
@test log(A4) logA4
511+
@test exp(log(A4)) A4
512512
end
513513

514514
@testset "issue #7181" begin
@@ -677,7 +677,7 @@ end
677677
@test exp(a) == exp(a)
678678
@test isposdef(one(elty))
679679
@test sqrtm(a) == sqrt(a)
680-
@test logm(a) log(a)
680+
@test log(a) log(a)
681681
@test lyap(one(elty),a) == -a/2
682682
end
683683

test/linalg/diagonal.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ srand(1)
6363
for func in (exp,)
6464
@test func(D) func(DM) atol=n^3*eps(relty)
6565
end
66-
@test logm(Diagonal(abs.(D.diag))) logm(abs.(DM)) atol=n^3*eps(relty)
66+
@test log(Diagonal(abs.(D.diag))) log(abs.(DM)) atol=n^3*eps(relty)
6767
end
6868
if elty <: BlasComplex
6969
for func in (logdet, sqrtm)
@@ -382,7 +382,7 @@ end
382382
@test ishermitian(Dsym) == false
383383

384384
@test exp(D) == Diagonal([exp([1 2; 3 4]), exp([1 2; 3 4])])
385-
@test logm(D) == Diagonal([logm([1 2; 3 4]), logm([1 2; 3 4])])
385+
@test log(D) == Diagonal([log([1 2; 3 4]), log([1 2; 3 4])])
386386
@test sqrtm(D) == Diagonal([sqrtm([1 2; 3 4]), sqrtm([1 2; 3 4])])
387387
end
388388

test/linalg/symmetric.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ end
1313
A1 = randn(4,4) + im*randn(4,4)
1414
A2 = A1 + A1'
1515
@test exp(A2) exp(Hermitian(A2))
16-
@test logm(A2) logm(Hermitian(A2))
16+
@test log(A2) log(Hermitian(A2))
1717
A3 = A1 * A1' # posdef
1818
@test exp(A3) exp(Hermitian(A3))
19-
@test logm(A3) logm(Hermitian(A3))
19+
@test log(A3) log(Hermitian(A3))
2020

2121
A1 = randn(4,4)
2222
A3 = A1 * A1'
2323
A4 = A1 + A1.'
2424
@test exp(A4) exp(Symmetric(A4))
25-
@test logm(A3) logm(Symmetric(A3))
26-
@test logm(A3) logm(Hermitian(A3))
25+
@test log(A3) log(Symmetric(A3))
26+
@test log(A3) log(Hermitian(A3))
2727
end
2828

2929
@testset "Core functionality" begin

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-
#exp/logm
177+
#exp/log
178178
if (elty1 == Float64 || elty1 == Complex128) && (t1 == UpperTriangular || t1 == LowerTriangular)
179-
@test exp(full(logm(A1))) full(A1)
179+
@test exp(full(log(A1))) full(A1)
180180
end
181181

182182
# scale

0 commit comments

Comments
 (0)