@@ -27,5 +27,36 @@ function remove_eighgauge_dependence!(
2727 mul! (ΔV, V, gaugepart, - 1 , 1 )
2828 return ΔV
2929end
30+ function stabilize_eigvals! (D:: AbstractVector )
31+ absD = abs .(D)
32+ p = invperm (sortperm (absD)) # rank of abs(D)
33+ # account for exact degeneracies in absolute value when having complex conjugate pairs
34+ for i in 1 : (length (D) - 1 )
35+ if absD[i] == absD[i + 1 ] # conjugate pairs will appear sequentially
36+ p[p .>= p[i + 1 ]] .- = 1 # lower the rank of all higher ones
37+ end
38+ end
39+ n = maximum (p)
40+ # rescale eigenvalues so that they lie on distinct radii in the complex plane
41+ # that are chosen randomly in non-overlapping intervals [k/n, (k+0.5)/n)] for k=1,...,n
42+ radii = ((1 : n) .+ rand (real (eltype (D)), n) ./ 2 ) ./ n
43+ for i in 1 : length (D)
44+ D[i] = sign (D[i]) * radii[p[i]]
45+ end
46+ return D
47+ end
48+ function make_eig_matrix (rng, T, n)
49+ A = randn (rng, T, n, n)
50+ D, V = eig_full (A)
51+ stabilize_eigvals! (diagview (D))
52+ Ac = V * D * inv (V)
53+ return (T <: Real ) ? real (Ac) : Ac
54+ end
55+ function make_eigh_matrix (rng, T, n)
56+ A = project_hermitian! (randn (rng, T, n, n))
57+ D, V = eigh_full (A)
58+ stabilize_eigvals! (diagview (D))
59+ return project_hermitian! (V * D * V' )
60+ end
3061
3162precision (:: Type{T} ) where {T <: Number } = sqrt (eps (real (T)))
0 commit comments