Is there a reason a `MersenneTwister` value is not broadcastable?

As mentioned by others, broadcast defaults to treating its arguments as collections. Types can opt in to being treated as “scalars” by defining Base.broadcastable(x::MyType) = Ref(x), or you can opt-in at the call site with an explicit Ref.

That being said, I agree that RNG types should opt-in to being treated as scalars. Fortunately, it is a one-line non-breaking change to add this to any existing type:

https://github.com/JuliaLang/julia/issues/31071

3 Likes