Skip to content

Commit eab70ea

Browse files
committed
Add wrapper for LAPACK _trexc methods (reordering of the Schur form)
1 parent 092bcf4 commit eab70ea

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

base/linalg/lapack.jl

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,10 +3855,37 @@ for (gees, gges, elty, relty) in
38553855
end
38563856
end
38573857
# Reorder Schur forms
3858-
for (trsen, tgsen, elty) in
3859-
((:dtrsen_, :dtgsen_, :Float64),
3860-
(:strsen_, :stgsen_, :Float32))
3858+
for (trexc, trsen, tgsen, elty) in
3859+
((:dtrexc_, :dtrsen_, :dtgsen_, :Float64),
3860+
(:strexc_, :strsen_, :stgsen_, :Float32))
38613861
@eval begin
3862+
trexc!(ifst::BlasInt, ilst::BlasInt, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty}) = trexc!('V', ifst, ilst, T, Q)
3863+
function trexc!(compq::Char, ifst::BlasInt, ilst::BlasInt, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty})
3864+
# * .. Scalar Arguments ..
3865+
# CHARACTER COMPQ
3866+
# INTEGER IFST, ILST, INFO, LDQ, LDT, N
3867+
# * ..
3868+
# * .. Array Arguments ..
3869+
# DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * )
3870+
chkstride1(T, Q)
3871+
n = chksquare(T)
3872+
ldt = max(1, stride(T, 2))
3873+
ldq = max(1, stride(Q, 2))
3874+
work = Array($elty, n)
3875+
info = Array(BlasInt, 1)
3876+
3877+
ccall(($(blasfunc(trexc)), liblapack), Void,
3878+
(Ptr{UInt8}, Ptr{BlasInt},
3879+
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
3880+
Ptr{BlasInt}, Ptr{BlasInt},
3881+
Ptr{$elty}, Ptr{BlasInt}),
3882+
&compq, &n,
3883+
T, &ldt, Q, &ldq,
3884+
&ifst, &ilst,
3885+
work, info)
3886+
@lapackerror
3887+
T, Q
3888+
end
38623889
function trsen!(select::StridedVector{BlasInt}, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty})
38633890
# * .. Scalar Arguments ..
38643891
# CHARACTER COMPQ, JOB
@@ -3975,10 +4002,36 @@ for (trsen, tgsen, elty) in
39754002
end
39764003
end
39774004

3978-
for (trsen, tgsen, elty) in
3979-
((:ztrsen_, :ztgsen_, :Complex128),
3980-
(:ctrsen_, :ctgsen_, :Complex64))
4005+
for (trexc, trsen, tgsen, elty) in
4006+
((:ztrexc_, :ztrsen_, :ztgsen_, :Complex128),
4007+
(:ctrexc_, :ctrsen_, :ctgsen_, :Complex64))
39814008
@eval begin
4009+
trexc!(ifst::BlasInt, ilst::BlasInt, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty}) = trexc!('V', ifst, ilst, T, Q)
4010+
function trexc!(compq::Char, ifst::BlasInt, ilst::BlasInt, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty})
4011+
# * .. Scalar Arguments ..
4012+
# CHARACTER COMPQ
4013+
# INTEGER IFST, ILST, INFO, LDQ, LDT, N
4014+
# * ..
4015+
# * .. Array Arguments ..
4016+
# DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * )
4017+
chkstride1(T, Q)
4018+
n = chksquare(T)
4019+
ldt = max(1, stride(T, 2))
4020+
ldq = max(1, stride(Q, 2))
4021+
info = Array(BlasInt, 1)
4022+
4023+
ccall(($(blasfunc(trexc)), liblapack), Void,
4024+
(Ptr{UInt8}, Ptr{BlasInt},
4025+
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
4026+
Ptr{BlasInt}, Ptr{BlasInt},
4027+
Ptr{BlasInt}),
4028+
&compq, &n,
4029+
T, &ldt, Q, &ldq,
4030+
&ifst, &ilst,
4031+
info)
4032+
@lapackerror
4033+
T, Q
4034+
end
39824035
function trsen!(select::StridedVector{BlasInt}, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty})
39834036
# * .. Scalar Arguments ..
39844037
# CHARACTER COMPQ, JOB

test/linalg/lapack.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,20 @@ for elty in (Float32, Float64, Complex64, Complex128)
427427
@test_throws DimensionMismatch LAPACK.laic1!(1,rand(elty,10),real(rand(elty)),rand(elty,11),rand(elty))
428428
end
429429

430+
#trexc
431+
for elty in (Float32, Float64, Complex64, Complex128)
432+
for c in ('V', 'N')
433+
A = convert(Matrix{elty}, [7 2 2 1; 1 5 2 0; 0 3 9 4; 1 1 1 4])
434+
T,Q,d = schur(A)
435+
Base.LinAlg.LAPACK.trexc!(c,1,2,T,Q)
436+
@test d[1] T[2,2]
437+
@test d[2] T[1,1]
438+
if (c == 'V')
439+
@test Q * T * Q' A
440+
end
441+
end
442+
end
443+
430444
# Test our own linear algebra functionaly against LAPACK
431445
for elty in (Float32, Float64, Complex{Float32}, Complex{Float64})
432446
for nn in (5,10,15)

0 commit comments

Comments
 (0)