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

fixed lapack error 22 and cleaned code #59

Merged
merged 30 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
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
10 changes: 5 additions & 5 deletions src/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ struct SkewCholesky{T,R<:UpperTriangular{<:T},J<:SkewHermTridiagonal{<:T},P<:Abs
end

function SkewCholesky(Rm::UpperTriangular{<:T},Pv::AbstractVector{<:Integer}) where {T<:Real}
n=size(Rm,1)
vec = zeros(T,n-1)
for i = 1:2:n-1
n = size(Rm, 1)
vec = zeros(T, n - 1)
for i = 1 : 2 : n - 1
vec[i] = -1
end
return SkewCholesky{T,UpperTriangular{<:T},SkewHermTridiagonal{<:T},AbstractVector{<:Integer}}(Rm,SkewHermTridiagonal(vec),Pv)
return SkewCholesky{T,UpperTriangular{<:T},SkewHermTridiagonal{<:T},AbstractVector{<:Integer}}(Rm, SkewHermTridiagonal(vec), Pv)

end

function _skewchol!(A::SkewHermitian)
@views B = A.data
tol = 1e-15*norm(B)
tol = 1e-15 * norm(B)
m = size(B,1)
J2 = similar(B,2,2)
J2[1,1] = 0; J2[2,1] = -1; J2[1,2] = 1; J2[2,2] = 0
Expand Down
100 changes: 47 additions & 53 deletions src/eigen.jl
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
# Based on eigen.jl in Julia. License is MIT: https://julialang.org/license


@views function LA.eigvals!(A::SkewHermitian{<:Real}, sortby::Union{Function,Nothing}=nothing)
vals = skeweigvals!(A)
!isnothing(sortby) && sort!(vals, by=sortby)
!isnothing(sortby) && sort!(vals, by = sortby)
return complex.(0, vals)
end

@views function LA.eigvals!(A::SkewHermitian{<:Real}, irange::UnitRange)
vals = skeweigvals!(A,irange)
vals = skeweigvals!(A, irange)
return complex.(0, vals)
end

@views function LA.eigvals!(A::SkewHermitian{<:Real}, vl::Real,vh::Real)
vals = skeweigvals!(A,-vh,-vl)
vals = skeweigvals!(A, -vh, -vl)
return complex.(0, vals)
end

@views function LA.eigvals!(A::SkewHermitian{<:Complex}, sortby::Union{Function,Nothing}=nothing)
H=Hermitian(A.data.*1im)
if sortby===nothing
H = Hermitian(A.data.*1im)
if sortby === nothing
return complex.(0, - eigvals!(H))
end
vals=eigvals!(H,sortby)
vals = eigvals!(H, sortby)
reverse!(vals)
vals.= .-vals
return complex.(0, vals)
end

@views function LA.eigvals!(A::SkewHermitian{<:Complex}, irange::UnitRange)
H=Hermitian(A.data.*1im)
vals=eigvals!(H,-irange)
vals.= .-vals
H = Hermitian(A.data.*1im)
vals = eigvals!(H,-irange)
vals .= .-vals
return complex.(0, vals)
end

@views function LA.eigvals!(A::SkewHermitian{<:Complex}, vl::Real,vh::Real)
H=Hermitian(A.data.*1im)
vals=eigvals!(H,-vh,-vl)
vals.= .-vals
H = Hermitian(A.data.*1im)
vals = eigvals!(H,-vh,-vl)
vals .= .-vals
return complex.(0, vals)
end

Expand All @@ -50,54 +48,53 @@ LA.eigvals(A::SkewHermitian, vl::Real,vh::Real) =
# no need to define LA.eigen(...) since the generic methods should work

@views function skeweigvals!(S::SkewHermitian{<:Real})
n = size(S.data,1)
n = size(S.data, 1)
E = skewblockedhess!(S)[2]
H = SymTridiagonal(zeros(eltype(E),n),E)
H = SymTridiagonal(zeros(eltype(E), n), E)
vals = eigvals!(H)
return vals .= .-vals
end

@views function skeweigvals!(S::SkewHermitian{<:Real},irange::UnitRange)
n = size(S.data,1)
E = skewblockedhess!(S)[2]
H = SymTridiagonal(zeros(eltype(E),n),E)
H = SymTridiagonal(zeros(eltype(E), n), E)
vals = eigvals!(H,irange)
return vals .= .-vals
end

@views function skeweigvals!(S::SkewHermitian{<:Real},vl::Real,vh::Real)
n = size(S.data,1)
E = skewblockedhess!(S)[2]
H = SymTridiagonal(zeros(eltype(E),n),E)
H = SymTridiagonal(zeros(eltype(E), n), E)
vals = eigvals!(H,vl,vh)
return vals .= .-vals
end

@views function skeweigen!(S::SkewHermitian{<:Real})
n = size(S.data,1)
n = size(S.data, 1)

tau,E = skewblockedhess!(S)
T = SkewHermTridiagonal(E)
H1 = Hessenberg{typeof(zero(eltype(S.data))),typeof(T),typeof(S.data),typeof(tau),typeof(false)}(T, 'L', S.data, tau, false)
A = S.data
H = SymTridiagonal(zeros(eltype(E),n),E)
H = SymTridiagonal(zeros(eltype(E), n), E)
trisol = eigen!(H)

vals = trisol.values*1im
vals = trisol.values * 1im
vals .*= -1
Qdiag = trisol.vectors

Qr = similar(A,n,(n+1)÷2)
Qim = similar(A,n,n÷2)
temp = similar(A,n,n)

Qr = similar(A, n, (n+1)÷2)
Qim = similar(A, n, n÷2)
temp = similar(A, n, n)
Q=Matrix(H1.Q)
Q1 = similar(A, (n+1)÷2, n)
Q2 = similar(A, n÷2, n)

Q1 = similar(A,(n+1)÷2,n)
Q2 = similar(A,n÷2,n)
@inbounds for j=1:n
@simd for i=1:2:n-1
k=(i+1)÷2
@inbounds for j = 1:n
@simd for i = 1:2:n-1
k = (i+1)÷2
Q1[k,j] = Qdiag[i,j]
Q2[k,j] = Qdiag[i+1,j]
end
Expand All @@ -107,19 +104,19 @@ end
@inbounds for i=1:2:n-1
k1 = (i+1)÷2
@simd for j=1:n
Qr[j,k1] = Q[j,i]*c
Qim[j,k1] = Q[j,i+1]*c
Qr[j,k1] = Q[j,i] * c
Qim[j,k1] = Q[j,i+1] * c
end
c *= (-1)
end

if n%2==1
k=(n+1)÷2
@simd for j=1:n
Qr[j,k] = Q[j,n]*c
Qr[j,k] = Q[j,n] * c
end
Q1[k,:] = Qdiag[n,:]
end

mul!(temp,Qr,Q1) #temp is Qr
mul!(Qdiag,Qim,Q2) #Qdiag is Qim

Expand All @@ -128,16 +125,16 @@ end


@views function LA.eigen!(A::SkewHermitian{<:Real})
vals,Qr,Qim = skeweigen!(A)
vals, Qr, Qim = skeweigen!(A)
return Eigen(vals,complex.(Qr,Qim))
end

copyeigtype(A::SkewHermitian) = copyto!(similar(A, LA.eigtype(eltype(A))), A)

@views function LA.eigen!(A::SkewHermitian{T}) where {T<:Complex}
H=Hermitian(A.data.*1im)
Eig=eigen!(H)
skew_Eig=Eigen(complex.(0,-Eig.values), Eig.vectors)
H = Hermitian(A.data.*1im)
Eig = eigen!(H)
skew_Eig = Eigen(complex.(0,-Eig.values), Eig.vectors)
return skew_Eig
end

Expand All @@ -148,20 +145,18 @@ LA.eigen(A::SkewHermitian) = LA.eigen!(copyeigtype(A))
vals .= abs.(vals)
return sort!(vals; rev=true)
end
@views function LA.svdvals!(A::SkewHermitian{<:Complex})
H=Hermitian(A.data.*1im)
return svdvals!(H)
end

LA.svdvals!(A::SkewHermitian{<:Complex}) = svdvals!(Hermitian(A.data.*1im))
LA.svdvals(A::SkewHermitian) = svdvals!(copyeigtype(A))

@views function LA.svd!(A::SkewHermitian{<:Real})
n=size(A,1)
E=eigen!(A)
U=E.vectors
n = size(A, 1)
E = eigen!(A)
U = E.vectors
vals = imag.(E.values)
I=sortperm(vals;by=abs,rev=true)
permute!(vals,I)
Base.permutecols!!(U,I)
I = sortperm(vals; by = abs, rev = true)
permute!(vals, I)
Base.permutecols!!(U, I)
V = U .* -1im
@inbounds for i=1:n
if vals[i] < 0
Expand All @@ -171,13 +166,12 @@ LA.svdvals(A::SkewHermitian) = svdvals!(copyeigtype(A))
end
end
end
return LA.SVD(U,vals,adjoint(V))
return LA.SVD(U, vals, adjoint(V))
end
@views function LA.svd(A::SkewHermitian{T}) where {T<:Complex}
H=Hermitian(A.data.*1im)
Svd=svd(H)
skew_Svd=SVD(Svd.U,Svd.S,(Svd.Vt).*(-1im))
return skew_Svd
H = Hermitian(A.data.*1im)
Svd = svd(H)
return SVD(Svd.U , Svd.S, (Svd.Vt).*(-1im))
end

LA.svd(A::SkewHermitian{<:Real}) = svd!(copyeigtype(A))
Loading