Skip to content

Commit

Permalink
Changed ArgumentError to DomainError for non-finite stepsize.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp committed Dec 31, 2017
1 parent 6b4c60e commit 1447516
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 0.6
ArgCheck
Compat
DataStructures
DiffResults
DocStringExtensions
Expand Down
4 changes: 3 additions & 1 deletion src/DynamicHMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Base: rand, length, show
import Base.LinAlg.checksquare

using ArgCheck: @argcheck
import Compat # for DomainError(val, msg) in v0.6
using DataStructures
using DiffResults: value, gradient
using DocStringExtensions: SIGNATURES, FIELDS
Expand Down Expand Up @@ -381,7 +382,8 @@ Note that the ratio is not capped by `1`, so it is not a valid probability
"""
function local_acceptance_ratio(H, z)
target = neg_energy(H, z)
@argcheck isfinite(target) "Starting point has non-finite density."
isfinite(target) ||
throw(DomainError(z.p, "Starting point has non-finite density."))
ϵ -> exp(neg_energy(H, leapfrog(H, z, ϵ)) - target)
end

Expand Down
2 changes: 1 addition & 1 deletion test/test-stepsize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ end
p = InitialStepsizeSearch()
H = Hamiltonian((x)->DiffResult(-Inf, ([0.0], )), GaussianKE(1))
z = DynamicHMC.phasepoint_in(H, [1.0], [1.0])
@test_throws ArgumentError find_initial_stepsize(p, H, z)
@test_throws DomainError find_initial_stepsize(p, H, z)
end

0 comments on commit 1447516

Please sign in to comment.