Skip to content

Commit cbd1bbe

Browse files
authored
Fix CUDA issue with irrational constant (#75)
1 parent 24fcdab commit cbd1bbe

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LogExpFunctions"
22
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
33
authors = ["StatsFun.jl contributors, Tamas K. Papp <[email protected]>"]
4-
version = "0.3.24"
4+
version = "0.3.25"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/basicfuns.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@ See:
231231
232232
Note: different than Maechler (2012), no negation inside parentheses
233233
"""
234-
log1mexp(x::Real) = x < IrrationalConstants.loghalf ? log1p(-exp(x)) : log(-expm1(x))
234+
function log1mexp(x::Real)
235+
# Use explicit `oftype(..)` instead of just `loghalf` to avoid CUDA issues:
236+
# https://github.com/JuliaStats/LogExpFunctions.jl/issues/73
237+
if x < oftype(float(x), IrrationalConstants.loghalf)
238+
return log1p(-exp(x))
239+
else
240+
return log(-expm1(x))
241+
end
242+
end
235243

236244
"""
237245
$(SIGNATURES)

0 commit comments

Comments
 (0)