JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.76k stars 5.49k forks source link

some combination of shapes during assignment (not broadcasted) into arrays don't error when they should #56203

Open adienes opened 4 weeks ago

adienes commented 4 weeks ago

consider A = zeros(2, 2), b = [1,1]

  1. A[1, :] = reshape(b, 1, 2)
  2. A[1, :] .= reshape(b, 1, 2) # ERROR: DimensionMismatch
  3. A[:, 1] = reshape(b, 1, 2)
  4. A[:, 1] .= reshape(b, 1, 2) # ERROR: DimensionMismatch

why do 2, 4 error but not 1, 2 ? should = and .= be pretty much always identical in the case of "standard" dense arrays? if not, what is the difference?

nsajko commented 3 weeks ago

The broadcasted assignment throwing is consistent with how broadcasting works, pretty sure there's nothing to improve on that side.

The = assignment is really just syntax sugar for setindex!(dst, src, indices...). It works as documented as far as I see, as far as I understand it just treats the inputs as iterators.

There's perhaps some redundancy here, but I don't think there's anything to change, at least not before a breaking release. Do you have any suggestions?