Many thanks!
This is actually what I need.
The ordering of the rows in output is not important to me and your code selects the points correctly from input by basically flattening all dimensions other than dim.
As a side note, is the call to contiguous() expensive or do I not need to be concerned?