JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.
Other
1.08k stars 410 forks source link

Unexpected behavior of `truncated` for zero variance distributions at the lower bound #1867

Open HakanBrian opened 1 month ago

HakanBrian commented 1 month ago

When truncating a Normal distribution with zero variance and mean equal to the lower bound of the truncated, evaluating rand will result in infinite compilation time. An equivalent operation with the upper bound of the truncated will return the value for the upper bound as expected.

Example:

using Distributions

rand(truncated(Normal(1, 0), 0, 1))  # Expected output: 1
rand(truncated(Normal(0, 0), 0, 1))  # Expected output: 0

# Note that when the expected output is 0 we get infinite compilation time.