1
1
using Printf
2
2
using LinearAlgebra
3
- using LinearAlgebra: Givens, Rotation
4
-
5
- # Auxiliary
6
- function adiagmax (A:: StridedMatrix )
7
- adm = zero (typeof (real (A[1 ])))
8
- @inbounds begin
9
- for i in size (A, 1 )
10
- adm = max (adm, abs (A[i, i]))
11
- end
12
- end
13
- return adm
14
- end
3
+ using LinearAlgebra: Givens, Rotation, givens
4
+
5
+ import Base: \
15
6
16
7
# Hessenberg Matrix
17
8
struct HessenbergMatrix{T,S<: StridedMatrix } <: AbstractMatrix{T}
@@ -30,19 +21,23 @@ function LinearAlgebra.ldiv!(H::HessenbergMatrix, B::AbstractVecOrMat)
30
21
n = size (H, 1 )
31
22
Hd = H. data
32
23
for i = 1 : n- 1
33
- G, _ = givens! (Hd, i, i + 1 , i)
34
- lmul! (G, view (Hd, 1 : n, i+ 1 : n))
24
+ G, _ = givens (Hd, i, i + 1 , i)
25
+ lmul! (G, view (Hd, 1 : n, i: n))
35
26
lmul! (G, B)
36
27
end
37
- ldiv! (Triangular (Hd, :U ), B)
28
+ ldiv! (UpperTriangular (Hd), B)
38
29
end
30
+ (\ )(H:: HessenbergMatrix , B:: AbstractVecOrMat ) = ldiv! (copy (H), copy (B))
39
31
40
32
# Hessenberg factorization
41
33
struct HessenbergFactorization{T,S<: StridedMatrix ,U} <: Factorization{T}
42
34
data:: S
43
35
τ:: Vector{U}
44
36
end
45
37
38
+ Base. copy (HF:: HessenbergFactorization{T,S,U} ) where {T,S,U} =
39
+ HessenbergFactorization {T,S,U} (copy (HF. data), copy (HF. τ))
40
+
46
41
function _hessenberg! (A:: StridedMatrix{T} ) where {T}
47
42
n = LinearAlgebra. checksquare (A)
48
43
τ = Vector {Householder{T}} (undef, n - 1 )
@@ -60,6 +55,14 @@ LinearAlgebra.hessenberg!(A::StridedMatrix) = _hessenberg!(A)
60
55
61
56
Base. size (H:: HessenbergFactorization , args... ) = size (H. data, args... )
62
57
58
+ function Base. getproperty (F:: HessenbergFactorization , s:: Symbol )
59
+ if s === :H
60
+ return HessenbergMatrix {eltype(F.data),typeof(F.data)} (F. data)
61
+ else
62
+ return getfield (F, s)
63
+ end
64
+ end
65
+
63
66
# Schur
64
67
struct Schur{T,S<: StridedMatrix } <: Factorization{T}
65
68
data:: S
@@ -74,19 +77,12 @@ function Base.getproperty(F::Schur, s::Symbol)
74
77
end
75
78
end
76
79
77
- function wilkinson (Hmm, t, d)
78
- λ1 = (t + sqrt (t * t - 4 d)) / 2
79
- λ2 = (t - sqrt (t * t - 4 d)) / 2
80
- return ifelse (abs (Hmm - λ1) < abs (Hmm - λ2), λ1, λ2)
81
- end
82
-
83
80
# We currently absorb extra unsupported keywords in kwargs. These could e.g. be scale and permute. Do we want to check that these are false?
84
81
function _schur! (
85
82
H:: HessenbergFactorization{T} ;
86
83
tol = eps (real (T)),
87
84
shiftmethod = :Francis ,
88
85
maxiter = 30 * size (H, 1 ),
89
- kwargs... ,
90
86
) where {T}
91
87
92
88
n = size (H, 1 )
@@ -176,6 +172,8 @@ function _schur!(
176
172
return Schur {T,typeof(HH)} (HH, τ)
177
173
end
178
174
_schur! (A:: StridedMatrix ; kwargs... ) = _schur! (_hessenberg! (A); kwargs... )
175
+
176
+ # FIXME ! Move this method to piracy extension
179
177
LinearAlgebra. schur! (A:: StridedMatrix ; kwargs... ) = _schur! (A; kwargs... )
180
178
181
179
function singleShiftQR! (
0 commit comments