Skip to content

Commit 45b734f

Browse files
committed
Deprecate eigfact to eig.
1 parent 0f7d9e2 commit 45b734f

19 files changed

+129
-144
lines changed

NEWS.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ This section lists changes that do not have deprecation warnings.
230230
* `lu` methods now return decomposition objects such as `LU` rather than
231231
tuples of arrays or tuples of numbers ([#27159]).
232232

233+
* `eig` methods now return decomposition objects such as `Eigen` and
234+
`GeneralizedEigen` rather than tuples of arrays or tuples of numbers ([#27159]).
235+
233236
* `countlines` now always counts the last non-empty line even if it does not
234237
end with EOL, matching the behavior of `eachline` and `readlines` ([#25845]).
235238

@@ -678,7 +681,7 @@ Deprecated or removed
678681
* The keyword `immutable` is fully deprecated to `struct`, and
679682
`type` is fully deprecated to `mutable struct` ([#19157], [#20418]).
680683

681-
* `lufact` has been deprecated to `lu` ([#27159]).
684+
* `lufact` and `eigfact` have respectively been deprecated to `lu` and `eig` ([#27159]).
682685

683686
* Indexing into multidimensional arrays with more than one index but fewer indices than there are
684687
dimensions is no longer permitted when those trailing dimensions have lengths greater than 1.

stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function _eigs(A, B;
7878
sym = !iscmplx && issymmetric(A) && issymmetric(B)
7979
nevmax = sym ? n-1 : n-2
8080
if nevmax <= 0
81-
throw(ArgumentError("input matrix A is too small. Use eigfact instead."))
81+
throw(ArgumentError("input matrix A is too small. Use eig instead."))
8282
end
8383
if nev > nevmax
8484
@warn "Adjusting nev from $nev to $nevmax"

stdlib/LinearAlgebra/docs/src/index.md

-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ LinearAlgebra.eigvals!
340340
LinearAlgebra.eigmax
341341
LinearAlgebra.eigmin
342342
LinearAlgebra.eigvecs
343-
LinearAlgebra.eigfact
344343
LinearAlgebra.eigfact!
345344
LinearAlgebra.hessfact
346345
LinearAlgebra.hessfact!

stdlib/LinearAlgebra/src/LinearAlgebra.jl

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export
8181
diagm,
8282
dot,
8383
eig,
84-
eigfact,
8584
eigfact!,
8685
eigmax,
8786
eigmin,

stdlib/LinearAlgebra/src/bidiag.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,4 @@ function eigvecs(M::Bidiagonal{T}) where T
625625
end
626626
Q #Actually Triangular
627627
end
628-
eigfact(M::Bidiagonal) = Eigen(eigvals(M), eigvecs(M))
628+
eig(M::Bidiagonal) = Eigen(eigvals(M), eigvecs(M))

stdlib/LinearAlgebra/src/dense.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ Compute the matrix exponential of `A`, defined by
478478
e^A = \\sum_{n=0}^{\\infty} \\frac{A^n}{n!}.
479479
```
480480
481-
For symmetric or Hermitian `A`, an eigendecomposition ([`eigfact`](@ref)) is
481+
For symmetric or Hermitian `A`, an eigendecomposition ([`eig`](@ref)) is
482482
used, otherwise the scaling and squaring algorithm (see [^H05]) is chosen.
483483
484484
[^H05]: Nicholas J. Higham, "The squaring and scaling method for the matrix exponential revisited", SIAM Journal on Matrix Analysis and Applications, 26(4), 2005, 1179-1193. [doi:10.1137/090768539](https://doi.org/10.1137/090768539)
@@ -602,7 +602,7 @@ the unique matrix ``X`` such that ``e^X = A`` and ``-\\pi < Im(\\lambda) < \\pi`
602602
the eigenvalues ``\\lambda`` of ``X``. If `A` has nonpositive eigenvalues, a nonprincipal
603603
matrix function is returned whenever possible.
604604
605-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is
605+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is
606606
used, if `A` is triangular an improved version of the inverse scaling and squaring method is
607607
employed (see [^AH12] and [^AHR13]). For general matrices, the complex Schur form
608608
([`schur`](@ref)) is computed and the triangular algorithm is used on the
@@ -660,7 +660,7 @@ If `A` has no negative real eigenvalues, compute the principal matrix square roo
660660
that is the unique matrix ``X`` with eigenvalues having positive real part such that
661661
``X^2 = A``. Otherwise, a nonprincipal square root is returned.
662662
663-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is
663+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is
664664
used to compute the square root. Otherwise, the square root is determined by means of the
665665
Björck-Hammarling method [^BH83], which computes the complex Schur form ([`schur`](@ref))
666666
and then the complex square root of the triangular factor.
@@ -732,7 +732,7 @@ end
732732
733733
Compute the matrix cosine of a square matrix `A`.
734734
735-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is used to
735+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is used to
736736
compute the cosine. Otherwise, the cosine is determined by calling [`exp`](@ref).
737737
738738
# Examples
@@ -765,7 +765,7 @@ end
765765
766766
Compute the matrix sine of a square matrix `A`.
767767
768-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is used to
768+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is used to
769769
compute the sine. Otherwise, the sine is determined by calling [`exp`](@ref).
770770
771771
# Examples
@@ -851,7 +851,7 @@ end
851851
852852
Compute the matrix tangent of a square matrix `A`.
853853
854-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is used to
854+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is used to
855855
compute the tangent. Otherwise, the tangent is determined by calling [`exp`](@ref).
856856
857857
# Examples
@@ -924,7 +924,7 @@ end
924924
925925
Compute the inverse matrix cosine of a square matrix `A`.
926926
927-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is used to
927+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is used to
928928
compute the inverse cosine. Otherwise, the inverse cosine is determined by using
929929
[`log`](@ref) and [`sqrt`](@ref). For the theory and logarithmic formulas used to compute
930930
this function, see [^AH16_1].
@@ -955,7 +955,7 @@ end
955955
956956
Compute the inverse matrix sine of a square matrix `A`.
957957
958-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is used to
958+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is used to
959959
compute the inverse sine. Otherwise, the inverse sine is determined by using [`log`](@ref)
960960
and [`sqrt`](@ref). For the theory and logarithmic formulas used to compute this function,
961961
see [^AH16_2].
@@ -986,7 +986,7 @@ end
986986
987987
Compute the inverse matrix tangent of a square matrix `A`.
988988
989-
If `A` is symmetric or Hermitian, its eigendecomposition ([`eigfact`](@ref)) is used to
989+
If `A` is symmetric or Hermitian, its eigendecomposition ([`eig`](@ref)) is used to
990990
compute the inverse tangent. Otherwise, the inverse tangent is determined by using
991991
[`log`](@ref). For the theory and logarithmic formulas used to compute this function, see
992992
[^AH16_3].

stdlib/LinearAlgebra/src/deprecated.jl

+19
Original file line numberDiff line numberDiff line change
@@ -1267,3 +1267,22 @@ Base.@deprecate_binding trace tr
12671267
@deprecate(lufact(A::AbstractMatrix{T}) where T, lu(A))
12681268
@deprecate(lufact(A::AbstractMatrix{T}, pivot::Union{Val{false}, Val{true}}) where T, lu(A, pivot))
12691269
@deprecate(lufact(A::Union{AbstractMatrix{T}, AbstractMatrix{Complex{T}}}, pivot::Union{Val{false}, Val{true}} = Val(true)) where {T<:AbstractFloat}, lu(A, pivot))
1270+
1271+
# deprecate eigfact to eig
1272+
@deprecate(eigfact(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) where T, eig(A; permute=permute, scale=scale))
1273+
@deprecate(eigfact(x::Number), eig(x))
1274+
@deprecate(eigfact(A::AbstractMatrix{TA}, B::AbstractMatrix{TB}) where {TA,TB}, eig(A, B))
1275+
@deprecate(eigfact(A::Number, B::Number), eig(A, B))
1276+
1277+
@deprecate(eigfact(A::SymTridiagonal{T}) where T, eig(A))
1278+
@deprecate(eigfact(A::SymTridiagonal{T}, irange::UnitRange) where T, eig(A, irange))
1279+
@deprecate(eigfact(A::SymTridiagonal{T}, vl::Real, vu::Real) where T, eig(A, vl, vu))
1280+
1281+
@deprecate(eigfact(M::Bidiagonal), eig(M))
1282+
@deprecate(eigfact(A::RealHermSymComplexHerm), eig(A))
1283+
@deprecate(eigfact(A::RealHermSymComplexHerm, irange::UnitRange), eig(A, irange))
1284+
@deprecate(eigfact(A::RealHermSymComplexHerm, vl::Real, vh::Real), eig(A, vl, vh))
1285+
1286+
@deprecate(eigfact(A::AbstractTriangular), eig(A))
1287+
1288+
@deprecate(eigfact(D::Diagonal; permute::Bool=true, scale::Bool=true), eig(D; permute=permute, scale=scale))

stdlib/LinearAlgebra/src/diagonal.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ end
445445
eigvals(D::Diagonal{<:Number}) = D.diag
446446
eigvals(D::Diagonal) = [eigvals(x) for x in D.diag] #For block matrices, etc.
447447
eigvecs(D::Diagonal) = Matrix{eltype(D)}(I, size(D))
448-
function eigfact(D::Diagonal; permute::Bool=true, scale::Bool=true)
448+
function eig(D::Diagonal; permute::Bool=true, scale::Bool=true)
449449
if any(!isfinite, D.diag)
450450
throw(ArgumentError("matrix contains Infs or NaNs"))
451451
end

stdlib/LinearAlgebra/src/eigen.jl

+39-78
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ end
2020
GeneralizedEigen(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V} =
2121
GeneralizedEigen{T,V,typeof(vectors),typeof(values)}(values, vectors)
2222

23+
# iteration for destructuring into components
24+
Base.iterate(S::Union{Eigen,GeneralizedEigen}) = (S.values, Val(:vectors))
25+
Base.iterate(S::Union{Eigen,GeneralizedEigen}, ::Val{:vectors}) = (S.vectors, Val(:done))
26+
Base.iterate(S::Union{Eigen,GeneralizedEigen}, ::Val{:done}) = nothing
27+
28+
# indexing for destructuring into components
29+
@inline function Base.getindex(S::Union{Eigen,GeneralizedEigen}, i::Integer)
30+
i == 1 ? (return S.values) :
31+
i == 2 ? (return S.vectors) :
32+
throw(BoundsError(S, i))
33+
end
34+
2335
isposdef(A::Union{Eigen,GeneralizedEigen}) = isreal(A.values) && all(x -> x > 0, A.values)
2436

2537
"""
2638
eigfact!(A, [B])
2739
28-
Same as [`eigfact`](@ref), but saves space by overwriting the input `A` (and
40+
Same as [`eig`](@ref), but saves space by overwriting the input `A` (and
2941
`B`), instead of creating a copy.
3042
"""
3143
function eigfact!(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) where T<:BlasReal
@@ -59,12 +71,14 @@ function eigfact!(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) whe
5971
end
6072

6173
"""
62-
eigfact(A; permute::Bool=true, scale::Bool=true) -> Eigen
74+
eig(A; permute::Bool=true, scale::Bool=true) -> Eigen
6375
6476
Computes the eigenvalue decomposition of `A`, returning an `Eigen` factorization object `F`
6577
which contains the eigenvalues in `F.values` and the eigenvectors in the columns of the
6678
matrix `F.vectors`. (The `k`th eigenvector can be obtained from the slice `F.vectors[:, k]`.)
6779
80+
Iterating the decomposition produces the components `F.values` and `F.vectors`.
81+
6882
The following functions are available for `Eigen` objects: [`inv`](@ref), [`det`](@ref), and [`isposdef`](@ref).
6983
7084
For general nonsymmetric matrices it is possible to specify how the matrix is balanced
@@ -74,7 +88,7 @@ make rows and columns more equal in norm. The default is `true` for both options
7488
7589
# Examples
7690
```jldoctest
77-
julia> F = eigfact([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
91+
julia> F = eig([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
7892
Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}}
7993
eigenvalues:
8094
3-element Array{Float64,1}:
@@ -98,53 +112,26 @@ julia> F.vectors
98112
1.0 0.0 0.0
99113
0.0 1.0 0.0
100114
0.0 0.0 1.0
101-
```
102-
"""
103-
function eigfact(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) where T
104-
AA = copy_oftype(A, eigtype(T))
105-
isdiag(AA) && return eigfact(Diagonal(AA), permute = permute, scale = scale)
106-
return eigfact!(AA, permute = permute, scale = scale)
107-
end
108-
eigfact(x::Number) = Eigen([x], fill(one(x), 1, 1))
109-
110-
function eig(A::Union{Number, StridedMatrix}; permute::Bool=true, scale::Bool=true)
111-
F = eigfact(A, permute=permute, scale=scale)
112-
F.values, F.vectors
113-
end
114115
115-
"""
116-
eig(A::Union{SymTridiagonal, Hermitian, Symmetric}, irange::UnitRange) -> D, V
117-
eig(A::Union{SymTridiagonal, Hermitian, Symmetric}, vl::Real, vu::Real) -> D, V
118-
eig(A, permute::Bool=true, scale::Bool=true) -> D, V
119-
120-
Computes eigenvalues (`D`) and eigenvectors (`V`) of `A`.
121-
See [`eigfact`](@ref) for details on the
122-
`irange`, `vl`, and `vu` arguments
123-
(for [`SymTridiagonal`](@ref), [`Hermitian`](@ref), and
124-
[`Symmetric`](@ref) matrices)
125-
and the `permute` and `scale` keyword arguments.
126-
The eigenvectors are returned columnwise.
116+
julia> vals, vecs = F; # destructuring via iteration
127117
128-
# Examples
129-
```jldoctest
130-
julia> eig([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
131-
([1.0, 3.0, 18.0], [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0])
118+
julia> vals == F.values && vecs == F.vectors
119+
true
132120
```
133-
134-
`eig` is a wrapper around [`eigfact`](@ref), extracting all parts of the
135-
factorization to a tuple; where possible, using [`eigfact`](@ref) is recommended.
136121
"""
137-
function eig(A::AbstractMatrix, args...)
138-
F = eigfact(A, args...)
139-
F.values, F.vectors
122+
function eig(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true) where T
123+
AA = copy_oftype(A, eigtype(T))
124+
isdiag(AA) && return eig(Diagonal(AA), permute = permute, scale = scale)
125+
return eigfact!(AA, permute = permute, scale = scale)
140126
end
127+
eig(x::Number) = Eigen([x], fill(one(x), 1, 1))
141128

142129
"""
143130
eigvecs(A; permute::Bool=true, scale::Bool=true) -> Matrix
144131
145132
Return a matrix `M` whose columns are the eigenvectors of `A`. (The `k`th eigenvector can
146133
be obtained from the slice `M[:, k]`.) The `permute` and `scale` keywords are the same as
147-
for [`eigfact`](@ref).
134+
for [`eig`](@ref).
148135
149136
# Examples
150137
```jldoctest
@@ -156,7 +143,7 @@ julia> eigvecs([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
156143
```
157144
"""
158145
eigvecs(A::Union{Number, AbstractMatrix}; permute::Bool=true, scale::Bool=true) =
159-
eigvecs(eigfact(A, permute=permute, scale=scale))
146+
eigvecs(eig(A, permute=permute, scale=scale))
160147
eigvecs(F::Union{Eigen, GeneralizedEigen}) = F.vectors
161148

162149
eigvals(F::Union{Eigen, GeneralizedEigen}) = F.values
@@ -351,13 +338,15 @@ function eigfact!(A::StridedMatrix{T}, B::StridedMatrix{T}) where T<:BlasComplex
351338
end
352339

353340
"""
354-
eigfact(A, B) -> GeneralizedEigen
341+
eig(A, B) -> GeneralizedEigen
355342
356343
Computes the generalized eigenvalue decomposition of `A` and `B`, returning a
357344
`GeneralizedEigen` factorization object `F` which contains the generalized eigenvalues in
358345
`F.values` and the generalized eigenvectors in the columns of the matrix `F.vectors`.
359346
(The `k`th generalized eigenvector can be obtained from the slice `F.vectors[:, k]`.)
360347
348+
Iterating the decomposition produces the components `F.values` and `F.vectors`.
349+
361350
# Examples
362351
```jldoctest
363352
julia> A = [1 0; 0 -1]
@@ -370,7 +359,7 @@ julia> B = [0 1; 1 0]
370359
0 1
371360
1 0
372361
373-
julia> F = eigfact(A, B);
362+
julia> F = eig(A, B);
374363
375364
julia> F.values
376365
2-element Array{Complex{Float64},1}:
@@ -381,47 +370,19 @@ julia> F.vectors
381370
2×2 Array{Complex{Float64},2}:
382371
0.0-1.0im 0.0+1.0im
383372
-1.0-0.0im -1.0+0.0im
373+
374+
julia> vals, vecs = F; # destructuring via iteration
375+
376+
julia> vals == F.values && vecs == F.vectors
377+
true
384378
```
385379
"""
386-
function eigfact(A::AbstractMatrix{TA}, B::AbstractMatrix{TB}) where {TA,TB}
380+
function eig(A::AbstractMatrix{TA}, B::AbstractMatrix{TB}) where {TA,TB}
387381
S = promote_type(eigtype(TA),TB)
388382
return eigfact!(copy_oftype(A, S), copy_oftype(B, S))
389383
end
390384

391-
eigfact(A::Number, B::Number) = eigfact(fill(A,1,1), fill(B,1,1))
392-
393-
"""
394-
eig(A, B) -> D, V
395-
396-
Computes generalized eigenvalues (`D`) and vectors (`V`) of `A` with respect to `B`.
397-
398-
`eig` is a wrapper around [`eigfact`](@ref), extracting all parts of the
399-
factorization to a tuple; where possible, using [`eigfact`](@ref) is recommended.
400-
401-
# Examples
402-
```jldoctest
403-
julia> A = [1 0; 0 -1]
404-
2×2 Array{Int64,2}:
405-
1 0
406-
0 -1
407-
408-
julia> B = [0 1; 1 0]
409-
2×2 Array{Int64,2}:
410-
0 1
411-
1 0
412-
413-
julia> eig(A, B)
414-
(Complex{Float64}[0.0+1.0im, 0.0-1.0im], Complex{Float64}[0.0-1.0im 0.0+1.0im; -1.0-0.0im -1.0+0.0im])
415-
```
416-
"""
417-
function eig(A::AbstractMatrix, B::AbstractMatrix)
418-
F = eigfact(A,B)
419-
F.values, F.vectors
420-
end
421-
function eig(A::Number, B::Number)
422-
F = eigfact(A,B)
423-
F.values, F.vectors
424-
end
385+
eig(A::Number, B::Number) = eig(fill(A,1,1), fill(B,1,1))
425386

426387
"""
427388
eigvals!(A, B) -> values
@@ -524,7 +485,7 @@ julia> eigvecs(A, B)
524485
-1.0-0.0im -1.0+0.0im
525486
```
526487
"""
527-
eigvecs(A::AbstractMatrix, B::AbstractMatrix) = eigvecs(eigfact(A, B))
488+
eigvecs(A::AbstractMatrix, B::AbstractMatrix) = eigvecs(eig(A, B))
528489

529490
function show(io::IO, mime::MIME{Symbol("text/plain")}, F::Union{Eigen,GeneralizedEigen})
530491
println(io, summary(F))

0 commit comments

Comments
 (0)