Skip to content

Commit ef815d6

Browse files
authored
Merge pull request #112 from JuliaLinearAlgebra/an/debug
Use logging system for debug printing
2 parents 29f8062 + d70acf2 commit ef815d6

File tree

3 files changed

+80
-166
lines changed

3 files changed

+80
-166
lines changed

src/eigenGeneral.jl

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ end
8484
function _schur!(
8585
H::HessenbergFactorization{T};
8686
tol = eps(real(T)),
87-
debug = false,
8887
shiftmethod = :Francis,
8988
maxiter = 30 * size(H, 1),
9089
kwargs...,
@@ -101,7 +100,7 @@ function _schur!(
101100

102101
@inbounds while true
103102
i += 1
104-
debug && println("iteration: $i")
103+
@debug "iteration" i
105104
if i > maxiter
106105
throw(ArgumentError("iteration limit $maxiter reached"))
107106
end
@@ -115,11 +114,7 @@ function _schur!(
115114
# Set istart to the beginning of the second block
116115
istart = _istart + 1
117116

118-
debug && @printf(
119-
"Split! Subdiagonal element is: %10.3e and istart now %6d\n",
120-
HH[istart, istart-1],
121-
istart
122-
)
117+
@debug "Split!" HH[istart, istart-1] istart
123118

124119
# Set the subdiagonal element to zero to signal that a split has taken place
125120
HH[istart, istart-1] = 0
@@ -132,14 +127,12 @@ function _schur!(
132127

133128
# if block size is one we deflate
134129
if istart >= iend
135-
debug &&
136-
@printf("Bottom deflation! Block size is one. New iend is %6d\n", iend - 1)
130+
@debug "Bottom deflation! Block size is one. New iend is" iend - 1
137131
iend -= 1
138132

139133
# and the same for a 2x2 block
140134
elseif istart + 1 == iend
141-
debug &&
142-
@printf("Bottom deflation! Block size is two. New iend is %6d\n", iend - 2)
135+
@debug "Bottom deflation! Block size is two. New iend is" iend - 2
143136
iend -= 2
144137

145138
# run a QR iteration
@@ -156,26 +149,14 @@ function _schur!(
156149
d = Hm1m1 * Hmm - HH[iend, iend-1] * HH[iend-1, iend]
157150
t = Hm1m1 + Hmm
158151
end
159-
debug && @printf(
160-
"block start is: %6d, block end is: %6d, d: %10.3e, t: %10.3e\n",
161-
istart,
162-
iend,
163-
d,
164-
t
165-
)
152+
@debug "block start is, block end, d, and t" istart iend d t
166153

167154
if shiftmethod == :Francis
168-
debug && @printf(
169-
"Francis double shift! Subdiagonal is: %10.3e, last subdiagonal is: %10.3e\n",
170-
HH[iend, iend-1],
171-
HH[iend-1, iend-2]
172-
)
155+
@debug "Francis double shift!" HH[iend, iend-1] HH[iend-1, iend-2]
156+
173157
doubleShiftQR!(HH, τ, t, d, istart, iend)
174158
elseif shiftmethod == :Rayleigh
175-
debug && @printf(
176-
"Single shift with Rayleigh shift! Subdiagonal is: %10.3e\n",
177-
HH[iend, iend-1]
178-
)
159+
@debug "Single shift with Rayleigh shift!" HH[iend, iend-1]
179160

180161
# Run a bulge chase
181162
singleShiftQR!(HH, τ, Hmm, istart, iend)

src/eigenSelfAdjoint.jl

Lines changed: 41 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ function eigQL2x2!(d::StridedVector, e::StridedVector, j::Integer, vectors::Matr
160160
return c, s
161161
end
162162

163-
function eigvalsPWK!(
164-
S::SymTridiagonal{T};
165-
tol = eps(T),
166-
debug::Bool = false,
167-
) where {T<:Real}
163+
function eigvalsPWK!(S::SymTridiagonal{T}; tol = eps(T)) where {T<:Real}
168164
d = S.dv
169165
e = S.ev
170166
n = length(d)
@@ -187,15 +183,16 @@ function eigvalsPWK!(
187183

188184
# Deflate?
189185
if blockstart == blockend
190-
# Yes
186+
@debug "Deflate? Yes!"
191187
blockstart += 1
192188
elseif blockstart + 1 == blockend
193-
debug && println("Yes, but after sreolving 2x2 block")
189+
@debug "Defalte? Yes, but after solving 2x2 block!"
194190
d[blockstart], d[blockend] =
195191
eigvals2x2(d[blockstart], d[blockend], sqrt(e[blockstart]))
196192
e[blockstart] = zero(T)
197193
blockstart += 1
198194
else
195+
@debug "Deflate? No!"
199196
# Calculate shift
200197
sqrte = sqrt(e[blockstart])
201198
μ = (d[blockstart+1] - d[blockstart]) / (2 * sqrte)
@@ -205,15 +202,9 @@ function eigvalsPWK!(
205202
# QL bulk chase
206203
singleShiftQLPWK!(S, μ, blockstart, blockend)
207204

208-
debug && @printf(
209-
"QL, blockstart: %d, blockend: %d, e[blockstart]: %e, e[blockend-1]:%e, μ: %e, rotations: %d\n",
210-
blockstart,
211-
blockend,
212-
e[blockstart],
213-
e[blockend-1],
214-
μ,
215-
iter += blockend - blockstart
216-
)
205+
rotations = blockend - blockstart
206+
iter += rotations
207+
@debug "QL, blockstart, blockend, e[blockstart], e[blockend-1], μ, rotations" blockstart blockend e[blockstart] e[blockend-1] μ rotations
217208
end
218209
if blockstart >= n
219210
break
@@ -227,7 +218,6 @@ function eigQL!(
227218
S::SymTridiagonal{T};
228219
vectors::Matrix = zeros(T, 0, size(S, 1)),
229220
tol = eps(T),
230-
debug::Bool = false,
231221
) where {T<:Real}
232222
d = S.dv
233223
e = S.ev
@@ -262,28 +252,22 @@ function eigQL!(
262252
end
263253
# Deflate?
264254
if blockstart == blockend
265-
# Yes!
255+
@debug "Deflate? Yes!"
266256
blockstart += 1
267257
elseif blockstart + 1 == blockend
268-
debug && println("Yes, but after solving 2x2 block")
258+
@debug "Deflate? Yes, but after solving 2x2 block"
269259
eigQL2x2!(d, e, blockstart, vectors)
270260
blockstart += 1
271261
else
262+
@debug "Deflate? No!"
272263
# Calculate shift
273264
μ = (d[blockstart+1] - d[blockstart]) / (2 * e[blockstart])
274265
r = hypot(μ, one(T))
275266
μ = d[blockstart] - (e[blockstart] /+ copysign(r, μ)))
276267

277268
# QL bulk chase
278269
singleShiftQL!(S, μ, blockstart, blockend, vectors)
279-
debug && @printf(
280-
"QL, blockstart: %d, blockend: %d, e[blockstart]: %e, e[blockend-1]:%e, μ: %f\n",
281-
blockstart,
282-
blockend,
283-
e[blockstart],
284-
e[blockend-1],
285-
μ
286-
)
270+
@debug "QL, blockstart, blockend, e[blockstart], e[blockend-1] μ" blockstart blockend e[blockstart] e[blockend-1] μ
287271
end
288272
if blockstart >= n
289273
break
@@ -298,7 +282,6 @@ function eigQR!(
298282
S::SymTridiagonal{T};
299283
vectors::Matrix = zeros(T, 0, size(S, 1)),
300284
tol = eps(T),
301-
debug::Bool = false,
302285
) where {T<:Real}
303286
d = S.dv
304287
e = S.ev
@@ -317,13 +300,14 @@ function eigQR!(
317300
end
318301
# Deflate?
319302
if blockstart == blockend
320-
# Yes!
303+
@debug "Deflate? Yes!"
321304
blockstart += 1
322305
elseif blockstart + 1 == blockend
323-
debug && println("Yes, but after solving 2x2 block")
306+
@debug "Deflate? Yes, but after solving 2x2 block!"
324307
eigQL2x2!(d, e, blockstart, vectors)
325308
blockstart += 1
326309
else
310+
@debug "Deflate? No!"
327311
# Calculate shift
328312
μ = (d[blockend-1] - d[blockend]) / (2 * e[blockend-1])
329313
r = hypot(μ, one(T))
@@ -332,15 +316,7 @@ function eigQR!(
332316
# QR bulk chase
333317
singleShiftQR!(S, μ, blockstart, blockend, vectors)
334318

335-
debug && @printf(
336-
"QR, blockstart: %d, blockend: %d, e[blockstart]: %e, e[blockend-1]:%e, d[blockend]: %f, μ: %f\n",
337-
blockstart,
338-
blockend,
339-
e[blockstart],
340-
e[blockend-1],
341-
d[blockend],
342-
μ
343-
)
319+
@debug "QR, blockstart, blockend, e[blockstart], e[blockend-1], d[blockend], μ" blockstart blockend e[blockstart] e[blockend-1] d[blockend] μ
344320
end
345321
if blockstart >= n
346322
break
@@ -601,87 +577,66 @@ function symtriUpper!(
601577
end
602578

603579

604-
_eigvals!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A))), debug = false) =
605-
eigvalsPWK!(A.diagonals, tol = tol, debug = debug)
580+
_eigvals!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A)))) =
581+
eigvalsPWK!(A.diagonals, tol = tol)
606582

607-
_eigvals!(A::SymTridiagonal; tol = eps(real(eltype(A))), debug = false) =
608-
eigvalsPWK!(A, tol = tol, debug = debug)
583+
_eigvals!(A::SymTridiagonal; tol = eps(real(eltype(A)))) = eigvalsPWK!(A, tol = tol)
609584

610-
_eigvals!(A::Hermitian; tol = eps(real(eltype(A))), debug = false) =
611-
eigvals!(symtri!(A), tol = tol, debug = debug)
585+
_eigvals!(A::Hermitian; tol = eps(real(eltype(A)))) = eigvals!(symtri!(A), tol = tol)
612586

613587

614-
LinearAlgebra.eigvals!(
615-
A::SymmetricTridiagonalFactorization;
616-
tol = eps(real(eltype(A))),
617-
debug = false,
618-
) = _eigvals!(A, tol = tol, debug = debug)
588+
LinearAlgebra.eigvals!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A)))) =
589+
_eigvals!(A, tol = tol)
619590

620-
LinearAlgebra.eigvals!(A::SymTridiagonal; tol = eps(real(eltype(A))), debug = false) =
621-
_eigvals!(A, tol = tol, debug = debug)
591+
LinearAlgebra.eigvals!(A::SymTridiagonal; tol = eps(real(eltype(A)))) =
592+
_eigvals!(A, tol = tol)
622593

623-
LinearAlgebra.eigvals!(A::Hermitian; tol = eps(real(eltype(A))), debug = false) =
624-
_eigvals!(A, tol = tol, debug = debug)
594+
LinearAlgebra.eigvals!(A::Hermitian; tol = eps(real(eltype(A)))) = _eigvals!(A, tol = tol)
625595

626596

627-
_eigen!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A))), debug = false) =
628-
LinearAlgebra.Eigen(
629-
eigQL!(A.diagonals, vectors = Array(A.Q), tol = tol, debug = debug)...,
630-
)
597+
_eigen!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A)))) =
598+
LinearAlgebra.Eigen(eigQL!(A.diagonals, vectors = Array(A.Q), tol = tol)...)
631599

632-
_eigen!(A::SymTridiagonal; tol = eps(real(eltype(A))), debug = false) = LinearAlgebra.Eigen(
633-
eigQL!(
634-
A,
635-
vectors = Matrix{eltype(A)}(I, size(A, 1), size(A, 1)),
636-
tol = tol,
637-
debug = debug,
638-
)...,
600+
_eigen!(A::SymTridiagonal; tol = eps(real(eltype(A)))) = LinearAlgebra.Eigen(
601+
eigQL!(A, vectors = Matrix{eltype(A)}(I, size(A, 1), size(A, 1)), tol = tol)...,
639602
)
640603

641-
_eigen!(A::Hermitian; tol = eps(real(eltype(A))), debug = false) =
642-
_eigen!(symtri!(A), tol = tol, debug = debug)
604+
_eigen!(A::Hermitian; tol = eps(real(eltype(A)))) = _eigen!(symtri!(A), tol = tol)
643605

644606

645-
LinearAlgebra.eigen!(
646-
A::SymmetricTridiagonalFactorization;
647-
tol = eps(real(eltype(A))),
648-
debug = false,
649-
) = _eigen!(A, tol = tol, debug = debug)
607+
LinearAlgebra.eigen!(A::SymmetricTridiagonalFactorization; tol = eps(real(eltype(A)))) =
608+
_eigen!(A, tol = tol)
650609

651-
LinearAlgebra.eigen!(A::SymTridiagonal; tol = eps(real(eltype(A))), debug = false) =
652-
_eigen!(A, tol = tol, debug = debug)
610+
LinearAlgebra.eigen!(A::SymTridiagonal; tol = eps(real(eltype(A)))) = _eigen!(A, tol = tol)
653611

654-
LinearAlgebra.eigen!(A::Hermitian; tol = eps(real(eltype(A))), debug = false) =
655-
_eigen!(A, tol = tol, debug = debug)
612+
LinearAlgebra.eigen!(A::Hermitian; tol = eps(real(eltype(A)))) = _eigen!(A, tol = tol)
656613

657614

658615
function eigen2!(
659616
A::SymmetricTridiagonalFactorization;
660617
tol = eps(real(float(one(eltype(A))))),
661-
debug = false,
662618
)
663619
V = zeros(eltype(A), 2, size(A, 1))
664620
V[1] = 1
665621
V[end] = 1
666-
eigQL!(A.diagonals, vectors = rmul!(V, A.Q), tol = tol, debug = debug)
622+
eigQL!(A.diagonals, vectors = rmul!(V, A.Q), tol = tol)
667623
end
668624

669-
function eigen2!(A::SymTridiagonal; tol = eps(real(float(one(eltype(A))))), debug = false)
625+
function eigen2!(A::SymTridiagonal; tol = eps(real(float(one(eltype(A))))))
670626
V = zeros(eltype(A), 2, size(A, 1))
671627
V[1] = 1
672628
V[end] = 1
673-
eigQL!(A, vectors = V, tol = tol, debug = debug)
629+
eigQL!(A, vectors = V, tol = tol)
674630
end
675631

676-
eigen2!(A::Hermitian; tol = eps(float(real(one(eltype(A))))), debug = false) =
677-
eigen2!(symtri!(A), tol = tol, debug = debug)
632+
eigen2!(A::Hermitian; tol = eps(float(real(one(eltype(A)))))) =
633+
eigen2!(symtri!(A), tol = tol)
678634

679635

680-
eigen2(A::SymTridiagonal; tol = eps(float(real(one(eltype(A))))), debug = false) =
681-
eigen2!(copy(A), tol = tol, debug = debug)
636+
eigen2(A::SymTridiagonal; tol = eps(float(real(one(eltype(A)))))) =
637+
eigen2!(copy(A), tol = tol)
682638

683-
eigen2(A::Hermitian, tol = eps(float(real(one(eltype(A))))), debug = false) =
684-
eigen2!(copy(A), tol = tol, debug = debug)
639+
eigen2(A::Hermitian, tol = eps(float(real(one(eltype(A)))))) = eigen2!(copy(A), tol = tol)
685640

686641
# First method of each type here is identical to the method defined in
687642
# LinearAlgebra but is needed for disambiguation

0 commit comments

Comments
 (0)