Distributions.jl
Distributions.jl copied to clipboard
Categorical cannot take abstract array p
For example:
P = abs.(randn(5,4,2));
p = view(P,:,1,1);
p ./=sum(p);
Then:
julia> Categorical(p)
ERROR: MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type SubArray{Float64,1,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Int64,Int64},true}
Closest candidates are:
convert(::Type{T}, ::T) where T<:AbstractArray at abstractarray.jl:14
convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/factorization.jl:53
convert(::Type{T}, ::T) where T at essentials.jl:168
...
Stacktrace:
[1] (::Distributions.var"#_#23#24")(::Bool, ::Type{DiscreteNonParametric{Int64,Float64,Base.OneTo{Int64},SubArray{Float64,1,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Int64,Int64},true}}}, ::Base.OneTo{Int64}, ::SubArray{Float64,1,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Int64,Int64},true}) at /home/cossio/.julia/packages/Distributions/kPXE9/src/univariate/discrete/discretenonparametric.jl:31
[2] Type at ./none:0 [inlined]
[3] #_#26 at /home/cossio/.julia/packages/Distributions/kPXE9/src/univariate/discrete/categorical.jl:31 [inlined]
[4] Type at ./none:0 [inlined]
[5] #Categorical#27 at /home/cossio/.julia/packages/Distributions/kPXE9/src/univariate/discrete/categorical.jl:34 [inlined]
[6] DiscreteNonParametric{Int64,P,Base.OneTo{Int64},Ps} where Ps where P(::SubArray{Float64,1,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Int64,Int64},true}) at /home/cossio/.julia/packages/Distributions/kPXE9/src/univariate/discrete/categorical.jl:34
[7] top-level scope at REPL[16]:1
Cannot Categorical(p) admit generic AbstractVector as argument p?
You can bypass the check with Categorical(p;check_args=false)
+1 to this. the error is hard to make sense of also