The second example shows that the result of sub2ind
might be very buggy in some specific cases.
julia> sub2ind((3,3), 1, 1)
1
julia> sub2ind((3,3), 1, 2)
4
julia> sub2ind((3,3), 2, 1)
2
julia> sub2ind((3,3), [1,1,2], [1,2,1])
3-element Array{Int64,1}:
1
4
2
# no error, even the subscript is out of range.
julia> sub2ind((3,3), 3, 4)
12
One cannot determine whether a subscript is in the range of an array by comparing its index:
julia> sub2ind((3,3), -1, 2)
2
julia> 0 < sub2ind((3,3), -1, 2) <= 9
true
parameter | details |
---|---|
dims::Tuple{Vararg{Integer}} | size of the array |
I::Integer... | subscripts(scalar) of the array |
I::AbstractArray{T<:Integer,1}... | subscripts(vector) of the array |