From a41b8c2ceee86b4fe5524f5c6649e7d8d0c4a11d Mon Sep 17 00:00:00 2001 From: Benjamin Born Date: Tue, 17 Jul 2018 21:54:44 +0200 Subject: [PATCH 1/3] Deprecate ordschur methods --- stdlib/LinearAlgebra/src/deprecated.jl | 33 +++++++++++++++++++ stdlib/LinearAlgebra/src/schur.jl | 44 -------------------------- 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/stdlib/LinearAlgebra/src/deprecated.jl b/stdlib/LinearAlgebra/src/deprecated.jl index 21602582d1d48..8f1452388385b 100644 --- a/stdlib/LinearAlgebra/src/deprecated.jl +++ b/stdlib/LinearAlgebra/src/deprecated.jl @@ -1593,3 +1593,36 @@ function Base.getindex(S::GeneralizedSVD, i::Integer) i == 6 ? (return S.R0) : throw(BoundsError(S, i)) end + +# deprecate two ordschur methods where the individual components are passed instead of +# the factorization + +function ordschur!(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} + depwarn(string("`ordschur!(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector})`", + "`where {Ty<:BlasFloat}` is deprecated, use `ordschur!(schur::Schur, select::Union{Vector{Bool},BitVector})`", "instead."), :ordschur!) + return LinearAlgebra.LAPACK.trsen!(convert(Vector{BlasInt}, select), T, Z)[1:3] +end + +function ordschur(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} + depwarn(string("`ordschur!(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector})`", + "`where {Ty<:BlasFloat}` is deprecated, use `ordschur(schur::Schur, select::Union{Vector{Bool},BitVector})`", "instead."), :ordschur) + return ordschur!(copy(T), copy(Z), select) +end + +function ordschur!(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, + Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} + depwarn(string("`ordschur!(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty},`", + "`Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat}`", + "is deprecated, use `ordschur!(gschur::GeneralizedSchur, select::Union{Vector{Bool},BitVector})`", + "instead."), :ordschur!) + return LinearAlgebra.LAPACK.tgsen!(convert(Vector{BlasInt}, select), S, T, Q, Z) +end + +function ordschur(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, + Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} + depwarn(string("`ordschur(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty},`", + "`Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat}`", + "is deprecated, use `ordschur(gschur::GeneralizedSchur, select::Union{Vector{Bool},BitVector})`", + "instead."), :ordschur) + return ordschur!(copy(S), copy(T), copy(Q), copy(Z), select) +end diff --git a/stdlib/LinearAlgebra/src/schur.jl b/stdlib/LinearAlgebra/src/schur.jl index c1b848c5408e5..fd66655d6f786 100644 --- a/stdlib/LinearAlgebra/src/schur.jl +++ b/stdlib/LinearAlgebra/src/schur.jl @@ -149,27 +149,6 @@ included or both excluded via `select`. ordschur(schur::Schur, select::Union{Vector{Bool},BitVector}) = Schur(ordschur(schur.T, schur.Z, select)...) -""" - ordschur!(T::StridedMatrix, Z::StridedMatrix, select::Union{Vector{Bool},BitVector}) -> T::StridedMatrix, Z::StridedMatrix, λ::Vector - -Same as [`ordschur`](@ref) but overwrites the input arguments. -""" -ordschur!(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = - LinearAlgebra.LAPACK.trsen!(convert(Vector{BlasInt}, select), T, Z)[1:3] - -""" - ordschur(T::StridedMatrix, Z::StridedMatrix, select::Union{Vector{Bool},BitVector}) -> T::StridedMatrix, Z::StridedMatrix, λ::Vector - -Reorders the Schur factorization of a real matrix `A = Z*T*Z'` according to the logical -array `select` returning the reordered matrices `T` and `Z` as well as the vector of -eigenvalues `λ`. The selected eigenvalues appear in the leading diagonal of `T` and the -corresponding leading columns of `Z` form an orthogonal/unitary basis of the corresponding -right invariant subspace. In the real case, a complex conjugate pair of eigenvalues must be -either both included or both excluded via `select`. -""" -ordschur(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = - ordschur!(copy(T), copy(Z), select) - struct GeneralizedSchur{Ty,M<:AbstractMatrix} <: Factorization{Ty} S::M T::M @@ -248,29 +227,6 @@ and `B` can still be obtained with `F.α./F.β`. ordschur(gschur::GeneralizedSchur, select::Union{Vector{Bool},BitVector}) = GeneralizedSchur(ordschur(gschur.S, gschur.T, gschur.Q, gschur.Z, select)...) -""" - ordschur!(S::StridedMatrix, T::StridedMatrix, Q::StridedMatrix, Z::StridedMatrix, select) -> S::StridedMatrix, T::StridedMatrix, Q::StridedMatrix, Z::StridedMatrix, α::Vector, β::Vector - -Same as [`ordschur`](@ref) but overwrites the factorization the input arguments. -""" -ordschur!(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, - Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = - LinearAlgebra.LAPACK.tgsen!(convert(Vector{BlasInt}, select), S, T, Q, Z) - -""" - ordschur(S::StridedMatrix, T::StridedMatrix, Q::StridedMatrix, Z::StridedMatrix, select) -> S::StridedMatrix, T::StridedMatrix, Q::StridedMatrix, Z::StridedMatrix, α::Vector, β::Vector - -Reorders the Generalized Schur factorization of a matrix pair `(A, B) = (Q*S*Z', Q*T*Z')` -according to the logical array `select` and returns the matrices `S`, `T`, `Q`, `Z` and -vectors `α` and `β`. The selected eigenvalues appear in the leading diagonal of both `S` -and `T`, and the left and right unitary/orthogonal Schur vectors are also reordered such -that `(A, B) = Q*(S, T)*Z'` still holds and the generalized eigenvalues of `A` and `B` can -still be obtained with `α./β`. -""" -ordschur(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, - Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = - ordschur!(copy(S), copy(T), copy(Q), copy(Z), select) - function getproperty(F::GeneralizedSchur, d::Symbol) if d == :values return getfield(F, :α) ./ getfield(F, :β) From bfa981b10e088b8b1a62d6a608c14db600afc247 Mon Sep 17 00:00:00 2001 From: Benjamin Born Date: Wed, 18 Jul 2018 10:33:38 +0200 Subject: [PATCH 2/3] Add news item --- NEWS.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS.md b/NEWS.md index c6fe261d7d238..f655d739f19e2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -782,6 +782,14 @@ Deprecated or removed (`vals, vecs = eigen(A, B)`), or as a `GeneralizedEigen` object (`X = eigen(A, B)`) ([#26997], [#27159], [#27212]). + * `ordschur(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector})` + and `ordschur(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, + Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector})` and their respective + inplace versions have been deprecated. + Use `ordschur(schur::Schur, select::Union{Vector{Bool},BitVector})` and + `ordschur(gschur::GeneralizedSchur, select::Union{Vector{Bool},BitVector})` instead + ([#28155]). + * Indexing into multidimensional arrays with more than one index but fewer indices than there are dimensions is no longer permitted when those trailing dimensions have lengths greater than 1. Instead, reshape the array or add trailing indices so the dimensionality and number of indices From 651b42367ec0219a603f56b4aa3c2d94548cdbcb Mon Sep 17 00:00:00 2001 From: Benjamin Born Date: Thu, 26 Jul 2018 20:32:18 +0200 Subject: [PATCH 3/3] Add auxiliary _ordschur and _ordschur! functions --- stdlib/LinearAlgebra/src/schur.jl | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/stdlib/LinearAlgebra/src/schur.jl b/stdlib/LinearAlgebra/src/schur.jl index fd66655d6f786..2139118cd0ca7 100644 --- a/stdlib/LinearAlgebra/src/schur.jl +++ b/stdlib/LinearAlgebra/src/schur.jl @@ -131,11 +131,17 @@ end Same as [`ordschur`](@ref) but overwrites the factorization `F`. """ function ordschur!(schur::Schur, select::Union{Vector{Bool},BitVector}) - _, _, vals = ordschur!(schur.T, schur.Z, select) + _, _, vals = _ordschur!(schur.T, schur.Z, select) schur.values[:] = vals return schur end +_ordschur(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = + _ordschur!(copy(T), copy(Z), select) + +_ordschur!(T::StridedMatrix{Ty}, Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = + LinearAlgebra.LAPACK.trsen!(convert(Vector{BlasInt}, select), T, Z)[1:3] + """ ordschur(F::Schur, select::Union{Vector{Bool},BitVector}) -> F::Schur @@ -147,7 +153,7 @@ subspace. In the real case, a complex conjugate pair of eigenvalues must be eith included or both excluded via `select`. """ ordschur(schur::Schur, select::Union{Vector{Bool},BitVector}) = - Schur(ordschur(schur.T, schur.Z, select)...) + Schur(_ordschur(schur.T, schur.Z, select)...) struct GeneralizedSchur{Ty,M<:AbstractMatrix} <: Factorization{Ty} S::M @@ -208,12 +214,20 @@ end Same as `ordschur` but overwrites the factorization `F`. """ function ordschur!(gschur::GeneralizedSchur, select::Union{Vector{Bool},BitVector}) - _, _, α, β, _, _ = ordschur!(gschur.S, gschur.T, gschur.Q, gschur.Z, select) + _, _, α, β, _, _ = _ordschur!(gschur.S, gschur.T, gschur.Q, gschur.Z, select) gschur.α[:] = α gschur.β[:] = β return gschur end +_ordschur(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, + Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = + _ordschur!(copy(S), copy(T), copy(Q), copy(Z), select) + +_ordschur!(S::StridedMatrix{Ty}, T::StridedMatrix{Ty}, Q::StridedMatrix{Ty}, + Z::StridedMatrix{Ty}, select::Union{Vector{Bool},BitVector}) where {Ty<:BlasFloat} = + LinearAlgebra.LAPACK.tgsen!(convert(Vector{BlasInt}, select), S, T, Q, Z) + """ ordschur(F::GeneralizedSchur, select::Union{Vector{Bool},BitVector}) -> F::GeneralizedSchur @@ -225,7 +239,7 @@ left and right orthogonal/unitary Schur vectors are also reordered such that and `B` can still be obtained with `F.α./F.β`. """ ordschur(gschur::GeneralizedSchur, select::Union{Vector{Bool},BitVector}) = - GeneralizedSchur(ordschur(gschur.S, gschur.T, gschur.Q, gschur.Z, select)...) + GeneralizedSchur(_ordschur(gschur.S, gschur.T, gschur.Q, gschur.Z, select)...) function getproperty(F::GeneralizedSchur, d::Symbol) if d == :values