Skip to content
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

Robustness enhanced #117

Merged
merged 115 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
a40b530
hessenberg merged
smataigne Aug 12, 2022
e52b307
hessenberg merged
smataigne Aug 12, 2022
241dbee
pfaffian.jl
smataigne Aug 12, 2022
2962c1c
Merge branch 'main' into smataigne2
smataigne Aug 12, 2022
505e913
pfaffian.jl
smataigne Aug 12, 2022
b30d351
Merge branch 'smataigne2' of https://github.com/smataigne/SkewLinearA…
smataigne Aug 12, 2022
99ae711
non blas type
smataigne Aug 15, 2022
0c6371d
non blas type
smataigne Aug 15, 2022
da5ba02
non blas type
smataigne Aug 15, 2022
3d3413a
non blas type
smataigne Aug 15, 2022
1bad4dd
eigen complex friendly
smataigne Aug 15, 2022
16facaf
eigen complex friendly
smataigne Aug 15, 2022
e79be1d
cholesky.jl added
smataigne Aug 15, 2022
27d50ca
Merge branch 'main' into smataigne2
smataigne Aug 15, 2022
ce25eaf
git merge fixes
smataigne Aug 15, 2022
609edd9
complex trigo
smataigne Aug 16, 2022
d4e5638
Merge https://github.com/smataigne/SkewLinearAlgebra.jl into smataigne2
smataigne Aug 16, 2022
eeda80a
Merge branch 'smataigne2' of https://github.com/smataigne/SkewLinearA…
smataigne Aug 16, 2022
05c12ef
tridiag tests added, fixed copy,conj,getindex
smataigne Aug 16, 2022
a929b56
Merge branch 'main' into smataigne2
smataigne Aug 16, 2022
424f419
complex eigen etc tridiagonal, Int32 friendly
smataigne Aug 17, 2022
7792643
Merge branch 'main' into smataigne2
smataigne Aug 17, 2022
670a48a
complex eigen etc tridiagonal, Int32 friendly
smataigne Aug 17, 2022
506d3ed
Merge branch 'smataigne2' of https://github.com/smataigne/SkewLinearA…
smataigne Aug 17, 2022
863735d
complex eigen etc tridiagonal, Int32 friendly
smataigne Aug 17, 2022
0f585f8
Fix lapackerror 22and cleaned code
smataigne Aug 17, 2022
205181e
Merge branch 'main' into smataigne2
smataigne Aug 17, 2022
3cf0891
Fix lapackerror 22and cleaned code
smataigne Aug 17, 2022
a0457dc
Merge branch 'smataigne2' of https://github.com/smataigne/SkewLinearA…
smataigne Aug 17, 2022
0e89f0f
size decreased
smataigne Aug 17, 2022
79531fc
hessenberg limit null case fixed
smataigne Aug 17, 2022
89327c6
Merge branch 'main' into smataigne2
smataigne Aug 17, 2022
b5534c9
lapack 22 friendly
smataigne Aug 17, 2022
15bb2c6
documentation
smataigne Aug 18, 2022
24d3fd2
trigo for tridiag
smataigne Aug 18, 2022
22d5189
empty
smataigne Aug 18, 2022
e0ca474
empty
smataigne Aug 18, 2022
586c7e1
Goodbye error22+little changes
smataigne Aug 18, 2022
b3f5635
Goodbye error22+little changes second chance
smataigne Aug 18, 2022
4187518
merging name change
smataigne Aug 19, 2022
5b7e167
logpfaffian+rdiv,ldiv etc for vectors, ambiguity on *,/?... stiil to fix
smataigne Aug 19, 2022
be92fd4
logpfaffian+rdiv,ldiv etc for vectors, ambiguity on *,/?... stiil to fix
smataigne Aug 19, 2022
3d82135
sincos(A)+ more tests
smataigne Aug 19, 2022
86671f4
Merge branch 'main' into smataigne2
smataigne Aug 19, 2022
3889ebb
Documenter
smataigne Aug 19, 2022
b4c7c8e
Documenter
smataigne Aug 19, 2022
1539be3
Documenter
smataigne Aug 19, 2022
32e6254
Documenter step2
smataigne Aug 19, 2022
f85f191
Documenter step 3
smataigne Aug 19, 2022
b1f53f4
Merge branch 'main' into smataigne2
smataigne Aug 19, 2022
bd10773
type stable exp file
smataigne Aug 19, 2022
c4730de
type stable exp file
smataigne Aug 19, 2022
4e085fb
Merge branch 'main' into smataigne2
smataigne Aug 19, 2022
0e06e5e
first jmatrix.jl file
smataigne Aug 19, 2022
26e6687
delete n==1 exp.jl and jmatrix.jl added
smataigne Aug 22, 2022
c586426
delete n==1 exp.jl and jmatrix.jl added
smataigne Aug 22, 2022
485d1ab
workflow fixed
smataigne Aug 22, 2022
38e55ce
Merge https://github.com/JuliaLinearAlgebra/SkewLinearAlgebra.jl into…
smataigne Aug 22, 2022
5ee1020
codecov enabled
smataigne Aug 22, 2022
5106fbb
Jmatrix enhanced and tridiag with solvers
smataigne Aug 22, 2022
104de9e
Jmatrix enhanced and tridiag with solvers
smataigne Aug 22, 2022
0bc581f
commit to pull
smataigne Aug 23, 2022
940cc4a
commit to pull
smataigne Aug 23, 2022
cce845d
commit to pull
smataigne Aug 23, 2022
5dfd460
commit to pull
smataigne Aug 23, 2022
8474693
n==1,except for tridiag
smataigne Aug 23, 2022
098ae2a
n==1,except for tridiag
smataigne Aug 23, 2022
395cc4c
n==1,except for tridiag
smataigne Aug 23, 2022
c6d49be
n==1,except for tridiag
smataigne Aug 23, 2022
05adc9e
thank you for being so patient, n==1 improved
smataigne Aug 23, 2022
3a5dd7d
some tests disabled for n==1
smataigne Aug 23, 2022
9c30342
some tests disabled for n==1
smataigne Aug 23, 2022
390f57a
cholesky fields updated
smataigne Aug 23, 2022
37a618c
skeweigen.jl
smataigne Aug 25, 2022
10a08ab
modify tol with simple/double
smataigne Aug 25, 2022
c2832dd
no d in bulge
smataigne Aug 25, 2022
b4615c3
n odd handled
smataigne Aug 25, 2022
46ebe78
working QR Algorithm
smataigne Aug 29, 2022
0e550e3
eigen for skew-symmetric
smataigne Aug 30, 2022
f8cfa0b
Merge branch 'main' into tridiag_eigen
smataigne Aug 30, 2022
1f12ce9
eigen for skew-symmetric
smataigne Aug 30, 2022
d0301be
higher iterations limit
smataigne Aug 30, 2022
96f0b79
Merge branch 'main' into tridiag_eigen
smataigne Aug 30, 2022
b0568cc
higher iterations limit
smataigne Aug 30, 2022
7dcc14b
higher iterations limit
smataigne Aug 30, 2022
f258c33
New stopping criterion
smataigne Aug 30, 2022
e152060
New stopping criterion
smataigne Aug 30, 2022
da61096
Old criterion reintegrated
smataigne Aug 30, 2022
65a2912
adaptative criterion
smataigne Sep 9, 2022
2fbc86a
adaptative criterion
smataigne Sep 9, 2022
436abdf
adaptative criterion 2
smataigne Sep 9, 2022
14b70ab
POSITIVE adaptative criterion
smataigne Sep 9, 2022
46384bc
while not if
smataigne Sep 9, 2022
39d9484
n > 2 cond checked
smataigne Sep 9, 2022
ffcbc54
n > 2 cond checkedat right place
smataigne Sep 9, 2022
9f46d9f
display matrix in failing tests
smataigne Sep 9, 2022
7c81824
modified shift
smataigne Sep 9, 2022
805d672
modified shift, modified tolerance
smataigne Sep 9, 2022
68f0f2b
correct iteration limit
smataigne Sep 9, 2022
59d1277
log,tan,cot,pfaffian+tests
smataigne Sep 10, 2022
d05acf9
Merge branch 'main' into tridiag_eigen
smataigne Sep 10, 2022
ee35d9f
avoid cot with singular sin in test
smataigne Sep 10, 2022
12a8845
avoid cot with singular sin in test
smataigne Sep 10, 2022
7fa94a5
Merge branch 'tridiag_eigen' of https://github.com/JuliaLinearAlgebra…
smataigne Sep 10, 2022
d988b31
avoid cot with singular sin in test
smataigne Sep 10, 2022
65b1b67
fix codecov
smataigne Sep 13, 2022
42e62b0
delete isapproxskewhermitian
smataigne Sep 13, 2022
491acff
Merge https://github.com/JuliaLinearAlgebra/SkewLinearAlgebra.jl into…
smataigne Sep 29, 2022
58ff262
givens and criterion fixed
smataigne Sep 29, 2022
87466cb
inacurracy solved
smataigne Sep 29, 2022
4eb80cc
Merge branch 'main' into SM3
smataigne Sep 29, 2022
bab63e1
Robustness enhanced
smataigne Oct 14, 2022
4240836
Merge branch 'SM3' of https://github.com/JuliaLinearAlgebra/SkewLinea…
smataigne Oct 14, 2022
99db4a8
Robustness enhanced
smataigne Oct 14, 2022
2cbe1db
Robustness enhanced
smataigne Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 156 additions & 42 deletions src/skeweigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,24 @@ end
val[2] = complex(0, -k)
end

function getshift(ev::AbstractVector{T}, lim::Real) where T
if abs(ev[2]) < lim
return ev[1]^2
function getshift(ev::AbstractVector{T}) where T
if abs(ev[2]) ≈ abs(ev[1])
return 0
end
return ev[2]^2
end

@views function implicitstep_novec(ev::AbstractVector{T} , n::Integer ) where T
bulge = zero(T)
lim = T(10^(div(log(10, eps(T)), 2)))
shift = getshift(ev[n-1:n], lim)
@inbounds(for i=1:n-1
shift = getshift(ev[n-1:n])
activation = 0
@inbounds(for i = 1:n-1
α = (i > 1 ? ev[i-1] : zero(ev[i]))
β = ev[i]
γ = ev[i+1]
x1 = - α * α - β * β + shift
x2 = - α * bulge + β * γ
c, s = ((iszero(x1) && iszero(x2)) ? getgivens(α,bulge) : getgivens(x1, x2))

c, s = ((iszero(x1) && iszero(x2)) ? getgivens(α, bulge) : getgivens(x1, x2))
if i > 1
ev[i-1] = c * α + s * bulge
end
Expand All @@ -95,6 +94,14 @@ end
ev[i+2] *= c
bulge = s * ζ
end
#Make it compulsory to initiate a bulge before stopping
if !iszero(bulge)
activation += 1
else
if activation > 0
return
end
end
end)
return
end
Expand All @@ -114,6 +121,10 @@ end
N = n
while n > 2 && iter < max_iter
implicitstep_novec(ev, n - 1)
while n > 2 && abs(ev[n-1]) <= tol
values[n] = 0
n -= 1
end
while n > 2 && abs(ev[n - 2]) <= tol * abs(ev[n - 1])
eigofblock(ev[n - 1], values[n-1:n] )
n -= 2
Expand All @@ -123,6 +134,9 @@ end
if n == 2
eigofblock(ev[1], values[1:2])
return values
elseif n == 1
values[1] = 0
return values
elseif n == 0
return values
else
Expand All @@ -132,8 +146,8 @@ end

@views function implicitstep_vec!(ev::AbstractVector{T}, Qeven::AbstractMatrix{T}, Qodd::AbstractMatrix{T}, n::Integer, N::Integer) where T
bulge = zero(T)
lim = T(10^(div(log(10, eps(T)), 2)))
shift = getshift(ev[n-1:n], lim)
shift = getshift(ev[n-1:n])
activation = 0
@inbounds(for i=1:n-1
α = (i > 1 ? ev[i-1] : zero(ev[i]))
β = ev[i]
Expand All @@ -160,6 +174,14 @@ end
Q[j, k] = c*σ + s*ω
Q[j, k+1] = -s*σ + c*ω
end

if !iszero(bulge)
activation += 1
else
if activation > 0
return
end
end
end)
return
end
Expand All @@ -181,37 +203,82 @@ end
tol = eps(T)*T(10)
max_iter = 30 * n
iter = 0 ;
halfN = div(n,2)
halfN = div(n, 2)

while n > 2 && iter < max_iter
implicitstep_vec!(ev, Qeven, Qodd, n - 1, halfN)
while n > 2 && abs(ev[n - 2]) <= tol*abs(ev[n - 1])
eigofblock(ev[n - 1], values[n-1:n])
while n > 2 && abs(ev[n-1]) <= tol
values[n] = 0
n -= 1
end
while n > 2 && abs(ev[n - 2]) <= tol * abs(ev[n - 1])
eigofblock(ev[n - 1], values[n-1:n] )
n -= 2
end
iter += 1
end
if n == 2
eigofblock(ev[1], values[1:2])
if n > 0
if n == 2
eigofblock(ev[1], values[1:2])
else
values[1] = 0
end
if isodd(N)
getoddvectors(Qodd, Ginit, N - 1)
end

s2 = T(1/sqrt(2))
zero = T(0)
@inbounds(for i = 1:2:N-1
i = 1
countzeros = 0
@inbounds(while i <= N
ii = div(i+1,2)
for j = 1:2:N-1
jj = div(j+1, 2)
vectors[j, i] = complex(s2 * Qodd[jj, ii], zero)
vectors[j+1, i] = complex(zero, - s2 * Qeven[jj, ii])
vectors[j, i+1] = complex(zero,s2 * Qodd[jj, ii])
vectors[j+1, i+1] = complex(- s2 * Qeven[jj,ii], zero)
end
if isodd(N)
vectors[N, i] = complex(s2 * Qodd[halfN+1, ii],zero)
vectors[N, i+1] = complex(zero, s2 * Qodd[halfN+1, ii])
if iszero(values[i])
if iseven(countzeros)
for j = 1:2:N-1
jj = div(j+1, 2)
vectors[j, i] = complex(Qodd[jj, ii], zero)
end
if isodd(N)
vectors[N, i] = complex(Qodd[halfN+1, ii],zero)
end
else
for j = 1:2:N-1
jj = div(j+1, 2)
vectors[j+1, i] = complex(Qeven[jj, ii], zero)
end
end
countzeros +=1
i += 1
else
if isodd(countzeros)
for j = 1:2:N-1
jj = div(j+1, 2)
vectors[j, i] = complex(zero, -s2 * Qodd[jj, ii+1])
vectors[j+1, i] = complex(s2 * Qeven[jj, ii], zero)
vectors[j, i+1] = complex(-s2 * Qodd[jj, ii+1], zero)
vectors[j+1, i+1] = complex(zero, s2 * Qeven[jj,ii])
end
if isodd(N)
vectors[N, i] = complex(zero, -s2 * Qodd[halfN+1, ii+1])
vectors[N, i+1] = complex(-s2 * Qodd[halfN+1, ii+1], zero)
end
else
for j = 1:2:N-1
jj = div(j+1, 2)
vectors[j, i] = complex(s2 * Qodd[jj, ii], zero)
vectors[j+1, i] = complex(zero, - s2 * Qeven[jj, ii])
vectors[j, i+1] = complex(zero,s2 * Qodd[jj, ii])
vectors[j+1, i+1] = complex(- s2 * Qeven[jj,ii], zero)
end
if isodd(N)
vectors[N, i] = complex(s2 * Qodd[halfN+1, ii],zero)
vectors[N, i+1] = complex(zero, s2 * Qodd[halfN+1, ii])
end
end
i+=2
end

end)

if isodd(N)
Expand Down Expand Up @@ -250,35 +317,82 @@ end
halfN = div(n, 2)
while n > 2 && iter < max_iter
implicitstep_vec!(ev, Qeven, Qodd, n - 1, halfN)
while n > 2 && abs(ev[n - 2]) <= tol*abs(ev[n - 1])
eigofblock(ev[n - 1], values[n-1:n])
while n > 2 && abs(ev[n-1]) <= tol
values[n] = 0
n -= 1
end
while n > 2 && abs(ev[n - 2]) <= tol * abs(ev[n - 1])
eigofblock(ev[n - 1], values[n-1:n] )
n -= 2
end
iter += 1
end
if n == 2
eigofblock(ev[1], values[1:2])
if n > 0
if n == 2
eigofblock(ev[1], values[1:2])
else
values[1] = 0
end

if isodd(N)
getoddvectors(Qodd, Ginit, N - 1)
end

s2 = T(1/sqrt(2))
NN = div(N+1, 2)
@inbounds(for i = 1:2:N-1
ii = div(i+1,2)
for j = 1:2:N-1
jj = div(j+1,2)
vectorsreal[j, i] = s2*Qodd[jj, ii]
vectorsreal[j+1, i+1] = -s2*Qeven[jj, ii]
vectorsim[j, i+1] = vectorsreal[j, i]
vectorsim[j+1, i] = vectorsreal[j+1, i+1]
end

if isodd(N)
vectorsreal[N, i] = s2 * Qodd[halfN+1, ii]
vectorsim[N, i+1] = vectorsreal[N, i]
i = 1
countzeros = 0
@inbounds(while i <= N
ii = div(i+1,2)
if iszero(values[i])
if iseven(countzeros)
for j = 1:2:N-1
jj = div(j+1, 2)
vectorsreal[j, i] = Qodd[jj, ii]
end
if isodd(N)
vectorsreal[N, i] = Qodd[halfN+1, ii]
end
else
for j = 1:2:N-1
jj = div(j+1, 2)
vectorsreal[j+1, i] = Qeven[jj, ii]
end
end
countzeros +=1
i += 1
else
if isodd(countzeros)
for j = 1:2:N-1
jj = div(j+1, 2)
vectorsim[j, i] = -s2 * Qodd[jj, ii+1]
vectorsreal[j+1, i] = s2 * Qeven[jj, ii]
vectorsreal[j, i+1] = -s2 * Qodd[jj, ii+1]
vectorsim[j+1, i+1] = s2 * Qeven[jj,ii]
end
if isodd(N)
vectorsreal[N, i] = -s2 * Qodd[halfN+1, ii+1]
vectorsim[N, i+1] = -s2 * Qodd[halfN+1, ii+1]
end
else
for j = 1:2:N-1
jj = div(j+1, 2)
vectorsreal[j, i] = s2 * Qodd[jj, ii]
vectorsim[j+1, i] = - s2 * Qeven[jj, ii]
vectorsim[j, i+1] = s2 * Qodd[jj, ii]
vectorsreal[j+1, i+1] = - s2 * Qeven[jj,ii]
end
if isodd(N)
vectorsreal[N, i] = s2 * Qodd[halfN+1, ii]
vectorsim[N, i+1] = s2 * Qodd[halfN+1, ii]
end
end
i+=2
end

end)

if isodd(N)
@inbounds(for j = 1:2:N
jj = div(j+1,2)
Expand Down
22 changes: 22 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,25 @@ end
@test repr("text/plain", JMatrix(4)) == "4×4 JMatrix{Int8, 1}:\n ⋅ 1 ⋅ ⋅\n -1 ⋅ ⋅ ⋅\n ⋅ ⋅ ⋅ 1\n ⋅ ⋅ -1 ⋅"
end

@testset "issue#116" begin

for ev in ([0,0,0], [1,2,3,2,1], [0,1,0], [1,0,0], [1,0,1], [1,1,0], [0,1,1], [0,0,1], [1,1,1],[1,1,0,1,1],[0,0,0,0,1,1,1],[0,1,0,1,0,1,1,1,0,0,0,1])
A = SkewHermTridiagonal(float.(ev))
a = sort(eigvals(A), by = imag)
b = sort(eigvals(im * Matrix(A)) / im, by = imag)
@test a ≈ b
E = eigen(A)
@test E.vectors*Diagonal(E.values)*E.vectors'≈A
end

for ev in ([1,1,0,1],[0,1,0,1,1,1,1,1])
A = SkewHermTridiagonal(float.(ev))
a = sort(eigvals(A), by = imag)
b = sort(eigvals(im * Matrix(A)) / im, by = imag)
@test a ≈ b
E = eigen(A)
@test E.vectors*Diagonal(E.values)*E.vectors'≈A
end

end