Why sortperm(Int32[]) return Int64[]

Do you know, why is it?

a=Int32[1,2,3,4]
sortperm(a)
1 Like

sortperm returns a vector of indexes into array a, so it’s going to be Int32 on a 32bit machine and Int64 on a 64bit machine:

julia> a = [ "z", "m", "a"]
3-element Array{String,1}:
 "z"
 "m"
 "a"

julia> sortperm(a)
3-element Array{Int64,1}:
 3
 2
 1

julia> a[sortperm(a)]
3-element Array{String,1}:
 "a"
 "m"
 "z"
7 Likes