Skip to content

Commit

Permalink
Merge pull request #22 from TuringLang/mt/fix_turing_700
Browse files Browse the repository at this point in the history
Fix Turing issue 700
  • Loading branch information
yebai authored Mar 4, 2019
2 parents 9ccc4af + e24fa54 commit d4ddabe
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Bijectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export TransformDistribution,

const DEBUG = Bool(parse(Int, get(ENV, "DEBUG_BIJECTORS", "0")))

_eps(::Type{T}) where {T} = eps(T)
# Workaround for eps(::ForwardDiff.Dual)
_eps(::Type{T}) where {T} = T(eps(T))
_eps(::Type{Real}) = eps(Float64)
function __init__()
@require ForwardDiff="f6369f11-7733-5829-9624-2563aa707210" @eval begin
Expand Down Expand Up @@ -62,8 +63,8 @@ end
#############

const TransformDistribution{T<:ContinuousUnivariateDistribution} = Union{T, Truncated{T}}
@inline function _clamp(x::Real, dist::TransformDistribution)
ϵ = eps(x)
@inline function _clamp(x::T, dist::TransformDistribution) where {T <: Real}
ϵ = _eps(T)
bounds = (minimum(dist) + ϵ, maximum(dist) - ϵ)
clamped_x = ifelse(x < bounds[1], bounds[1], ifelse(x > bounds[2], bounds[2], x))
DEBUG && @debug "x = $x, bounds = $bounds, clamped_x = $clamped_x"
Expand Down

0 comments on commit d4ddabe

Please sign in to comment.