Skip to content

Support potential type argument in rand for eltype of Sampleable #2306

@bgctw

Description

@bgctw

In Distributions there is a long-standing discussion about how to specify the type of samples from a Distribution. This is important for code involving GPU computations that often needs Float32 rather than Float64.

Currently, this eltype of the sample is somehow mingled with the type of the parameters in Distributions.jl.
One suggestion is, to specify the eltype with a new variant of the rand function: rand(::Type{T}, ::Sampleable, ...)

In the linked issue, I argued for an alternative solution where this type can be specified with the Distribution, because the rand approach is not straightforward to extend to Turing. In Turing, the user, i.e. the author of the model, does not call the rand function directly, but relies on specifying the distribution, that a prior is sampled from.

However, it is believed that Turing should adapt.
Indeed, it seems that it can already be specified with the default type parameter in the Turing.@model macro, like
Turing.@model function tmodel_cross(obs_target, ::Type{T} = Float32) where {T}
Contrary, if it would be hard for Turing to adapt its syntax to specify the eltype of the Sampleable, this would be good time to contribute the discussion at the linked Distribution.jl issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions