From 144751610027e1cdcdd4bd9012cca8b2dfef9cdc Mon Sep 17 00:00:00 2001 From: "Tamas K. Papp" Date: Sun, 31 Dec 2017 12:32:36 +0100 Subject: [PATCH] Changed ArgumentError to DomainError for non-finite stepsize. --- REQUIRE | 1 + src/DynamicHMC.jl | 4 +++- test/test-stepsize.jl | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/REQUIRE b/REQUIRE index 41e8ad1..f931928 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,6 @@ julia 0.6 ArgCheck +Compat DataStructures DiffResults DocStringExtensions diff --git a/src/DynamicHMC.jl b/src/DynamicHMC.jl index dbe07d4..9c1874b 100644 --- a/src/DynamicHMC.jl +++ b/src/DynamicHMC.jl @@ -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 @@ -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 diff --git a/test/test-stepsize.jl b/test/test-stepsize.jl index 2d7869a..1d8b2a8 100644 --- a/test/test-stepsize.jl +++ b/test/test-stepsize.jl @@ -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