Skip to content

Commit fe5999b

Browse files
committed
Add type conversion for MLD calls
Calling a MLD with a different type of vector than what it was defined with caused ForwardDiff tagging errors, due to the DI preparation mechanism. Added a `covert` to prevent this.
1 parent 3e59447 commit fe5999b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/MarginalLogDensities.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ function Base.show(io::IO, mld::MarginalLogDensity)
224224
end
225225

226226
function (mld::MarginalLogDensity)(v::AbstractVector{T}, data=mld.data; verbose=false) where T
227-
return _marginalize(mld, v, data, mld.method, verbose)
227+
v1 = convert.(eltype(mld.u), v)
228+
return _marginalize(mld, v1, data, mld.method, verbose)
228229
end
229230

230231

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ end
149149
@test logpdf_laplace >= mld_laplace.logdensity(x, ())
150150
@test logpdf_cubature1 >= mld_cubature1.logdensity(x, ())
151151
@test logpdf_cubature2 >= mld_cubature2.logdensity(x, ())
152+
153+
# test for correct type promotion
154+
v_int = ones(Int, njoint(mld_laplace))
155+
v_float = ones(Float64, njoint(mld_laplace))
156+
@test mld_laplace(v_int) == mld_laplace(v_float)
152157
end
153158

154159

0 commit comments

Comments
 (0)