JuliaLang/julia — pull request #5811 by simonster (2014-02-14 01:44:58+00:00)
Title: Add unique(AbstractArray, dim)

Efficiently finds the unique columns, rows, etc. of an array. The algorithm first hashes along the specified dimension, then finds the unique hashes, and finally checks that the hashes don't collide. It is roughly O(n) in the number of elements in the matrix.

Compared with MATLAB's `unique(x, 'rows')`, this approach gives much more consistent performance. It is ~10% slower for MATLAB's best case (when values are random, and so sorting requires inspecting only a single column) and much faster for other cases (it is 25x faster than MATLAB for 500 repeats of the same 10 random rows with 5000 columns).

This is my first time using Cartesian. Without it, this code is presently about 10% faster for finding unique rows of a matrix, but the overhead is probably worth it for the generality.