Skip to content

Commit f72c9ce

Browse files
committed
specialize normalize for symmetric
1 parent 2f50a1b commit f72c9ce

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/fillalgebra.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ function permutecols!!(A::AbstractMatrix, p::AbstractVector{<:Integer})
543543
A
544544
end
545545

546+
_normalizecols!(M, T) = foreach(normalize!, eachcol(M))
547+
function _normalizecols!(M, T::Union{SymTridiagonal, Symmetric{<:Number, <:Tridiagonal}})
548+
n = size(M,1)
549+
invnrm = sqrt(2/(n+1))
550+
M .*= invnrm
551+
return M
552+
end
553+
546554
function _eigvecs_toeplitz(T; sortby = nothing)
547555
Base.require_one_based_indexing(T)
548556
n = checksquare(T)
@@ -557,11 +565,12 @@ function _eigvecs_toeplitz(T; sortby = nothing)
557565
for j in 1:cld(n,2)
558566
M[j, q] = prefactors[j] * sinpi(j*qrev/(n+1))
559567
end
568+
phase = iseven(n+q) ? 1 : -1
560569
for j in cld(n,2)+1:n
561-
M[j, q] = (-1)^(n+q) * prefactors[2j-n] * M[n+1-j,q]
570+
M[j, q] = phase * prefactors[2j-n] * M[n+1-j,q]
562571
end
563-
normalize!(view(M, :, q))
564572
end
573+
_normalizecols!(M, T)
565574
if !isnothing(sortby)
566575
perm = sortperm(eigvals(T), by = sortby)
567576
permutecols!!(M, perm)

0 commit comments

Comments
 (0)