I wonder what the type of indices is for standard arrays? Int, Int64, or . . . ?
I have this use in mind at present:
# Collect indices for which v[i] < thresh
function partition_vec(v, thresh)
idx = Vector{Int??????}()
for i in eachindex(v)
if v[i] < thresh
push!(idx, i)
end
end
idx
end
idx = partition_vec(rand(Float64,30), 0.3)
It’s not that I’m likely going to use huge arrays for which the range of index matters, but we’ve seen the problem of int
as size in C Language. You are supposed to use size_t
but a lot of programmers used int
instead and a lot of code broke when programs started to allocate arrays over 2 GB.
A related question is, how does one get the index type of an array? The above code would be cleaner if it were
function partition_vec(v, thresh)
idx = Vector{index_type_of(v)}()
. . . .
This is overkill for most cases. I’m asking this just out of curiosity.