-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy patheigenSelfAdjoint.jl
676 lines (600 loc) · 19.8 KB
/
eigenSelfAdjoint.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
using Printf
using LinearAlgebra
using LinearAlgebra: givensAlgorithm
struct SymmetricTridiagonalFactorization{T} <: Factorization{T}
uplo::Char
factors::Matrix{T}
τ::Vector{T}
diagonals::SymTridiagonal
end
Base.size(S::SymmetricTridiagonalFactorization, i::Integer) = size(S.factors, i)
struct EigenQ{T} <: AbstractMatrix{T}
uplo::Char
factors::Matrix{T}
τ::Vector{T}
end
function Base.getproperty(S::SymmetricTridiagonalFactorization, s::Symbol)
if s == :Q
return EigenQ(S.uplo, S.factors, S.τ)
else
return getfield(S, s)
end
end
Base.size(Q::EigenQ) = (size(Q.factors, 1), size(Q.factors, 1))
function Base.size(Q::EigenQ, i::Integer)
if i < 1
throw(ArgumentError(""))
elseif i < 3
return size(Q.factors, 1)
else
return 1
end
end
function LinearAlgebra.lmul!(Q::EigenQ, B::StridedVecOrMat)
m, n = size(B)
if size(Q, 1) != m
throw(DimensionMismatch(""))
end
if Q.uplo == 'L'
for k = length(Q.τ):-1:1
for j = 1:size(B, 2)
b = view(B, :, j)
vb = B[k+1, j]
for i = (k+2):m
vb += Q.factors[i, k]'B[i, j]
end
τkvb = Q.τ[k]'vb
B[k+1, j] -= τkvb
for i = (k+2):m
B[i, j] -= Q.factors[i, k] * τkvb
end
end
end
elseif Q.uplo == 'U'
for k = length(Q.τ):-1:1
for j = 1:size(B, 2)
b = view(B, :, j)
vb = B[k+1, j]
for i = (k+2):m
vb += Q.factors[k, i] * B[i, j]
end
τkvb = Q.τ[k]'vb
B[k+1, j] -= τkvb
for i = (k+2):m
B[i, j] -= Q.factors[k, i]' * τkvb
end
end
end
else
throw(ArgumentError("Q.uplo is neither 'L' or 'U'. This should never happen."))
end
return B
end
function LinearAlgebra.rmul!(A::StridedMatrix, Q::EigenQ)
m, n = size(A)
if size(Q, 1) != n
throw(DimensionMismatch(""))
end
if Q.uplo == 'L'
for k = 1:length(Q.τ)
for i = 1:size(A, 1)
a = view(A, i, :)
va = A[i, k+1]
for j = (k+2):n
va += A[i, j] * Q.factors[j, k]
end
τkva = va * Q.τ[k]'
A[i, k+1] -= τkva
for j = (k+2):n
A[i, j] -= τkva * Q.factors[j, k]'
end
end
end
elseif Q.uplo == 'U' # FixMe! Should consider reordering loops
for k = 1:length(Q.τ)
for i = 1:size(A, 1)
a = view(A, i, :)
va = A[i, k+1]
for j = (k+2):n
va += A[i, j] * Q.factors[k, j]'
end
τkva = va * Q.τ[k]'
A[i, k+1] -= τkva
for j = (k+2):n
A[i, j] -= τkva * Q.factors[k, j]
end
end
end
else
throw(ArgumentError("Q.uplo is neither 'L' or 'U'. This should never happen."))
end
return A
end
Base.Array(Q::EigenQ) = lmul!(Q, Matrix{eltype(Q)}(I, size(Q, 1), size(Q, 1)))
function _updateVectors!(c, s, j, vectors)
@inbounds for i = 1:size(vectors, 1)
v1 = vectors[i, j+1]
v2 = vectors[i, j]
vectors[i, j+1] = c * v1 + s * v2
vectors[i, j] = c * v2 - s * v1
end
end
function eigvals2x2(d1::Number, d2::Number, e::Number)
r1 = (d1 + d2) / 2
r2 = hypot(d1 - d2, 2 * e) / 2
return r1 + r2, r1 - r2
end
function eig2x2!(d::StridedVector, e::StridedVector, j::Integer, vectors::Matrix)
dj = d[j]
dj1 = d[j + 1]
ej = e[j]
r1 = (dj + dj1) / 2
r2 = hypot(dj - dj1, 2 * ej) / 2
λ⁺ = r1 + r2
λ⁻ = r1 - r2
d[j] = λ⁺
d[j + 1] = λ⁻
e[j] = 0
if iszero(ej)
c = one(λ⁺)
s = zero(λ⁺)
elseif abs(λ⁺ - dj) > abs(λ⁻ - dj)
c = -ej / hypot(ej, λ⁺ - dj)
s = sqrt(1 - c*c)
else
s = abs(ej) / hypot(ej, λ⁻ - dj)
c = copysign(sqrt(1 - s*s), -ej)
end
_updateVectors!(c, s, j, vectors)
return c, s
end
function eigvalsPWK!(S::SymTridiagonal{T}; tol = eps(T), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) where {T<:Real}
d = S.dv
e = S.ev
n = length(d)
blockstart = 1
blockend = n
iter = 0
@inbounds begin
for i = 1:n-1
e[i] = abs2(e[i])
end
while true
# Check for zero off diagonal elements
for be = (blockstart + 1):n
if abs(e[be - 1]) <= tol * sqrt(abs(d[be - 1])) * sqrt(abs(d[be]))
blockend = be - 1
break
end
blockend = n
end
@debug "submatrix" blockstart blockend
# Deflate?
if blockstart == blockend
@debug "Deflate? Yes!"
blockstart += 1
elseif blockstart + 1 == blockend
@debug "Defalte? Yes, but after solving 2x2 block!"
d[blockstart], d[blockend] =
eigvals2x2(d[blockstart], d[blockend], sqrt(e[blockstart]))
e[blockstart] = zero(T)
blockstart += 1
else
@debug "Deflate? No!"
# Calculate shift
sqrte = sqrt(e[blockstart])
μ = (d[blockstart+1] - d[blockstart]) / (2 * sqrte)
r = hypot(μ, one(T))
μ = d[blockstart] - sqrte / (μ + copysign(r, μ))
# QL bulk chase
@debug "Values before PWK QL bulge chase" e[blockstart] e[blockend-1] μ
singleShiftQLPWK!(S, μ, blockstart, blockend)
rotations = blockend - blockstart
iter += rotations
@debug "Values after PWK QL bulge chase" e[blockstart] e[blockend-1] rotations
end
if blockstart >= n
break
end
end
end
# LinearAlgebra.eigvals will pass sortby=nothing but LAPACK always sort the symmetric
# eigenvalue problem so we'll will do the same here
LinearAlgebra.sorteig!(d, sortby === nothing ? LinearAlgebra.eigsortby : sortby)
end
function eigQL!(
S::SymTridiagonal{T};
vectors::Matrix = zeros(T, 0, size(S, 1)),
tol = eps(T),
) where {T<:Real}
d = S.dv
e = S.ev
n = length(d)
if size(vectors, 2) != n
throw(
DimensionMismatch(
"eigenvector matrix must have $(n) columns but had $(size(vectors, 2))",
),
)
end
if size(vectors, 1) > n
throw(
DimensionMismatch(
"eigenvector matrix must have at most $(n) rows but had $(size(vectors, 1))",
),
)
end
blockstart = 1
blockend = n
@inbounds begin
while true
# Check for zero off diagonal elements
for be = (blockstart + 1):n
if abs(e[be - 1]) <= tol * sqrt(abs(d[be - 1])) * sqrt(abs(d[be]))
blockend = be - 1
break
end
blockend = n
end
@debug "submatrix" blockstart blockend
# Deflate?
if blockstart == blockend
@debug "Deflate? Yes!"
blockstart += 1
elseif blockstart + 1 == blockend
@debug "Deflate? Yes, but after solving 2x2 block"
eig2x2!(d, e, blockstart, vectors)
blockstart += 2
else
@debug "Deflate? No!"
# Calculate shift
μ = (d[blockstart + 1] - d[blockstart]) / (2 * e[blockstart])
r = hypot(μ, one(T))
μ = d[blockstart] - (e[blockstart] / (μ + copysign(r, μ)))
# QL bulk chase
@debug "Values before bulge chase" e[blockstart] e[blockend - 1] d[blockstart] μ
singleShiftQL!(S, μ, blockstart, blockend, vectors)
@debug "Values after bulge chase" e[blockstart] e[blockend - 1] d[blockstart]
end
if blockstart >= n
break
end
end
end
p = sortperm(d)
return d[p], vectors[:, p]
end
function eigQR!(
S::SymTridiagonal{T};
vectors::Matrix = zeros(T, 0, size(S, 1)),
tol = eps(T),
) where {T<:Real}
d = S.dv
e = S.ev
n = length(d)
blockstart = 1
blockend = n
@inbounds begin
while true
# Check for zero off diagonal elements
for be = (blockstart + 1):n
if abs(e[be - 1]) <= tol * sqrt(abs(d[be - 1])) * sqrt(abs(d[be]))
blockend = be - 1
break
end
blockend = n
end
@debug "submatrix" blockstart blockend
# Deflate?
if blockstart == blockend
@debug "Deflate? Yes!"
blockstart += 1
elseif blockstart + 1 == blockend
@debug "Deflate? Yes, but after solving 2x2 block!"
eig2x2!(d, e, blockstart, vectors)
blockstart += 2
else
@debug "Deflate? No!"
# Calculate shift
μ = (d[blockend - 1] - d[blockend]) / (2 * e[blockend - 1])
r = hypot(μ, one(T))
μ = d[blockend] - (e[blockend - 1] / (μ + copysign(r, μ)))
# QR bulk chase
@debug "Values before QR bulge chase" e[blockstart] e[blockend - 1] d[blockend] μ
singleShiftQR!(S, μ, blockstart, blockend, vectors)
@debug "Values after QR bulge chase" e[blockstart] e[blockend - 1] d[blockend]
end
if blockstart >= n
break
end
end
end
p = sortperm(d)
return d[p], vectors[:, p]
end
# Own implementation based on Parlett's book
function singleShiftQLPWK!(
S::SymTridiagonal,
shift::Number,
istart::Integer = 1,
iend::Integer = length(S.dv),
)
d = S.dv
e = S.ev
n = length(d)
γi = d[iend] - shift
π = abs2(γi)
ci = one(eltype(S))
s = zero(eltype(S))
@inbounds for i = iend-1:-1:istart
ei = e[i]
ζ = π + ei
if i < iend - 1
e[i+1] = s * ζ
end
ci1 = ci
ci = π / ζ
s = ei / ζ
di = d[i]
γi1 = γi
γi = ci * (di - shift) - s * γi1
d[i+1] = γi1 + di - γi
π = ci == 0 ? ei * ci1 : γi * γi / ci
end
e[istart] = s * π
d[istart] = shift + γi
S
end
# Own implementation based on Parlett's book
function singleShiftQL!(
S::SymTridiagonal,
shift::Number,
istart::Integer = 1,
iend::Integer = length(S.dv),
vectors = zeros(eltype(S), 0, size(S, 1)),
)
d, e = S.dv, S.ev
n = length(d)
γi = d[iend] - shift
π = γi
ci, si = one(eltype(S)), zero(eltype(S))
@inbounds for i = (iend-1):-1:istart
ei = e[i]
ci1 = ci
si1 = si
ci, si, ζ = givensAlgorithm(π, ei)
if i < iend - 1
e[i+1] = si1 * ζ
end
di = d[i]
γi1 = γi
γi = ci * ci * (di - shift) - si * si * γi1
d[i+1] = γi1 + di - γi
π = ci == 0 ? -ei * ci1 : γi / ci
# update eigen vectors
_updateVectors!(ci, si, i, vectors)
end
e[istart] = si * π
d[istart] = shift + γi
S
end
# Own implementation based on Parlett's book
function singleShiftQR!(
S::SymTridiagonal,
shift::Number,
istart::Integer = 1,
iend::Integer = length(S.dv),
vectors = zeros(eltype(S), 0, size(S, 1)),
)
d, e = S.dv, S.ev
n = length(d)
γi = d[istart] - shift
π = γi
ci, si = one(eltype(S)), zero(eltype(S))
for i = (istart+1):iend
ei = e[i-1]
ci1 = ci
si1 = si
ci, si, ζ = givensAlgorithm(π, ei)
if i > istart + 1
e[i-2] = si1 * ζ
end
di = d[i]
γi1 = γi
γi = ci * ci * (di - shift) - si * si * γi1
d[i-1] = γi1 + di - γi
π = ci == 0 ? -ei * ci1 : γi / ci
# update eigen vectors
_updateVectors!(ci, -si, i - 1, vectors)
end
e[iend-1] = si * π
d[iend] = shift + γi
S
end
symtri!(A::Hermitian) = A.uplo == 'L' ? symtriLower!(A.data) : symtriUpper!(A.data)
symtri!(A::Symmetric{T}) where {T<:Real} =
A.uplo == 'L' ? symtriLower!(A.data) : symtriUpper!(A.data)
# Assume that lower triangle stores the relevant part
function symtriLower!(
AS::StridedMatrix{T},
τ = zeros(T, size(AS, 1) - 1),
u = Vector{T}(undef, size(AS, 1)),
) where {T}
n = size(AS, 1)
# We ignore any non-real components of the diagonal
@inbounds for i = 1:n
AS[i, i] = real(AS[i, i])
end
@inbounds for k = 1:(n-2+!(T <: Real))
τk = LinearAlgebra.reflector!(view(AS, (k+1):n, k))
τ[k] = τk
for i = (k+1):n
u[i] = AS[i, k+1]
end
for j = (k+2):n
ASjk = AS[j, k]
for i = j:n
u[i] += AS[i, j] * ASjk
end
end
for j = (k+1):(n-1)
tmp = zero(T)
for i = j+1:n
tmp += AS[i, j]'AS[i, k]
end
u[j] += tmp
end
vcAv = u[k+1]
for i = (k+2):n
vcAv += AS[i, k]'u[i]
end
ξτ2 = real(vcAv) * abs2(τk) / 2
u[k+1] = u[k+1] * τk - ξτ2
for i = (k+2):n
u[i] = u[i] * τk - ξτ2 * AS[i, k]
end
AS[k+1, k+1] -= 2real(u[k+1])
for i = (k+2):n
AS[i, k+1] -= u[i] + AS[i, k] * u[k+1]'
end
for j = (k+2):n
ASjk = AS[j, k]
uj = u[j]
AS[j, j] -= 2real(uj * ASjk')
for i = (j+1):n
AS[i, j] -= u[i] * ASjk' + AS[i, k] * uj'
end
end
end
SymmetricTridiagonalFactorization(
'L',
AS,
τ,
SymTridiagonal(real(diag(AS)), real(diag(AS, -1))),
)
end
# Assume that upper triangle stores the relevant part
function symtriUpper!(
AS::StridedMatrix{T},
τ = zeros(T, size(AS, 1) - 1),
u = Vector{T}(undef, size(AS, 1)),
) where {T}
n = LinearAlgebra.checksquare(AS)
# We ignore any non-real components of the diagonal
@inbounds for i = 1:n
AS[i, i] = real(AS[i, i])
end
@inbounds for k = 1:(n-2+!(T <: Real))
# This is a bit convoluted method to get the conjugated vector but conjugation is required for correctness of arrays of quaternions. Eventually, it should be sufficient to write vec(x') but it currently (July 10, 2018) hits a bug in LinearAlgebra
τk = LinearAlgebra.reflector!(vec(transpose(view(AS, k, (k+1):n)')))
τ[k] = τk'
for j = (k+1):n
tmp = AS[k+1, j]
for i = (k+2):j
tmp += AS[k, i] * AS[i, j]
end
for i = (j+1):n
tmp += AS[k, i] * AS[j, i]'
end
u[j] = τk' * tmp
end
vcAv = u[k+1]
for i = (k+2):n
vcAv += u[i] * AS[k, i]'
end
ξ = real(vcAv * τk)
for j = (k+1):n
ujt = u[j]
hjt = j > (k + 1) ? AS[k, j] : one(ujt)
ξhjt = ξ * hjt
for i = (k+1):(j-1)
hit = i > (k + 1) ? AS[k, i] : one(ujt)
AS[i, j] -= hit' * ujt + u[i]' * hjt - hit' * ξhjt
end
AS[j, j] -= 2 * real(hjt' * ujt) - abs2(hjt) * ξ
end
end
SymmetricTridiagonalFactorization(
'U',
AS,
τ,
SymTridiagonal(real(diag(AS)), real(diag(AS, 1))),
)
end
_eigvals!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) =
eigvalsPWK!(A.diagonals; tol, sortby)
_eigvals!(A::SymTridiagonal; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = eigvalsPWK!(A; tol, sortby)
_eigvals!(A::Hermitian; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = eigvals!(symtri!(A); tol, sortby)
LinearAlgebra.eigvals!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) =
_eigvals!(A; tol, sortby)
LinearAlgebra.eigvals!(A::SymTridiagonal; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) =
_eigvals!(A; tol, sortby)
LinearAlgebra.eigvals!(A::Hermitian; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = _eigvals!(A; tol, sortby)
_eigen!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) =
LinearAlgebra.Eigen(LinearAlgebra.sorteig!(eigQL!(A.diagonals, vectors = Array(A.Q), tol = tol)..., sortby)...)
_eigen!(A::SymTridiagonal; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = LinearAlgebra.Eigen(
eigQL!(A, vectors = Matrix{eltype(A)}(I, size(A, 1), size(A, 1)), tol = tol)...,
)
_eigen!(A::Hermitian; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = _eigen!(symtri!(A), tol = tol)
LinearAlgebra.eigen!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) =
_eigen!(A; tol, sortby)
LinearAlgebra.eigen!(A::SymTridiagonal; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = _eigen!(A; tol, sortby)
LinearAlgebra.eigen!(A::Hermitian; tol = eps(real(eltype(A))), sortby::Union{Function,Nothing}=LinearAlgebra.eigsortby) = _eigen!(A; tol, sortby)
function eigen2!(
A::SymmetricTridiagonalFactorization;
tol = eps(real(float(one(eltype(A))))),
)
V = zeros(eltype(A), 2, size(A, 1))
V[1] = 1
V[end] = 1
eigQL!(A.diagonals, vectors = rmul!(V, A.Q), tol = tol)
end
function eigen2!(A::SymTridiagonal; tol = eps(real(float(one(eltype(A))))))
V = zeros(eltype(A), 2, size(A, 1))
V[1] = 1
V[end] = 1
eigQL!(A, vectors = V, tol = tol)
end
eigen2!(A::Hermitian; tol = eps(float(real(one(eltype(A)))))) =
eigen2!(symtri!(A), tol = tol)
eigen2(A::SymTridiagonal; tol = eps(float(real(one(eltype(A)))))) =
eigen2!(copy(A), tol = tol)
eigen2(A::Hermitian, tol = eps(float(real(one(eltype(A)))))) = eigen2!(copy(A), tol = tol)
# First method of each type here is identical to the method defined in
# LinearAlgebra but is needed for disambiguation
const _eigencopy_oftype = if VERSION >= v"1.9"
LinearAlgebra.eigencopy_oftype
else
LinearAlgebra.copy_oftype
end
if VERSION < v"1.7"
function LinearAlgebra.eigvals(A::Hermitian{<:Real})
T = typeof(sqrt(zero(eltype(A))))
return eigvals!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigvals(A::Hermitian{<:Complex})
T = typeof(sqrt(zero(eltype(A))))
return eigvals!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigvals(A::Hermitian)
T = typeof(sqrt(zero(eltype(A))))
return eigvals!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Hermitian{<:Real})
T = typeof(sqrt(zero(eltype(A))))
return eigen!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Hermitian{<:Complex})
T = typeof(sqrt(zero(eltype(A))))
return eigen!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Hermitian)
T = typeof(sqrt(zero(eltype(A))))
return eigen!(_eigencopy_oftype(A, T))
end
end
# Aux (should go somewhere else at some point)
function LinearAlgebra.givensAlgorithm(f::Real, g::Real)
h = hypot(f, g)
return f / h, g / h, h
end