JuliaStats / Distributions.jl

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

`pdf` is ambiguous for `UnivariateGMM` #1463

Open ForceBru opened 2 years ago

ForceBru commented 2 years ago

Code

julia> distr = UnivariateGMM([-1, 1], [.1, .2], Categorical([.4, .6]))
UnivariateGMM{Vector{Int64}, Vector{Float64}, Categorical{Float64, Vector{Float64}}}(
K: 2
means: [-1, 1]
stds: [0.1, 0.2]
prior: Categorical{Float64, Vector{Float64}}(support=Base.OneTo(2), p=[0.4, 0.6])
)

julia> pdf(distr, collect(-1:0.1:1))
ERROR: MethodError: pdf(::UnivariateGMM{Vector{Int64}, Vector{Float64}, Categorical{Float64, Vector{Float64}}}, ::Vector{Float64}) is ambiguous. Candidates:
  pdf(d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real, M}) where {N, M} in Distributions at ~/.julia/packages/Distributions/vR2pk/src/common.jl:249
  pdf(d::UnivariateDistribution, X::AbstractArray) in Distributions at deprecated.jl:70
Possible fix, define
  pdf(::UnivariateDistribution, ::AbstractArray{T, M} where T<:Real) where M
Stacktrace:
 [1] top-level scope
   @ REPL[100]:1

Versions

devmotion commented 2 years ago

For univariate distributions, calling pdf on an array of values is deprecated. Nevertheless it should not throw an error but only display a deprecation warning (if they are enabled).