-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
julia> @code_warntype ConjugatePriors.NormalInverseGamma(1., 1., 1., 1.)
Variables:
#self# <optimized out>
mu::Float64
v0::Float64
sh::Float64
r::Float64
T::Any
Body:
begin
T::Any = (Base.promote_type)(Float64, (Base.promote_type)(Float64, (Base.promote_type)(Float64, Float64)::Any)::Any)::Any # line 20:
return ((Core.apply_type)(ConjugatePriors.NormalInverseGamma, T::Any)::Type{ConjugatePriors.NormalInverseGamma{_}} where _)((T::Any)(mu::Float64)::Any, (T::Any)(v0::Float64)::Any, (T::Any)(sh::Float64)::Any, (T::Any)(r::Float64)::Any)::ConjugatePriors.NormalInverseGamma{_} where _
end::ConjugatePriors.NormalInverseGamma{_} where _
I think this comes from having constructors like
ConjugatePriors.jl/src/normalinversegamma.jl
Lines 18 to 21 in 36fe174
function NormalInverseGamma(mu::Real, v0::Real, sh::Real, r::Real) | |
T = promote_type(typeof(mu), typeof(v0), typeof(sh), typeof(r)) | |
return NormalInverseGamma{T}(T(mu),T(v0),T(sh),T(r)) | |
end |
where the type is computed at runtime (with promote_type
), but I could be wrong about that.
When all the arguments are of the same type, adding a method like NormalInverseGamma(::T, ::T, ::T, ::T) where {T<:Real})
gets rid of the type instability. Another possible fix would be to use the inner constructor with the explicit type parameter whenever possible (e.g., in posterior_canon
, which is where I was bitten by this).
Metadata
Metadata
Assignees
Labels
No labels