Why does sortperm! allocate here?

Amazing Dan, thank you!

I confirm it does not allocate any more.

I would argue that the documentation for sortperm! is lacking.

help?> sortperm!
search: sortperm! partialsortperm! sortperm partialsortperm

  sortperm!(ix, A; alg::Algorithm=DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward, [dims::Integer])

  Like sortperm, but accepts a preallocated index vector or array ix with the same axes as A. ix is initialized to contain the values LinearIndices(A).

  │ Warning
  │
  │  Behavior can be unexpected when any mutated argument shares memory with any other argument.

  │ Julia 1.9
  │
  │  The method accepting dims requires at least Julia 1.9.

  Examples
  ≡≡≡≡≡≡≡≡

Do you think it is worth opening an issue on Github for? For me before this I’ve naturally associated any function which is in-place ! to also be allocation free, while I do admit that this does not have to be the case, I believe most have this default expectation?

Kind regards

1 Like