zenna / Omega.jl

Causal, Higher-Order, Probabilistic Programming
MIT License
164 stars 17 forks source link

Pointwise .== fails with arrays #216

Open zenna opened 2 years ago

zenna commented 2 years ago
julia> x = manynth(Normal(0, 1), [1,2,3])
Mv{Vector{Int64}, Normal{Float64}}([1, 2, 3], Normal{Float64}(μ=0.0, σ=1.0))

julia> randsample(x)
3-element Vector{Float64}:
  0.5329609997818248
  0.6091868691905119
 -1.1231586242100318

julia> x .== [3,4,5]
ERROR: MethodError: no method matching size(::Mv{Vector{Int64}, Normal{Float64}})
Closest candidates are:
  size(::Union{LinearAlgebra.Adjoint{T, var"#s859"}, LinearAlgebra.Transpose{T, var"#s859"}} where {T, var"#s859"<:(AbstractVector)}) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:172
  size(::Union{LinearAlgebra.Adjoint{T, var"#s859"}, LinearAlgebra.Transpose{T, var"#s859"}} where {T, var"#s859"<:(AbstractMatrix)}) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:173
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/LinearAlgebra/src/qr.jl:567
  ...
Stacktrace:
 [1] axes
   @ ./abstractarray.jl:95 [inlined]
 [2] combine_axes
   @ ./broadcast.jl:499 [inlined]
 [3] instantiate
   @ ./broadcast.jl:281 [inlined]
 [4] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.Unknown, Nothing, typeof(==), Tuple{Mv{Vector{Int64}, Normal{Float64}}, Vector{Int64}}})
   @ Base.Broadcast ./broadcast.jl:860
 [5] top-level scope
   @ REPL[29]:1

The issue is that the array is hijacking the broadcasting behavior