Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwanted type promotion from Float32 to Float64 while calculating logpdf of TuringDiagMvNormal #156

Closed
tlauli opened this issue Mar 13, 2021 · 1 comment · Fixed by #259

Comments

@tlauli
Copy link

tlauli commented Mar 13, 2021

While computing logpdf of Multivariate normal distributions, the logpdf is of type Float64, even when the mean, covariance matrix and observation all have eltype Float32.
MVE for TuringDiagMvNormal (TuringScalMvNormal and TuringDenseMvNormal suffer the same problem):

julia> using Distributions, DistributionsAD
julia> d = TuringDiagMvNormal(zeros(Float32, 2), ones(Float32, 2))
TuringDiagMvNormal{Vector{Float32}, Vector{Float32}}(m=Float32[0.0, 0.0], σ=Float32[1.0, 1.0])
julia> l = logpdf(d, [1f0, 2f0])
-4.337877066409345
julia> typeof(l)
Float64  #expected Float32

After a quick glance at the source, the problem seems to be that the constant 2π is Float64, which then promotes the rest of the expression.

@drrmmng
Copy link

drrmmng commented Jun 8, 2021

I'm experiencing the same problem with DistributionsAD v0.6.28

Edit:
Thinking about this a bit longer, I'm not sure if it is reasonable to expect that the output type of logpdf should mirror the type of either the parameters of the distribution or the value whose log probability should be determined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants