From 05bc67c57742742df3982b7112ecb963b4a3d56a Mon Sep 17 00:00:00 2001 From: st-- Date: Mon, 7 Feb 2022 15:58:21 +0100 Subject: [PATCH] improve eigvals & co docstrings (#43904) --- stdlib/LinearAlgebra/src/eigen.jl | 18 ++++++++++-------- stdlib/LinearAlgebra/src/symmetriceigen.jl | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/stdlib/LinearAlgebra/src/eigen.jl b/stdlib/LinearAlgebra/src/eigen.jl index e9b9f2b2493a3..3060f2a086942 100644 --- a/stdlib/LinearAlgebra/src/eigen.jl +++ b/stdlib/LinearAlgebra/src/eigen.jl @@ -140,7 +140,8 @@ end sorteig!(λ::AbstractVector, sortby::Union{Function,Nothing}=eigsortby) = sortby === nothing ? λ : sort!(λ, by=sortby) """ - eigen!(A, [B]; permute, scale, sortby) + eigen!(A; permute, scale, sortby) + eigen!(A, B; sortby) Same as [`eigen`](@ref), but saves space by overwriting the input `A` (and `B`), instead of creating a copy. @@ -179,7 +180,7 @@ end """ eigen(A; permute::Bool=true, scale::Bool=true, sortby) -> Eigen -Computes the eigenvalue decomposition of `A`, returning an [`Eigen`](@ref) factorization object `F` +Compute the eigenvalue decomposition of `A`, returning an [`Eigen`](@ref) factorization object `F` which contains the eigenvalues in `F.values` and the eigenvectors in the columns of the matrix `F.vectors`. (The `k`th eigenvector can be obtained from the slice `F.vectors[:, k]`.) @@ -316,7 +317,7 @@ Return the eigenvalues of `A`. For general non-symmetric matrices it is possible to specify how the matrix is balanced before the eigenvalue calculation. The `permute`, `scale`, and `sortby` keywords are -the same as for [`eigen!`](@ref). +the same as for [`eigen`](@ref). # Examples ```jldoctest @@ -462,17 +463,18 @@ function eigen!(A::StridedMatrix{T}, B::StridedMatrix{T}; sortby::Union{Function end """ - eigen(A, B) -> GeneralizedEigen + eigen(A, B; sortby) -> GeneralizedEigen -Computes the generalized eigenvalue decomposition of `A` and `B`, returning a +Compute the generalized eigenvalue decomposition of `A` and `B`, returning a [`GeneralizedEigen`](@ref) factorization object `F` which contains the generalized eigenvalues in `F.values` and the generalized eigenvectors in the columns of the matrix `F.vectors`. (The `k`th generalized eigenvector can be obtained from the slice `F.vectors[:, k]`.) Iterating the decomposition produces the components `F.values` and `F.vectors`. -Any keyword arguments passed to `eigen` are passed through to the lower-level -[`eigen!`](@ref) function. +By default, the eigenvalues and vectors are sorted lexicographically by `(real(λ),imag(λ))`. +A different comparison function `by(λ)` can be passed to `sortby`, or you can pass +`sortby=nothing` to leave the eigenvalues in an arbitrary order. # Examples ```jldoctest @@ -563,7 +565,7 @@ end """ eigvals(A, B) -> values -Computes the generalized eigenvalues of `A` and `B`. +Compute the generalized eigenvalues of `A` and `B`. # Examples ```jldoctest diff --git a/stdlib/LinearAlgebra/src/symmetriceigen.jl b/stdlib/LinearAlgebra/src/symmetriceigen.jl index f19ab20866923..8d90f370e06b6 100644 --- a/stdlib/LinearAlgebra/src/symmetriceigen.jl +++ b/stdlib/LinearAlgebra/src/symmetriceigen.jl @@ -16,7 +16,7 @@ eigen!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}, irange::UnitRange) """ eigen(A::Union{SymTridiagonal, Hermitian, Symmetric}, irange::UnitRange) -> Eigen -Computes the eigenvalue decomposition of `A`, returning an [`Eigen`](@ref) factorization object `F` +Compute the eigenvalue decomposition of `A`, returning an [`Eigen`](@ref) factorization object `F` which contains the eigenvalues in `F.values` and the eigenvectors in the columns of the matrix `F.vectors`. (The `k`th eigenvector can be obtained from the slice `F.vectors[:, k]`.) @@ -42,7 +42,7 @@ eigen!(A::RealHermSymComplexHerm{T,<:StridedMatrix}, vl::Real, vh::Real) where { """ eigen(A::Union{SymTridiagonal, Hermitian, Symmetric}, vl::Real, vu::Real) -> Eigen -Computes the eigenvalue decomposition of `A`, returning an [`Eigen`](@ref) factorization object `F` +Compute the eigenvalue decomposition of `A`, returning an [`Eigen`](@ref) factorization object `F` which contains the eigenvalues in `F.values` and the eigenvectors in the columns of the matrix `F.vectors`. (The `k`th eigenvector can be obtained from the slice `F.vectors[:, k]`.) @@ -86,7 +86,7 @@ eigvals!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}, irange::UnitRang """ eigvals(A::Union{SymTridiagonal, Hermitian, Symmetric}, irange::UnitRange) -> values -Returns the eigenvalues of `A`. It is possible to calculate only a subset of the +Return the eigenvalues of `A`. It is possible to calculate only a subset of the eigenvalues by specifying a [`UnitRange`](@ref) `irange` covering indices of the sorted eigenvalues, e.g. the 2nd to 8th eigenvalues. @@ -127,7 +127,7 @@ eigvals!(A::RealHermSymComplexHerm{T,<:StridedMatrix}, vl::Real, vh::Real) where """ eigvals(A::Union{SymTridiagonal, Hermitian, Symmetric}, vl::Real, vu::Real) -> values -Returns the eigenvalues of `A`. It is possible to calculate only a subset of the eigenvalues +Return the eigenvalues of `A`. It is possible to calculate only a subset of the eigenvalues by specifying a pair `vl` and `vu` for the lower and upper boundaries of the eigenvalues. # Examples