Skip to content

Commit

Permalink
Special case Geometric(OneHalf())
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner committed Dec 19, 2024
1 parent ceb6343 commit 1331649
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/univariate/discrete/geometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function Geometric(p::Real; check_args::Bool=true)
return Geometric{typeof(p)}(p)
end

Geometric() = Geometric{Float64}(0.5)
struct OneHalf <: Real end
Geometric() = Geometric{OneHalf}(OneHalf())
Base.getproperty(d::Geometric{OneHalf}, s::Symbol) = s == :p ? 0.5 : getfield(d, s)

@distr_support Geometric 0 Inf

Expand Down Expand Up @@ -137,6 +139,7 @@ cf(d::Geometric, t::Real) = laplace_transform(d, -t*im)
### Sampling

rand(rng::AbstractRNG, d::Geometric) = floor(Int,-randexp(rng) / log1p(-d.p))
rand(rng::AbstractRNG, ::Geometric{OneHalf}) = leading_zeros(rand(rng, UInt))

### Model Fitting

Expand Down

0 comments on commit 1331649

Please sign in to comment.