@@ -11,7 +11,7 @@ julia> xlogx(0)
11
11
"""
12
12
function xlogx (x:: Number )
13
13
result = x * log (x)
14
- ifelse ( iszero (x), zero (result), result)
14
+ return iszero (x) ? zero (result) : result
15
15
end
16
16
17
17
"""
@@ -26,7 +26,7 @@ julia> xlogy(0, 0)
26
26
"""
27
27
function xlogy (x:: Number , y:: Number )
28
28
result = x * log (y)
29
- ifelse ( iszero (x) && ! isnan (y), zero (result), result)
29
+ return iszero (x) && ! isnan (y) ? zero (result) : result
30
30
end
31
31
32
32
# The following bounds are precomputed versions of the following abstract
@@ -60,15 +60,7 @@ logistic(x::Real) = inv(exp(-x) + one(x))
60
60
function logistic (x:: Union{Float16, Float32, Float64} )
61
61
e = exp (x)
62
62
lower, upper = _logistic_bounds (x)
63
- ifelse (
64
- x < lower,
65
- zero (x),
66
- ifelse (
67
- x > upper,
68
- one (x),
69
- e / (one (x) + e)
70
- )
71
- )
63
+ return x < lower ? zero (x) : x > upper ? one (x) : e / (one (x) + e)
72
64
end
73
65
74
66
"""
@@ -210,7 +202,7 @@ non-finite values.
210
202
"""
211
203
function logaddexp (x:: Real , y:: Real )
212
204
# ensure Δ = 0 if x = y = ± Inf
213
- Δ = ifelse ( x == y, zero (x - y), abs (x - y) )
205
+ Δ = x == y ? zero (x - y) : abs (x - y)
214
206
max (x, y) + log1pexp (- Δ)
215
207
end
216
208
0 commit comments