The documentation for indexing assignment in the Julia manual says that:
If any index
I_k
selects more than one location, then the right hand sideX
must be an array with the same shape as the result of indexingA[I_1, I_2, ..., I_n]
or a vector with the same number of elements. The value in locationI_1[i_1], I_2[i_2], ..., I_n[i_n]
ofA
is overwritten with the valueX[I_1, I_2, ..., I_n]
, converting if necessary.
However, I am not sure if this is a bug, but the behavior in 1.5.3 seems to be slightly different. Consider the following definitions:
julia> A = zeros(10, 10); #10 x 10 Array{T, 2}
julia> b = ones(100); #100 element Array{T, 1}
julia> s = zeros(1, 100); #1 x 100 Array{T, 2}
julia> t = zeros(100, 1); # 100 x 1 Array{T, 2}
Now as documented,
julia> A[:, :] = b # works as documented
fills A with ones. The behavior with s
and t
, however, is a bit puzzling. Neither of them are vectors. However,
julia> A[:, :] = s
fills A
with zeros, even though this behavior does not seem to be documented in the quote from the “Indexing assignment” section reproduced above, as s
neither has the same dimensions as A
, nor is it a “vector”. Indeed,
julia> A[:, :] = t
raises precisely this error:
ERROR: DimensionMismatch("tried to assign 100Ă—1 array to 10Ă—10 destination")
So my question is the following: is it due to a documented feature that the assignment with s
above works, but the one with t
fails?
Julia version: 1.5.3