Skip to content

LogitNormal disrupts types #1765

@bgctw

Description

@bgctw

For some number-crunching project we work with Float32 instead of Float64.
Most distributions in Distributions.jl allow to construct a Float32-based version by providing a Type parameter, nice.

However, when I transform a Float32 based LogitNormal distribution (e.g. shift mean by +) the mean applied to the distribution gives me a Float64 instead of a Float32.

The reason is

  • AffineTransformation uses eltype(basedist) to determine its number and parameter type
  • default eltype of an uniform continuous distribution is Float64

The normal distribution already defines
Base.eltype(::Type{Normal{T}}) where {T} = T

Should we add such a method to all the other distributions that are based on a parametric type?

Here is a minimal (not) working example

    dln = LogitNormal{Float32}(0f0, sqrt(2f0))
    dshifted = dln * 2f0 + 1f0
    @test params(dshifted)[1] isa Float32
    @test mean(dshifted) isa Float32

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