Julia里面 . 是可以自动Broadcast的,但是遇到了一个很神奇的现象如下:
数和数,数和tuple,tuple 和 tuple 都没问题,但是最后一个为什么会错??
julia> 1 .+ 1
2
julia> 1 .+ (1,2)
(2, 3)
julia> (1,2) .+ 1
(2, 3)
julia> (1,2) .+ (1,2)
(2, 4)
julia> (1,2) .+ 1 .+ (1,2)
(3, 5)
julia> 1 .+ 1 .+ (1,2)
ERROR: MethodError: no method matching argtail()
Closest candidates are:
argtail(::Any, ::Any…) at essentials.jl:172
Stacktrace:
[1] tail(::Tuple{}) at .\essentials.jl:173
[2] longest_tuple(::Nothing, ::Tuple{}) at .\broadcast.jl:928 (repeats 3 times)
[3] longest_tuple(::Nothing, ::Tuple{Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(+),Tuple{Int64,Int64}},Tuple{Int64,Int64}}) at .\broadcast.jl:927
[4] copy at .\broadcast.jl:920 [inlined]
[5] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple},Nothing,typeof(+),Tuple{Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(+),Tuple{Int64,Int64}},Tuple{Int64,Int64}}}) at .\broadcast.jl:724
[6] top-level scope at none:0