ENH: Speed up `unique` with `return_inverse`

This replaces a sort with fancy indexing.
Merge pull request #5012 from jaimefrio/faster_return_inverse

ENH: Speed up `unique` with `return_inverse`