I use Julia 1.7.0rc1 and it seems that broadcasting works for Vector{String} and does not work on Vector{SubString{String}}. Is this something intended or I run into a bug?
Yet the outcome of split.("1 22 333") mysteriously fails on broadcasting while to should not. Scalars in broadcasting should be treated as zero sized arrays, no?
Moreover, like all vectorized “dot calls,” these “dot operators” are fusing . For example, if you compute 2 .* A.^2 .+ sin.(A) (or equivalently @. 2A^2 + sin(A) , using the @. macro) for an array A , it performs a single loop over A , computing 2a^2 + sin(a) for each element of A .
Let us try to translate it for our case. You have "1 22 333" input. You iterate it. Strings have special handling in broadcasting so it is a single element loop (i.e. we do not iterate string), so it seems that just parse(Int, split("1 22 333")) should be done as you passed one element in the input. And this fails.
What I say is that this is the expected behavior. Since you input a 0-dimensional argument then parse must be called only once on the output of the split (since 0-dimensional input contains exactly one element).
For example what would you expect to happen if you did parse.(Int, split.(Ref("1 22 333")))?
Note that for broadcasting "1 22 333" and Ref("1 22 333") is exactly the same since:
It’s fused. There is only one iteration. The string is treated as a scalar for broadcasting, and it is the only thing being iterated over. So there is no choice to do something different.
So all three arguments take part in determination of the dimension.
However, the dimensions of the output can be determined in a way independent from the functions involved. Only dimensionality of their arguments matters.
Here a special case is if you pass only 0-dimensional arguments, when - for convenience - the result of the operation is not wrapped in a 0-dimensional container, but is unwrapped when broadcasting is performed. And this is probably the reason of the confusion.
See e.g.
julia> sin.(fill(1))
0.8414709848078965
and you can see that 0-dimensional array was dropped.
This behavior is relevant if you wanted to implement custom broadcasting for your own types, as 0-dimensional containers require special treatment.
which fails for essentially the same reason.
The length of the first argument (for iteration) is 2, and the length of the second argument is 1, so it is reused.