Functional sorting of the matrix rather than the dual transpose. This is faster than the dual transpose version, in particular in large sparse structures. Needs improvement with the use of sortperm which is causing a large amount of allocation.