Skip to content

Commit f6bfc32

Browse files
committed
Add the generalized Schur factorization and make Schur a factorization. Also fix factorizations for Number types, #2729. Remove Dense from factorization names.
1 parent 27b3f7a commit f6bfc32

File tree

7 files changed

+334
-179
lines changed

7 files changed

+334
-179
lines changed

base/exports.jl

+14-9
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,20 @@ export
105105
Stat,
106106
Factorization,
107107
BunchKaufman,
108-
CholeskyDense,
109-
CholeskyPivotedDense,
110-
EigenDense,
111-
GSVDDense,
112-
HessenbergDense,
113-
LUDense,
108+
Cholesky,
109+
CholeskyPivoted,
110+
Eigen,
111+
GeneralizedSchur,
112+
GeneralizedSVD,
113+
Hessenberg,
114+
LU,
114115
LUTridiagonal,
115116
LDLTTridiagonal,
116-
QRDense,
117-
QRPivotedDense,
118-
SVDDense,
117+
QR,
118+
QRPivoted,
119+
Schur,
120+
SVD,
121+
GeneralizedSVD,
119122
Hermitian,
120123
Triangular,
121124
Diagonal,
@@ -608,6 +611,8 @@ export
608611
rref,
609612
scale!,
610613
schur,
614+
schurfact,
615+
schurfact!,
611616
solve,
612617
svd,
613618
svdfact!,

base/linalg.jl

+13-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ export
1212
Woodbury,
1313
Factorization,
1414
BunchKaufman,
15-
CholeskyDense,
16-
CholeskyPivotedDense,
17-
EigenDense,
18-
GSVDDense,
19-
HessenbergDense,
20-
LUDense,
15+
Cholesky,
16+
CholeskyPivoted,
17+
Eigen,
18+
GeneralizedSVD,
19+
GeneralizedSchur,
20+
Hessenberg,
21+
LU,
2122
LUTridiagonal,
2223
LDLTTridiagonal,
23-
QRDense,
24-
QRPivotedDense,
25-
SVDDense,
24+
QR,
25+
QRPivoted,
26+
Schur,
27+
SVD,
2628
Hermitian,
2729
Triangular,
2830
Diagonal,
@@ -92,6 +94,8 @@ export
9294
rref,
9395
scale!,
9496
schur,
97+
schurfact!,
98+
schurfact,
9599
solve,
96100
svd,
97101
svdfact!,

base/linalg/dense.jl

+9-13
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ function sqrtm(A::StridedMatrix, cond::Bool)
382382
if ishermitian(A)
383383
return sqrtm(Hermitian(A), cond)
384384
else
385-
T,Q,_ = schur(complex(A))
386-
R = zeros(eltype(T), n, n)
385+
SchurF = schurfact!(iscomplex(A) ? copy(A) : complex(A))
386+
R = zeros(eltype(SchurF[:T]), n, n)
387387
for j = 1:n
388-
R[j,j] = sqrt(T[j,j])
388+
R[j,j] = sqrt(SchurF[:T][j,j])
389389
for i = j - 1:-1:1
390-
r = T[i,j]
390+
r = SchurF[:T][i,j]
391391
for k = i + 1:j - 1
392392
r -= R[i,k]*R[k,j]
393393
end
@@ -397,9 +397,9 @@ function sqrtm(A::StridedMatrix, cond::Bool)
397397
end
398398
end
399399
end
400-
retmat = Q*R*Q'
400+
retmat = SchurF[:vectors]*R*SchurF[:vectors]'
401401
if cond
402-
alpha = norm(R)^2/norm(T)
402+
alpha = norm(R)^2/norm(SchurF[:T])
403403
return (all(imag(retmat) .== 0) ? real(retmat) : retmat), alpha
404404
else
405405
return (all(imag(retmat) .== 0) ? real(retmat) : retmat)
@@ -428,8 +428,6 @@ function inv(A::StridedMatrix)
428428
return inv(lufact(A))
429429
end
430430

431-
schur{T<:BlasFloat}(A::StridedMatrix{T}) = LAPACK.gees!('V', copy(A))
432-
433431
function (\){T<:BlasFloat}(A::StridedMatrix{T}, B::StridedVecOrMat{T})
434432
if size(A, 1) == size(A, 2) # Square
435433
if istriu(A) return Triangular(A, 'U')\B end
@@ -477,14 +475,12 @@ function cond(A::StridedMatrix, p)
477475
if p == 2
478476
v = svdvals(A)
479477
maxv = max(v)
480-
cnd = maxv == 0.0 ? Inf : maxv / min(v)
478+
return maxv == 0.0 ? Inf : maxv / min(v)
481479
elseif p == 1 || p == Inf
482480
m, n = size(A)
483481
if m != n; error("Use 2-norm for non-square matrices"); end
484-
cnd = 1 / LAPACK.gecon!(p == 1 ? '1' : 'I', lufact(A).LU, norm(A, p))
485-
else
486-
error("Norm type must be 1, 2 or Inf")
482+
return cond(lufact(A), p)
487483
end
488-
return cnd
484+
error("Norm type must be 1, 2 or Inf")
489485
end
490486
cond(A::StridedMatrix) = cond(A, 2)

0 commit comments

Comments
 (0)