No, broadcast
doesn’t need this (in 0.6, it works on arbitrary “scalar” types that don’t have getindex
).
I think that largely this is the Matlab legacy; in Matlab, numbers are “really” 1x1 matrices internally, and it is quite common to write functions that are supposed to work on either scalars or arrays of numbers in order to vectorize. To simplify the process of writing such generic scalar/vector code, you can access numbers as if they were 0-dimensional arrays in Julia.
I think that a lot of the need for this should be gone now with 0.5’s dot-call syntax: in the cases where you would previously have written a generic vector/scalar function, you should now just write the scalar function f(x)
, and then apply it to arrays A
with f.(A)
. This is not only easier, it is also faster because it can fuse with other elementwise operations and the result can be assigned in-place with .=
.
See also: make numbers non-iterable? · Issue #7903 · JuliaLang/julia · GitHub