I am looking for a version of argsort
, such as exists in numpy or in fortran. Is there an implementation of argsort
in Nim ... or accessible to Nim in some library? It seems a bit surprising that it is missing.
UPDATE
The following seems to work for argsort
:
proc argsort[T](a : T) : seq[int] =
result = toSeq(0..a.len - 1)
sort(result, proc (i, j: int): int = cmp(a[i], a[j]))
Presumably, though, it could be more efficient written natively and avoiding the function pointer....