Skip to content

Commit 7217873

Browse files
committed
Merge remote-tracking branch 'origin/master' into tp/release-1.0
2 parents e987576 + c9adf5a commit 7217873

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

Project.toml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,5 @@ ChangesOfVariables = "0.1"
2727
DocStringExtensions = "0.8, 0.9"
2828
InverseFunctions = "0.1"
2929
IrrationalConstants = "0.1, 0.2"
30+
LinearAlgebra = "1.10"
3031
julia = "1.10"
31-
32-
[extras]
33-
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
34-
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
35-
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
36-
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
37-
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
38-
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
39-
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
40-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
41-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
42-
43-
[targets]
44-
test = ["ChainRulesCore", "ChainRulesTestUtils", "ChangesOfVariables", "FiniteDifferences", "ForwardDiff", "InverseFunctions", "OffsetArrays", "Random", "Test"]

src/logsumexp.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,23 @@ _logsumexp_onepass_op((xmax, r)::Tuple{<:Number,<:Number}, x::Number) =
114114
_logsumexp_onepass_op(x::Number, xmax::Number, r::Number) =
115115
_logsumexp_onepass_op(promote(x, xmax)..., r)
116116
function _logsumexp_onepass_op(x::T, xmax::T, r::Number) where {T<:Number}
117+
# The following invariants are maintained through the reduction:
118+
# `xmax` is the maximum of the elements encountered so far,
119+
# ``r = ∑ᵢ exp(xᵢ - xmax)`` over the same elements.
117120
_xmax, _r = if isnan(x) || isnan(xmax)
118121
# ensure that `NaN` is propagated correctly for complex numbers
119122
z = oftype(x, NaN)
120123
z, r + exp(z)
121124
else
122125
real_x = real(x)
123126
real_xmax = real(xmax)
124-
if real_x > real_xmax
127+
if isinf(real_x) && isinf(real_xmax) && (real_x * real_xmax) > 0
128+
# handle `x = xmax = ±Inf` correctly, without relying on ForwardDiff.value
129+
xmax, r + exp(zero(x - xmax))
130+
elseif real_x > real_xmax
125131
x, (r + one(r)) * exp(xmax - x)
126-
elseif real_x < real_xmax
127-
xmax, r + exp(x - xmax)
128132
else
129-
# handle `x = xmax = ±Inf` correctly
130-
# checking inequalities above instead of equality fixes issue #59
131-
xmax, r + exp(zero(x - xmax))
133+
xmax, r + exp(x - xmax)
132134
end
133135
end
134136
return _xmax, _r

test/Project.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[deps]
2+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
4+
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
5+
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
6+
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
7+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
8+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
9+
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
10+
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
11+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
12+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
13+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ include("basicfuns.jl")
1616
include("chainrules.jl")
1717
include("inverse.jl")
1818
include("with_logabsdet_jacobian.jl")
19+
20+
# QA
21+
import JET
22+
JET.report_package("LogExpFunctions")
23+
import Aqua
24+
Aqua.test_all(LogExpFunctions)

0 commit comments

Comments
 (0)