Skip to content

Commit 288b6d7

Browse files
timholyamontoison
authored andcommitted
Improve inference for Double64
Some of the methods in Krylov return `Union`s when passed `Double64` arguments. This commit reworks those methods to ensure deterministic return types.
1 parent 4e3d7a4 commit 288b6d7

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/krylov_utils.jl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,25 @@ function sym_givens(a :: T, b :: T) where T <: AbstractFloat
2424
# http://www.stanford.edu/group/SOL/dissertations/sou-cheng-choi-thesis.pdf
2525
# D. Orban, Montreal, May 2015.
2626

27-
if b == 0
28-
if a == 0
29-
c = one(T)
30-
else
31-
c = sign(a) # In Julia, sign(0) = 0.
32-
end
27+
if iszero(b)
28+
c = T(sign(a) + iszero(a)) # In Julia, sign(0) = 0.
3329
s = zero(T)
3430
ρ = abs(a)
3531

36-
elseif a == 0
32+
elseif iszero(a)
3733
c = zero(T)
38-
s = sign(b)
34+
s = T(sign(b))
3935
ρ = abs(b)
4036

4137
elseif abs(b) > abs(a)
4238
t = a / b
43-
s = sign(b) / sqrt(one(T) + t * t)
39+
s = T(sign(b)) / sqrt(oneunit(T) + t * t)
4440
c = s * t
4541
ρ = b / s # Computationally better than ρ = a / c since |c| ≤ |s|.
4642

4743
else
4844
t = b / a
49-
c = sign(a) / sqrt(one(T) + t * t)
45+
c = T(sign(a)) / sqrt(oneunit(T) + t * t)
5046
s = c * t
5147
ρ = a / c # Computationally better than ρ = b / s since |s| ≤ |c|
5248
end
@@ -387,12 +383,12 @@ function to_boundary(n :: Int, x :: AbstractVector{FC}, d :: AbstractVector{FC},
387383
mulorldiv!(z, M, x, ldiv)
388384
rxd = kdot(n, z, d)
389385
xNorm2 = kdotr(n, z, x)
390-
mulorldiv!(z, M, d, ldiv)
386+
mulorldiv!(z, M, d, ldiv)
391387
dNorm2 = kdotr(n, z, d)
392-
end
388+
end
393389
dNorm2 == zero(T) && error("zero direction")
394390
flip && (rxd = -rxd)
395-
391+
396392
radius2 = radius * radius
397393
(xNorm2 radius2) || error(@sprintf("outside of the trust region: ‖x‖²=%7.1e, Δ²=%7.1e", xNorm2, radius2))
398394

0 commit comments

Comments
 (0)