Weird broadcasting behaviour

Broadcasting works for matrices up to 10 by 10, then fails:

julia>  n=10; A = rand(n,n); B = ones(n,n);

julia> y .= A .+ B;

julia>  n=11; A = rand(n,n); B = ones(n,n);

julia> y .= A .+ B;
ERROR: DimensionMismatch("array could not be broadcast to match destination")
Stacktrace:
 [1] check_broadcast_shape at ./broadcast.jl:509 [inlined]
 [2] check_broadcast_axes at ./broadcast.jl:512 [inlined]
 [3] check_broadcast_axes at ./broadcast.jl:515 [inlined]
 [4] instantiate at ./broadcast.jl:259 [inlined]
 [5] materialize!(::Array{Float64,2}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2},Nothing,typeof(+),Tuple{Array{Float64,2},Array{Float64,2}}}) at ./broadcast.jl:823
 [6] top-level scope at REPL[265]:1

I have no idea why this might be, please help!

This isn’t about size. The problem is y is 10x10, so you can’t copy an 11x11 array into it

1 Like