-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: add ordschur function to base/linalg #8467
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -666,6 +666,8 @@ export | |
lyap, | ||
norm, | ||
null, | ||
ordschur!, | ||
ordschur, | ||
peakflops, | ||
pinv, | ||
qr, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,8 @@ export | |
lyap, | ||
norm, | ||
null, | ||
ordschur!, | ||
ordschur, | ||
peakflops, | ||
pinv, | ||
qr, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3508,6 +3508,104 @@ for (gees, gges, elty, relty) in | |
end | ||
end | ||
end | ||
# Reorder Schur forms | ||
for (trsen, elty) in | ||
((:dtrsen_,:Float64), | ||
(:strsen_,:Float32)) | ||
@eval begin | ||
function trsen!(select::Array{Int}, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty}) | ||
# * .. Scalar Arguments .. | ||
# CHARACTER COMPQ, JOB | ||
# INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N | ||
# DOUBLE PRECISION S, SEP | ||
# * .. | ||
# * .. Array Arguments .. | ||
# LOGICAL SELECT( * ) | ||
# INTEGER IWORK( * ) | ||
# DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ), WR( * ) | ||
chkstride1(T, Q) | ||
n = chksquare(T) | ||
ld = max(1, n) | ||
wr = similar(T, $elty, n) | ||
wi = similar(T, $elty, n) | ||
m = sum(select) | ||
work = Array($elty, 1) | ||
lwork = blas_int(-1) | ||
iwork = Array(BlasInt, 1) | ||
liwork = blas_int(-1) | ||
info = Array(BlasInt, 1) | ||
select = convert(Array{BlasInt}, select) | ||
|
||
for i = 1:2 | ||
ccall(($(string(trsen)), liblapack), Void, | ||
(Ptr{BlasChar}, Ptr{BlasChar}, Ptr{BlasInt}, Ptr{BlasInt}, | ||
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, | ||
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{Void}, Ptr{Void}, | ||
Ptr{$elty}, Ptr {BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}, | ||
Ptr{BlasInt}), | ||
&'N', &'V', select, &n, | ||
T, &ld, Q, &ld, | ||
wr, wi, &m, C_NULL, C_NULL, | ||
work, &lwork, iwork, &liwork, | ||
info) | ||
@lapackerror | ||
if i == 1 # only estimated optimal lwork, liwork | ||
lwork = blas_int(real(work[1])) | ||
liwork = blas_int(real(iwork[1])) | ||
work = Array($elty, lwork) | ||
iwork = Array(BlasInt, liwork) | ||
end | ||
end | ||
T, Q, all(wi .== 0) ? wr : complex(wr, wi) | ||
end | ||
end | ||
end | ||
|
||
for (trsen, elty) in | ||
((:ztrsen_,:Complex128), | ||
(:ctrsen_,:Complex64)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here follows the complex definition which is basically the same with a ccall just to w instead of wr, wi and no iwork, liwork arguments. is there a way to metaprogramm this nicely, inserting the specific "wr, wi, " in one case and "w" in the other case to the ccall with no duplicate code? |
||
@eval begin | ||
function trsen!(select::Array{Int}, T::StridedMatrix{$elty}, Q::StridedMatrix{$elty}) | ||
# * .. Scalar Arguments .. | ||
# CHARACTER COMPQ, JOB | ||
# INTEGER INFO, LDQ, LDT, LWORK, M, N | ||
# DOUBLE PRECISION S, SEP | ||
# * .. | ||
# * .. Array Arguments .. | ||
# LOGICAL SELECT( * ) | ||
# COMPLEX Q( LDQ, * ), T( LDT, * ), W( * ), WORK( * ) | ||
chkstride1(T, Q) | ||
n = chksquare(T) | ||
ld = max(1, n) | ||
w = similar(T, $elty, n) | ||
m = sum(select) | ||
work = Array($elty, 1) | ||
lwork = blas_int(-1) | ||
info = Array(BlasInt, 1) | ||
select = convert(Array{BlasInt}, select) | ||
|
||
for i = 1:2 | ||
ccall(($(string(trsen)), liblapack), Void, | ||
(Ptr{BlasChar}, Ptr{BlasChar}, Ptr{BlasInt}, Ptr{BlasInt}, | ||
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, | ||
Ptr{$elty}, Ptr{BlasInt}, Ptr{Void}, Ptr{Void}, | ||
Ptr{$elty}, Ptr {BlasInt}, | ||
Ptr{BlasInt}), | ||
&'N', &'V', select, &n, | ||
T, &ld, Q, &ld, | ||
w, &m, C_NULL, C_NULL, | ||
work, &lwork, | ||
info) | ||
@lapackerror | ||
if i == 1 # only estimated optimal lwork, liwork | ||
lwork = blas_int(real(work[1])) | ||
work = Array($elty, lwork) | ||
end | ||
end | ||
T, Q, w | ||
end | ||
end | ||
end | ||
|
||
### Rectangular full packed format | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok leaving this a one-liner?