在使用Distributions.quantile 的时候发现这个broadcast的错误,报错说对Noraml也就是第一个参数的类型调用了iterate。于是查了一下?quantile,发现quantile的用法有3种:
quantile(itr, p; sorted=false)
eg: quantile(0:20, [0.1, 0.5, 0.9])
quantile(v, w::AbstractWeights, p)
quantile(d::UnivariateDistribution, q::Real)
这样说来,quantile应该是错误地调用了第一个函数,但是实际上第三个才是想要的。
julia> using Distributions
julia> d=Normal(0.0,1.0)
Normal{Float64}(μ=0.0, σ=1.0)
julia> quantile(d,0.7)
0.5244005127080407
julia> quantile.(d,[0.1,0.7])
ERROR: MethodError: no method matching iterate(::Normal{Float64})
Closest candidates are:
iterate(::Core.SimpleVector) at essentials.jl:578
iterate(::Core.SimpleVector, ::Any) at essentials.jl:578
iterate(::ExponentialBackOff) at error.jl:171
...
Stacktrace:
[1] copyto!(::Array{Float64,1}, ::Normal{Float64}) at .\abstractarray.jl:646
[2] _collect(::UnitRange{Int64}, ::Normal{Float64}, ::Base.HasEltype, ::Base.HasLength) at .\array.jl:563
[3] collect(::Normal{Float64}) at .\array.jl:557
[4] broadcastable(::Normal{Float64}) at .\broadcast.jl:609
[5] broadcasted(::Function, ::Normal{Float64}, ::Array{Float64,1}) at .\broadcast.jl:1139
[6] top-level scope at none:0